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).]
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).
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
posted
0
Thank you for your help. I'll try what you explained.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.