views:

67

answers:

2

I'm trying to parse this XML string:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<response type="success">
   <lots>
      <lot>32342</lot>
      <lot>52644</lot>
   </lots>
 </response>

When I get the root node, which is "response", I use the method getChildNodes() which returns a NodeList of length 3. However what I'm confused about is the order the NodeList gets created in. I used some print statements to show whats in the list

Item length: 3
Item (0): [#text: 
]
Item (1): [lots: null]
Item (2): [#text: 
]

So the text node is first which is two levels below the root, then the next child of the root, and then the next text node.

Is there a particular order and/or reason the list is ordered in this way?

+2  A: 

You are seeing the whitespace text surrounding the childnode "lots"

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<response type="success">
{txt1}<lots>
         <lot>32342</lot>
         <lot>52644</lot>
      </lots>{txt2}
 </response>
crowne
I think your right, How would I parse the file to ignore whitespace?I've tried setIgnoringElementContentWhitespace(true);Or is that something that will always be there?
Albinoswordfish
A: 

Actually I found the problem, I was using '\n' characters which was causing extra text nodes being parsed

Albinoswordfish