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 ?

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.

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 ?

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 ...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.