• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

xml JAVA

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With DOM you may need to go recursive here. Try with getChildNodes
 
Norazanita Adnan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
 
Ever since I found this suit I've felt strange new needs. And a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic