0

I have the following XML, and I cannot access the tag <description>.

https://i.stack.imgur.com/Ck6mq.jpg

A simpler XML I can read well, but this I cannot.

Parsing code follows:

xmlFile = new File(route);
documentFactory = DocumentBuilderFactory.newInstance();   
documentBuilder = documentFactory.newDocumentBuilder();
doc = documentBuilder.parse(xmlFile);
doc.getDocumentElement().normalize();
kjhughes
  • 106,133
  • 27
  • 181
  • 240
wagego
  • 3
  • 3
  • 5
    Can you just post the Xml as part of your question, photographed code is unpleasant. – Newd Jul 14 '15 at 19:53

2 Answers2

0

The comprobante element has an XML declaration in it:

<?xml version="1.0" encoding="UTF-8"?>

An XML declaration may only appear once in an XML document and may only occur at the very top. Anything else prevents the file from being well-formed and will preclude use of conformant XML tools. You must remove the extraneous XML declaration if you want to treat this data as XML.

Community
  • 1
  • 1
kjhughes
  • 106,133
  • 27
  • 181
  • 240
0

the comprobante element contains another xml as text node. It is that nested xml which contains description element you are searching for. what you can do is:

doc = documentBuilder.parse(xmlFile);
element = get comprobante element from doc
InputSource is = new InputSource(new StringReader(element.getTextContent());
doc = documentBuilder.parse(is);
now search for description element in this doc
Santhosh Kumar Tekuri
  • 3,012
  • 22
  • 22
  • EXCELLENT, I made a method to parse this part of code and I can now seamlessly access that data. Thank you very much for the help! – wagego Jul 15 '15 at 16:13