[Simple-support] Need to use simple to write an inputStream to some useable xml form
Brought to you by:
niallg
|
From: meghiddo <mat...@ho...> - 2009-06-08 20:53:21
|
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:
public void load(){
// Create an instance of HttpClient.
HttpClient client = new HttpClient();
SimpleXml access = new SimpleXml();
// Create a method instance.
GetMethod method = new GetMethod(devicesUrl);
InputStream responseBody = null;
try {
// Execute the method.
int statusCode = client.executeMethod(method);
//System.out.println( method.getStatusCode());
if (statusCode != HttpStatus.SC_OK) {
System.out.println("Method failed: " + method.getStatusLine());
}
// Read the response body.
responseBody = method.getResponseBodyAsStream();
//System.out.println("printing current value of
method.getResponseBodyAsString from httpclient class "+
//method.getResponseBodyAsString());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("printing InputStream responseBody from httpclient
class: " + responseBody.toString());
}
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
--
View this message in context: http://www.nabble.com/Need-to-use-simple-to-write-an-inputStream-to-some-useable-xml-form-tp23931939p23931939.html
Sent from the Simple XML Serialization mailing list archive at Nabble.com.
|