aspose file tools*
The moose likes XML and Related Technologies and the fly likes XML processing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML processing" Watch "XML processing" New topic
Author

XML processing

Joon Park
Greenhorn

Joined: Jul 10, 2001
Posts: 6
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

Joined: Mar 17, 2000
Posts: 5782
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.


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Amit Ganatra
Greenhorn

Joined: Jun 19, 2001
Posts: 19
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).]


SCJP2
Joon Park
Greenhorn

Joined: Jul 10, 2001
Posts: 6
Thank you for your help. I'll try what you explained.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: XML processing