I am trying to decode XML received from a webservice (e.g. change < to <, etc.). The XML is in an InputStream but I could use an InputSource, if needed. I see XMLDecoder but I don't understand its usage. Any help is appreciated.
In other words the XML is escaped, not encoded. (And because I knew how XML and HTML escaping works, I knew to type those things in the first line in escaped form so that the forum software would unescape them to look the way I wanted.)
Anyway... is the whole XML document escaped like that, or is it only text nodes within the XML document which are escaped? I can't imagine you using a whole XML document in an XPath expression, so I'm guessing it's the latter -- which would be normal -- but it wouldn't hurt to have a full explanation from you.
Yes, I meant (amp)lt(semi-colon). It is a very small XML response from a web service. When I print the response to my console, all of the < and > are escaped (except for the root node, which is normal). I receive the response as an InputStream which I feed to an XML parser:
The unescaped XML looks like (this is what this message board does to the document when it is escaped):
So in fact what you have is a root node, which is the <string> element, and it contains text which is an entire XML document (escaped, of course, since it's in a text node)?
Then the easiest way to deal with it is to just extract that text node into a String (this step does the unescaping) and then pass it to a second DocumentBuilder object, which will parse it just like the normal XML document it is. Your root element for that document would be the <NewDataSet> element, so you would have to change your XPath a bit.