This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes xml JAVA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "xml JAVA" Watch "xml JAVA" New topic
Author

xml JAVA

Norazanita Adnan
Ranch Hand

Joined: May 28, 2008
Posts: 44
i need help...im so lost

my XML file
<veryDOC>
<MYDOCUMENT>
<DOCUMENT>
<STUDENT>
<NAME>Anorexic Al</NAME>
<ADDR>10 Slimway Rd</ADDR>
<GRADE>A</GRADE>
</STUDENT>
<STUDENT>
<NAME>Bulimic Bill</NAME>
<ADDR> 123 Upchuck Drive</ADDR>
<GRADE>B+</GRADE>
</STUDENT>
<STUDENT>
<NAME>Cadaverous Chen</NAME>
<ADDR>14 Mordant St.</ADDR>
<GRADE>B-</GRADE>
</STUDENT>
</DOCUMENT>
</MYDOCUMENT>
</veryDOC>

i want to write java code that read all the xml file and print out the output in the console like this...

(STUDENT , NAME ,Anorexic Al)
(STUDENT , ADDR ,10 Slimway Rd)
(STUDENT , GRADE ,A)
(STUDENT , NAME ,Bulimic Bill)
(STUDENT , ADDR ,123 Upchuck Drive)
(STUDENT , GRADE ,B+)
(STUDENT , NAME ,Cadaverous Chen)
(STUDENT , ADDR ,14 Mordant St)
(STUDENT , GRADE ,B-)
(DOCUMENT , STUDENT , NAME)
(MYDOCUMENT, DOCUMENT,STUDENT)
(veryDOC , MYDOCUMENT ,DOCUMENT)


meaning it will travers to the very inner child node and go up to the root

anyway is it possible to be done?
ive try few example but it cant read the value unless we do it something like ..i need to make the code flexible as i dont know the name of element in xml files.

is there any example that similar to this.hope someone able to help me..

thanks in advance
Gamini Sirisena
Ranch Hand

Joined: Aug 05, 2008
Posts: 347
With DOM you may need to go recursive here. Try with getChildNodes
Norazanita Adnan
Ranch Hand

Joined: May 28, 2008
Posts: 44


this is my code and this is the result :-

Enter XML File name: student.xml
Root element of the doc is veryDOC
TRAVERSE ...
Node: veryDOC value=[null]
Node: #text value=[]
Node: MYDOCUMENT value=[null]
Node: #text value=[]
Node: DOCUMENT value=[null]
Node: #text value=[]
Node: STUDENT value=[null]
Node: #text value=[]
Node: NAME value=[null]
Node: #text value=[Anorexic Al]
Node: #text value=[]
Node: ADDR value=[null]
Node: #text value=[10 Slimway Rd]
Node: #text value=[]
Node: GRADE value=[null]
Node: #text value=[A]
Node: #text value=[]
Node: #text value=[]
Node: STUDENT value=[null]
Node: #text value=[]
Node: NAME value=[null]
Node: #text value=[Bulimic Bill]
Node: #text value=[]
Node: ADDR value=[null]
Node: #text value=[123 Upchuck Drive]
Node: #text value=[]
Node: GRADE value=[null]
Node: #text value=[B+]
Node: #text value=[]
Node: #text value=[]
Node: STUDENT value=[null]
Node: #text value=[]
Node: NAME value=[null]
Node: #text value=[Cadaverous Chen]
Node: #text value=[]
Node: ADDR value=[null]
Node: #text value=[14 Mordant St.]
Node: #text value=[]
Node: GRADE value=[null]
Node: #text value=[B-]
Node: #text value=[]
Node: #text value=[]
Node: #text value=[]
Node: #text value=[]


what can i modify to make it

(STUDENT , NAME ,Anorexic Al)
(STUDENT , ADDR ,10 Slimway Rd)
(STUDENT , GRADE ,A)
(STUDENT , NAME ,Bulimic Bill)
(STUDENT , ADDR ,123 Upchuck Drive)
(STUDENT , GRADE ,B+)
(STUDENT , NAME ,Cadaverous Chen)
(STUDENT , ADDR ,14 Mordant St)
(STUDENT , GRADE ,B-)
(DOCUMENT , STUDENT , NAME)
(MYDOCUMENT, DOCUMENT,STUDENT)
(veryDOC , MYDOCUMENT ,DOCUMENT)


any idea??

hope anyone can help me
 
Consider Paul's rocket mass heater.
 
subject: xml JAVA
 
Similar Threads
Display XML tag using JSTL
read the XML file
question about AttributeList interface
How to modify the XML Document?
How to update the xml tag attributes for the given tag