Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes XML and Related Technologies and the fly likes trouble parsing stream or string into xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "trouble parsing stream or string into xml" Watch "trouble parsing stream or string into xml" New topic

trouble parsing stream or string into xml

Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

I posted this on the simplexml forum, but thought Id do so here as well in hopes of getting this solved faster, so if some of this doesnt seem to pertain to this forum that is why:

SO I have a method that uses httpclient to get data from a web service. The data is stored on the web service in an xml format. I can use httpclient getMethod to retrieve this xml either as a stream or a string.
So I have that data stored in a varable, called responseBody.
Now I need to convert that into xml form. If I try to add the current value of responseBody to a list (when it is a String) the list does print out the data and it does look like xml. But for some reason it is not being recognized as xml. It is being recognized as a String, and even though that String looks like xml, it is not being recognized as such ny a rich:tree

The final goal is to somehow bind this xml to a list (or some other possible value), which I can then bind to a richfaces tree through a backing bean.

So here is my method that gets the responseBody from the web service:

This seems to be working OK. Through various tests I have been able to print out the value of resposeBody and it does return this:

<?xml version="1.0" encoding="UTF-8"?>
<name>Example Device 1</name>
<name>WSN CRio Device</name>

That is if I get responseBody as a String. If I get responseBody as a stream, I cant print out the value but I am guessing it would be the same, just in a stream form right? If I try to print it as a Stream it gives me some odd print out that doesnt mean much, I just know it does not mean null.

So assuming that is true, I have my variable responseBody, either as a String or Stream depending on what I do, and it holds the xml I printed above.

Now I need simple to take that data in, and output it in some kind of xml form that I can use. Although Im not sure what yet...

Like I said, the end goal is to use this xml to populate a rich tree. If I leave responseBody as a String, and use that to populate the tree it gives me a one node tree that has all of that xml text on one line...not too useful.

From what I understand from the jboss forum, if I can get some form of xml bound to the rich tree then I can use this line on my jsf page to do what I need:

<rich:recursiveTreeNodesAdaptor roots="#{}" var="item" nodes="#{}" />

Ideally that will make a nice tree. If that line were to use the xml I printed from above, the result Im hoping for would be a tree like this:

---Example Device 1
---WSN CRio Device

But I just cant get this working,
so any help at all anyone might have would be great. I mean anything, I have tried all I can think to do, so even if you have help pretaining to the tree rather than simpleXml that is great


True wisdom is in knowing you know nothing - Socrates
GeeCON Prague 2014
subject: trouble parsing stream or string into xml