0

Hi,
I have an XML file looks like this
<node>
<node2><node3>1</node3></node2>
<node2><node3>2</node3></node2>
<node2><node3>3</node3></node2>
</node>
I am trying to read one child into a string
I want my string to look like that : <node2><node3>1</node3></node2>

File xml = new File("json.txt");
		SAXReader reader = new SAXReader();
		Document doc = reader.read(xml);
		Element root = doc.getRootElement();
		
		for (Iterator i = root.elements().iterator(); i.hasNext();) {
			Element elem = (Element) i.next();
				Document doc1 = elem.getDocument();
                                String temp = doc1.asXML();
				System.out.println(doc1.asXML());
		}

currently temp looks like that
<node>
<node2><node3>1</node3></node2>
<node2><node3>2</node3></node2>
<node2><node3>3</node3></node2>
</node>
but I want temp to look like that
<node2><node3>1</node3></node2>
What am I missing ?

2
Contributors
3
Replies
5
Views
5 Years
Discussion Span
Last Post by stultuske
0

basically, what you are doing is you read the entire xml file (not just a part) and you store the xml code you just read into temp.

0

basically, what you are doing is you read the entire xml file (not just a part) and you store the xml code you just read into temp.

How can I read only part of the xml ?

0

I used to use JDom for that, you can (for instance) read a list of all the elements of a certain element, read the value of a certain element ...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.