• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

decode an inputstream

 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello:

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.

eric
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You want to "decode" XML? I don't understand what you mean by that. Could you explain it differently?
 
John Eric Hamacher
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello:
The response I'm getting from the web service contains <-semi-colon instead of < and so forth. My Xpath doesn't work unless I do these conversions.


eric
 
John Eric Hamacher
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't convey this right . . . lt convert to <
 
John Eric Hamacher
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(apos)lt(semi-colon)
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm guessing you mean &lt; and not 'lt; -- right?

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.
 
John Eric Hamacher
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the response:

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):




 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Eric Hamacher wrote:



GO BIG RED!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic