aspose file tools*
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
Author

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"?>
<deviceCollection>
<device>
<deviceId>exampleDevice1</deviceId>
<name>Example Device 1</name>
</device>
<device>
<deviceId>WSN-Module-8F3A-D247-4B99</deviceId>
<name>WSN CRio Device</name>
</device>
</deviceCollection>


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:

-exampleDevice1
---Example Device 1
-WSN-Module-8F3A-D247-4B99
---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

Thanks


True wisdom is in knowing you know nothing - Socrates
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: trouble parsing stream or string into xml