开发者

Issue when parsing XML Node text that contains space?

开发者 https://www.devze.com 2023-04-12 19:37 出处:网络
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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消