This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

reading xml file dynamically

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i need to read a dynamic xml file from java code.. i have googled it but got only code for static xml parsing...can any one help in this regard...thanking you in advance.
 
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you tell us where you see the difference between static and dynamic XML parsing is? Those are not terms that are commonly used.
 
ash chowdary
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dynamic in the sense that, we will be getting an xml file,in which we don't know the nodes of that file except root node.
 
Ulf Dittmer
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the operations that you need to perform on the XML?
 
ash chowdary
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
need to read all nodes and respective values.
 
Ulf Dittmer
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any API can do that: SAX, DOM, JDOM, XOM, ...
 
Bartender
Posts: 2330
100
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
All code online would be according to your defination, "static"

This is because usually a parser has an idea about the grammar
The apis mentioned will allow you to access the elements of an xml file

so say, you have the following:



and :


When you parse this with SAX,
you will come across document start eg: root
and for every tag, you will read the element start eg: name/userId
then you will read the chars within it eg: "salvin" / "java"
Now its up to you to write logic for them.
Without logic, its only known that A contains B.
 
salvin francis
Bartender
Posts: 2330
100
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
also note that the example I have written is "flat" and usually xml contains nested data within tags...



So here, your code should expect that "site" is a parent for a series of elements including "name","desc","url"
also note the attributes "isMultiline" and "openInNewWindow"

what would you expect the code to do in the given xml example ?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!