• Post Reply Bookmark Topic Watch Topic
  • New Topic

trouble parsing stream or string into xml  RSS feed

Matt Kohanek
Village Idiot
Ranch Hand
Posts: 484
Java jQuery Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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="#{recTreeBean.data}" var="item" nodes="#{item.name}" />

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

It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!