• 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

JAVA and XML

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does anyone know of a tutorial out there about using the built in java api's to parse xml. I have never used them before and just need some simple ideas to point me in the right direction. I am trying to read a simple xml file, and use its contents to set string values in java.

<connection>
<name>Database</name>
<dsn>DataSource</dsn>
</connection>

Thanks

Joe
 
Ranch Hand
Posts: 775
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sun Java XML tutoria
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm, if I had to suggest just one way to do a little bit of parsing, as simply and directly as possible, I would suggest dom4j. Any other suggestions for quick and easy parsing with a minimum of mumbo-jumbo?
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On the other hand, people who learn a complex technology using just a few simple ideas are at risk of ignoring large parts of that technology and continuing to use just those simple ideas even when there are better ideas available.
 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Clapham:
On the other hand, people who learn a complex technology using just a few simple ideas are at risk of ignoring large parts of that technology and continuing to use just those simple ideas even when there are better ideas available.



IMHO JAXP's DOM implementation does not hold and killer feature or better ways to do to things over other tree based models like jdom, dom4j, xom...I mean in most cases it adds more complexity without any tangible benifits to a java developer

can you think of any
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Benefits of JAXP:
1. it is in EVERY Java SE library, no thrashing around trying to make sure your customers have the right external library in the right place.
2. it is a complete implementation of the w3c DOM
3. the "pluggable" architecture has been refined to where you can plug in your own parser if you absolutely have to
4. Java 5 contains many convenience classes and methods - considerably more than the previous releases - example - the java.util.Properties class now has a loadFromXML method!!
Bill
 
Rajagopal Manohar
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by William Brogden:
Benefits of JAXP:
1. it is in EVERY Java SE library, no thrashing around trying to make sure your customers have the right external library in the right place.
2. it is a complete implementation of the w3c DOM
3. the "pluggable" architecture has been refined to where you can plug in your own parser if you absolutely have to
4. Java 5 contains many convenience classes and methods - considerably more than the previous releases - example - the java.util.Properties class now has a loadFromXML method!!
Bill



Most of what you have listed are benifits of JAXP

What about the extra complexity of DOM over a more Java centric Tree model like JDOM or dom4j, Does that not make the latter more attractive to use?

But I agree that once you have decided that Tree model representation of XML is not what you need JAXP's SAX and probably STaX look attractive.
 
Rajagopal Manohar
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

2. it is a complete implementation of the w3c DOM



Hmmm...this is not the first time I am hearing this

What benefits does it offer to any Java developer who is not developing web browsers?
 
Reid M. Pinchback
Ranch Hand
Posts: 775
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Slight but understandable misconception. XML DOM exposed to Java has nothing to do with the browser DOM exposed to Javascript. They look a lot alike, but their purpose is slightly different.

The point of XML DOM is that it gives you an exact representation of everything it is possible to find in any XML document. Any feature allowed by the XML spec is supported by the XML DOM. It isn't always the most convenient tool, but it is the most complete. Historically it was the only API that you could use for both parsing and for serialization, but that isn't true anymore, there are other low-level XML APIs that provide serialization.
 
Joe Shy
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all the posts, I will definitely look into this more. I will be taking a class for my employer on J2EE which covers SAX and some DOM. I guess I will wait for that to start writing some code.

Thanks again,

Joe
reply
    Bookmark Topic Watch Topic
  • New Topic