Re: [Simple-support] How to parse xml into objects I can use to build a richfaces tree?
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2009-05-30 11:45:10
|
Hi,
This should work for your XML.
@Root
class DeviceCollection{
@ElementList(inline=true)
private Collection<Device> list;
@Root
private static class Device {
@Element String deviceId;
@Element String name;
}
public Collection<Device> getDeviceCollection() {
return list;
}
}
Niall
--- On Thu, 5/28/09, meghiddo <mat...@ho...> wrote:
> From: meghiddo <mat...@ho...>
> Subject: [Simple-support] How to parse xml into objects I can use to build a richfaces tree?
> To: sim...@li...
> Date: Thursday, May 28, 2009, 7:21 AM
>
> There has to be a way to do this!! I need java code that
> will
>
> 1 - look at this xml schema
> 2 - take whatever the text node value is for
> <deviceId> and set it equal to
> String device; or treenode device;
>
> It seems so simple, but I just cant seem to do it!!
>
>
>
> The xml looks like this:
>
> [code]<deviceCollection>
> <device>
>
> <deviceId>exampleDevice1</deviceId>
> <name>Example Device
> 1</name>
> </device>
> </deviceCollection>[/code]
>
> I have a readXml method already:
>
> [code]public DeviceCollection readXML(InputStream xml)
> throws Exception {
> Serializer serializer = new
> Persister();
>
> DeviceCollection
> deviceCollection = null;
> deviceCollection =
> serializer.read(DeviceCollection.class, xml);
> xml.close();
> return deviceCollection;
>
> }
> [/code]
>
> And here is my method where I am attempting to bind this
> data:
>
> [code]static String devicesUrl =
> "http://webc-apps.ni.com/measure/1.01/devices";
>
> public static void updateNode() throws
> IOException, Exception {
>
> // Create an instance of
> HttpClient.
> HttpClient client =
> new HttpClient();
>
> // Create a method
> instance.
> GetMethod method =
> new GetMethod(devicesUrl);
>
> XMLTreeDataBuilderTest node =
> new XMLTreeDataBuilderTest();
> DeviceCollectionXMLAO access =
> new DeviceCollectionXMLAO();
> DeviceCollection
> deviceCollection;
>
>
> deviceCollection =
> access.readXML(method.getResponseBodyAsStream());
>
> [/code]
>
> I am not sure where I am going wrong here. All I
> really know is I am
> needing to take the values from the deviceid node and name
> node, and bind
> them to something which I can then use in my jsf page to
> build a tree.
> It has to be dynamic as well, because that xml from the top
> is going to be
> different depending on the user..
> please help, Ive been at this for a week and havent made
> much progress
> --
> View this message in context: http://www.nabble.com/How-to-parse-xml-into-objects-I-can-use-to-build-a-richfaces-tree--tp23762343p23762343.html
> Sent from the Simple XML Serialization mailing list archive
> at Nabble.com.
>
>
> ------------------------------------------------------------------------------
> Register Now for Creativity and Technology (CaT), June 3rd,
> NYC. CaT
> is a gathering of tech-side developers & brand
> creativity professionals. Meet
> the minds behind Google Creative Lab, Visual Complexity,
> Processing, &
> iPhoneDevCamp as they present alongside digital
> heavyweights like Barbarian
> Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com
> _______________________________________________
> Simple-support mailing list
> Sim...@li...
> https://lists.sourceforge.net/lists/listinfo/simple-support
>
|