My xml file is look like this . I want to get the value node text content as like this .
<property regex=".*" xpath=".*">
<value>
127.0.0.1
</value>
<property regex=".*" xpath=".*">
<value>
</value>
</property>
I want to get text as order they specified in a file . Here is my java code .
Document doc = parseDocument("properties.xml");
NodeList properties = doc.getElementsByTagName("property");
for( int i = 0 , len = properties.getLength() ; i < len ; i++) {
Element property = (Element)properties.item(i);
//How can i proceed further .
}
Output Expected :
Node 1 : 127.0.0.1
Please suggest your views .
The following method looks for all
propertyelements within the document and collects allvaluechildren of those elements namedvaluewihtout using XPath.But you can do the same in a more elegant way using the XPath expression
//property/value:You can use the method above like this:
I tested it with the following two XML inputs, since your XML lacks a closing
</property>tag.Here is the first one (I added extra elements, to show that they are not found):
The second one has nested property elements (I added the missing element at the end):