scottjsn
09-05-2008, 01:41 PM
Try to understand the XML string:
String x="<rootTag><p>test1</p><p>test2</p></rootTag>";
Document doc = utils.convertXMLToDoc(x);
NodeList nl = doc.getElementsByTagName("p");
Node nd = nl.item(0);
String result = nd.getFirstChild().getNodeValue();
//result returns "test1"
This is what I wanted. So far so good. Now, I go back to remove the root tag.
String x="<p>test1</p><p>test2</p>";
Re-run the above codes, generating an error.
Why must an XML string contain a root tag to wrap the elements?
Thanks
Scott
String x="<rootTag><p>test1</p><p>test2</p></rootTag>";
Document doc = utils.convertXMLToDoc(x);
NodeList nl = doc.getElementsByTagName("p");
Node nd = nl.item(0);
String result = nd.getFirstChild().getNodeValue();
//result returns "test1"
This is what I wanted. So far so good. Now, I go back to remove the root tag.
String x="<p>test1</p><p>test2</p>";
Re-run the above codes, generating an error.
Why must an XML string contain a root tag to wrap the elements?
Thanks
Scott