Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
337 views
in Technique[技术] by (71.8m points)

java - DOMDocument getNodeValue() returns null (contains an output escaped string)

I am processing a DomDocument which is basically the XML result of a SOAP web service. To give you an idea, this is what it looks like

...<ParentNode><ChildNode>&lt;output&gt;&lt;escaped&lt;string</ChildNode></ParentNode>...

Yes, the value of ChildNode is a string that has been output escaped and is XML that is packed within this XML. I do the usual run of DomDocument processing such as

NodeList rows = dom.getElementsByTagName(ChildNode);
for(int i=0;i<rows.length;i++)
{
  System.out.println(rows[i].getParentNode()); // returns ParentNode
  System.out.println(rows[i].getNodeName()); // returns ChildNode
  System.out.println(rows[i].getNodeValue()); // returns null
}

After you inspect the above code, you realize that even though the node returns correct values for ParentNode and the NodeName node, it returns a null value upon accessing getNodeValue(). There is a string here, and I can see it in my console output. But I am not sure what trick I am missing here, does the output escaping mess it up in any particular way?

Thanks, Parijat

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You want getTextContent() rather than getNodeValue() - the latter always returns null for element nodes.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...