aspose file tools*
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
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: 375
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: xml JAVA