Good day!
When working with this XML document:
<?xml version="1.0" encoding="UTF-8"?> <response> <state>200</state> <error></error> <result> <user name="parent" title="NONE"> <roles> <item>parent</item> </roles> </user> </result> </response>
I have some problems with parsing it. Here is how I pull information from it:
(I use the DocumentBuilderFactory-> DocumentBuilder-> Document classes for working with XML)
... DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dbuilder= dfactory.newDocumentBuilder(); byte[] bytes = xmltext.getBytes(); // xmltext - текст XML InputStream is = new ByteArrayInputStream(bytes); Document xmldoc = dbuilder.parse(is); xmldoc.getDocumentElement().normalize(); ... NodeList d = xmldoc.getDocumentElement().getElementsByTagName("roles"); String ut=d.item(0).getFirstChild().getNodeValue(); ...
As a result, I get an empty string in the variable "ut". And in it should be the text "parent".
Why it happens? Thank.