• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to print Comments available in xml

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<?xml version="1.0" encoding="UTF-8"?>
<Library>
   <Book id="111">
       <name>Core Java</name>
       <department>Computer</department>
       <!-- Book Rack 122 -->
   </Book >
 
   <Book id="112">
       <name>VB .NET</name>
       <department>Computer</department>
       <!-- Book Rack 127 -->
   </Book >
</Library>


How do i parse this xml and print the comments using Java?

Output expected:
Name: Core Java
Book Rack 122
Name: VB .NET
Book Rack 127


Thanks in advance
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java has different APIs for parsing XML.

For something like this, I would choose one of the lower-level APIs: DOM, SAX or StAX.
(It won't be easy to get at the comments when you use the higher-level JAXB API).

Here are some good tutorials: A Guide to XML in Java

The easiest will probably to use the DOM API. Tutorial here: How to read XML file in Java – (DOM Parser)
The comments will show up as nodes in the DOM tree, just like everything else in the XML.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic