Hi,
I have some problems by getting the attributes from the first child node, if i try to get child elements everything works fine, but whenever i need the elementvalue from a node with attributes i doesn't return anything.
The xpath expression works fine if i want to get the element value from all childs, but not when i just want from one of them.
This one works,
XPathFactory factory1 = XPathFactory.newInstance();
XPath xpath = factory1.newXPath();
xpath.setNamespaceContext(new PersonalNamespaceContext());
XPathExpression expr
= xpath.compile("//default:DeviceExchange[1]/default:Status/text()");
// gets the value of the node picked out
Object result = expr.evaluate(doc, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
for (int i = 0; i < nodes.getLength(); i++) {
names[i] = nodes.item(i).getNodeValue();
String a = names;
// checks if status is exchanged, if it is sets status to 1
if (a.length() == 9){
names[i] = "1"; }
else{ names[i] = "0";}
System.out.println(names[i]);This doesn't
XPathFactory factory2 = XPathFactory.newInstance();
XPath xpath2 = factory2.newXPath();
xpath2.setNamespaceContext(new PersonalNamespaceContext());
XPathExpression expr2 = xpath2.compile("//default:DeviceExchange[1]/default:Field[@names='MLPKTID']/text()");
Object result2 = expr2.evaluate(doc, XPathConstants.NODESET);
NodeList nodes2 = (NodeList) result2;
for (int i = 0; i < nodes2.getLength(); i++) {
names2[i] = nodes2.item(i).getNodeValue();
System.out.println(names2[i]);}Does anyone have any ideas? I will apreciate all help!
Edited by: fusen on Oct 25, 2007 1:12 AM