I am working with Java and the DOM libraries. I have开发者_StackOverflow an XML file which I need to parse through and feed into a database for validation and comparison.
I have setup my parser and I am getting great results but have rain into a problem. When a node has a text value (which includes a space) the second portion of the text is cut off...
<price>
<list type="new">
<name>A Name</name>
<description>[First Data Piece][Second Data Piece]</description>
</list>
</price>
When I parse this XML I only received [First Data Piece] as the text value for the description node.
private String getTextValue(Element ele, String tagName) {
String textVal = null;
NodeList nl = ele.getElementsByTagName(tagName);
if(nl != null && nl.getLength() > 0) {
Element el = (Element)nl.item(0);
textVal = el.getFirstChild().getNodeValue();
}
return textVal;
}
This is the code that is getting the text from the XML... Please let me know what else I may need to provide.
精彩评论