my dog learned polymorphism*
The moose likes Java in General and the fly likes Looking for correct data type to take in stream of xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Looking for correct data type to take in stream of xml" Watch "Looking for correct data type to take in stream of xml" New topic
Author

Looking for correct data type to take in stream of xml

Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

Ive been looking into TreeData but not sure it is what I need. I basically have some xml I can get from the web service as a stream or a String. I need some type of data type that is suitable to hold this Stream of xml. Then I am needing to make a tree that uses EL to bind this dataType variable and iterate through it. Something like - <tree value="#{bean.dataSource}" vars="nodes" nodes="#{nodes.name}" /> - you get the idea.

Any new tips on this, I know I asked a while back and the topic kind of veered off somewhere else, but I really have only this problem left that is stopping me from completing my project.


True wisdom is in knowing you know nothing - Socrates
Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686

I use String or JDOM


===Vyas Sanzgiri===
My Blog
David Sharpe
Ranch Hand

Joined: Jun 15, 2009
Posts: 32
I use JDOM as well. It's very easy to use and there are many examples available online.

You need to remember that when you're working with something as common as XML, there's rarely a reason to consider using lower-level data structures.
Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

ANy tutorials you can recommend because I sure have looked through a lot of them and havent made a lot of progress.
Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

I might be mis representing what is going on i found out aftre I started looking at JDOM.

I can already deserialize the xml with SimpleXML. I can get it as a Stream. So far what i have done is used a for llop, where every device in my deviceCOlection puts the deviceName in a list. So I have a list fll of device names or a list full of project names. But only certain devices belong to certain projects. Right now all I can do is make every device listed under every project. I dont know what to do here. I know I need one list, which will probably be a list of lists. At the top will be projects, and each project list needs to then have a list of devices. Then i can have my tree iterate through each project.

I cant get any help on JBoss forums for rich tree either. There is either too much of a language barrier or they just dont like me over there haha.

I just need a starting point so I can ask more specific questions but I dont even know how to start this process



edit - is there a data type I can feed in a Stream, and that stream is xml. Then bind that data type to some jsf tree, and tell it to variate through each set of nodes in the stream I fed in. god I cant even make sense here, this sucks so much


something that does it like .asp would be great, I was able to create the tree I need in about two minutes using asp, they make it so easy
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18874
    
  40

I can already deserialize the xml with SimpleXML. I can get it as a Stream. So far what i have done is used a for llop, where every device in my deviceCOlection puts the deviceName in a list. So I have a list fll of device names or a list full of project names. But only certain devices belong to certain projects. Right now all I can do is make every device listed under every project. I dont know what to do here. I know I need one list, which will probably be a list of lists. At the top will be projects, and each project list needs to then have a list of devices. Then i can have my tree iterate through each project.


I think that you are under the false impression that XML parsers is a datatype -- it isn't. The purpose of an XML parser is to parse the XML. The result can actually be a data structure, or a set of callbacks, which you can use to create a data structure. If the data structure isn't exactly what you want, then you either have to convert it to exact what you want, or modify your code to use the data structure that is returned.

To change your XML parser because the data returned isn't exactly correct is a bit extreme. You have a XML parser that returns a structure, and you have some other library that expects the data in a particular structure. Your job is to write all the code that converts between the two structures. Based on all the questions that you asked so far, it looks like it is probably easier to do that than to change either of the two sides.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
David Sharpe
Ranch Hand

Joined: Jun 15, 2009
Posts: 32
I'm not sure I understand well enough to be helpful, but I'll take another stab at this.

"I can already deserialize the xml with SimpleXML. I can get it as a Stream."

I've never used SimpleXML, so I'm not sure what its capable of, but JDOM will do a lot more than just give you the XML as a Stream. Did you check out the API?

If you had something that looked like this:



You'd say something like:



Which would hopefully print something like this (assuming my in-head compiler is working):

Project gilmore has the following devices:
RQ98
HH75
Project ahmadi has the following devices:
TTb8
UD98


JDOM's API is very robust (e.g. Element). I'd be surprised if SimpleXML was as useful.

Anyhow, to sum it up, what I'm trying to describe is that a JDOM Document is already a tree structure with useful operations defined. It isn't what you're looking for?
Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

so that xml you have there is it a local xml file? Is that how that would work. The thing for me is, the xml is stored on a web service, so I have to use all these extra steps.


First I use httpclient to get the xml from the data service and bind it to one of my objects, say the project object. The I use simpleXml for the parsing. Here is my code that looks through the project collection and takes each project namee and adds it to the projectNamesList: In this there are two method calls from other classes and I show what those methods do in a comment block. I dont know if anyone is going to want to take teh time to figure out how this works, I have trouble explaining some parts myself because the access method I did not even write and the other stuff I just kept trying differet things till something finally worked...

David Sharpe
Ranch Hand

Joined: Jun 15, 2009
Posts: 32
Matt Kohanek wrote:so that xml you have there is it a local xml file? Is that how that would work. The thing for me is, the xml is stored on a web service, so I have to use all these extra steps.

JDOM can build documents from files, streams, readers, URLs, etc., as explained in the API. Your "Response" method is returning an InputStream. This method would turn that InputStream into a JDOM document. Or, this method could get it straight from the URL.

And then Element has all the XML-related methods I've ever needed.

As Henry Wong describes, it seems that SimpleXML is mostly just a parser (once again, I've never used it); what you want is a parser and a robust datatype: JDOM supplies both.
Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

Well, SimpleXML is already a big part of my project, I use it to serialize data input from users. DO you see any issues with me using Simple to serialize but using JDOM for the deserialization?
David Sharpe
Ranch Hand

Joined: Jun 15, 2009
Posts: 32
The way I see it, with my entirely superficial understanding of your intent, is:
XML -> JDOM -> YourProgram -> SimpleXML -> XML

So as long as SimpleXML produces a valid XML document, JDOM should be able to handle it. Testing that theory wouldn't take much effort. (If you have a longer-term program in mind that you want to be maintainable, it might be worth the time investment to go full-hog and choose either SimpleXML or JDOM.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Looking for correct data type to take in stream of xml