This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML processing

 
Joon Park
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I'm new to XML processing in Java and I need some help. I have following XML file that I want to extract a vector of store object from:
<CHAINS>
--<STORE>
----<LOCATION>USA</LOCATION>
----<REVENUE>120000</REVENUE>
----<MENU>
------<ITEM>Big Burger</ITEM>
------<ITEM>Taco Salad</ITEM>
------<ITEM>Huge Drink</ITEM>
----</MENU>
--</STORE>
--<STORE>
----<LOCATION>CAN</LOCATION>
----<REVENUE>90000</REVENUE>
----<MENU>
------<ITEM>Big Burger</ITEM>
------<ITEM>French Toast</ITEM>
----</MENU>
--</STORE>
--<STORE>
----<LOCATION>JPN</LOCATION>
----<REVENUE>150000</REVENUE>
----<MENU>
------<ITEM>Big Burger</ITEM>
------<ITEM>Taco Salad</ITEM>
------<ITEM>Miso Soup</ITEM>
------<ITEM>Sushi Salad</ITEM>
------<ITEM>Huge Drink</ITEM>
----</MENU>
--</STORE>
.
.
.
</CHAINS>
How do I go about doing this? I was able to retrieve locations and revenues from it somehow and built a vector of store object, but I couldn't figure out how to retrieve Menu items (Menu items are different from location to location). I hope there is easier way to getting store object. Thanks in advance for your help.
[This message has been edited by Joon Park (edited July 29, 2001).]
 
Ajith Kallambella
Sheriff
Posts: 5782
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you looked at DOM API? The Document object provides several methods that can be used to retrieve nodes based on node-name. Also checkout the JDOM Framework that automatically converts the DOM objects into Java collections.
Cheers!
------------------
Ajith Kallambella M.
Sun Certified Programmer for the Java�2 Platform.
IBM Certified Developer - XML and Related Technologies, V1.
 
Amit Ganatra
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joon Park:
Hello,
as Ajith mentioned in his reply, to check DOMAPI as solution to your query.
I would simply add to it by saying u can use:
NodeList list = doc.getElementsByTageName("Menu");
to each Menu object u can then ask for its childNodes i.e.
NodeList children = Menu.getChildNodes();
Hope this helps,

I'm new to XML processing in Java and I need some help. I have following XML file that I want to extract a vector of store object from:
<CHAINS>
--<STORE>
----<LOCATION>USA</LOCATION>
----<REVENUE>120000</REVENUE>
----<MENU>
------<ITEM>Big Burger</ITEM>
------<ITEM>Taco Salad</ITEM>
------<ITEM>Huge Drink</ITEM>
----</MENU>
--</STORE>
--<STORE>
----<LOCATION>CAN</LOCATION>
----<REVENUE>90000</REVENUE>
----<MENU>
------<ITEM>Big Burger</ITEM>
------<ITEM>French Toast</ITEM>
----</MENU>
--</STORE>
--<STORE>
----<LOCATION>JPN</LOCATION>
----<REVENUE>150000</REVENUE>
----<MENU>
------<ITEM>Big Burger</ITEM>
------<ITEM>Taco Salad</ITEM>
------<ITEM>Miso Soup</ITEM>
------<ITEM>Sushi Salad</ITEM>
------<ITEM>Huge Drink</ITEM>
----</MENU>
--</STORE>
.
.
.
</CHAINS>
How do I go about doing this? I was able to retrieve locations and revenues from it somehow and built a vector of store object, but I couldn't figure out how to retrieve Menu items (Menu items are different from location to location). I hope there is easier way to getting store object. Thanks in advance for your help.
[This message has been edited by Joon Park (edited July 29, 2001).]

 
Joon Park
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your help. I'll try what you explained.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic