• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Looking for correct data type to take in stream of xml

 
Village Idiot
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 686
Netbeans IDE Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use String or JDOM
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

 
David Sharpe
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.)
 
It's a beautiful day in this neighborhood - Fred Rogers. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic