• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Code sample request  RSS feed

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,
Given this small xml:
<message>
<from> aaa </from>
<to> bbb </to>
<cc> ccc </cc>
<text> Hello </text>
</message>
Could somebody please send me a small piece of Java code preferable using DOM showing how to extract values "aaa"
"bbb" "ccc" and "Hello"?
Thanks in advance
Ambrose
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ambrose,
Unfortunately I can not take the time to do the actual code for you, but I can tell you how to proceed in order to accomplish what you are asking...
First of all you need to use a DOMParser object to parse your xml file into a DOM Document (). Once you have this you could search the elements by using the getElementsByTagName method and then get the child node of the element (which would be a text node type). After this you could use the getNodeValue method to return you corresponding text values....
Hope this helps!
Cheers!
Johannes
 
Not so fast naughty spawn! I want you to know about
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!