-1

Sample XML:

<Books>
<Book id="1" Name="C#">
<URL>http://localhost/download/M1.xml</URL>
</Book>

<Book id="2" Name="Oracle">
<URL>http://localhost/download/M2.xml</URL>
</Book>

<Book id="3" Name="Archius">
<URL>http://localhost/download/M3.xml</URL>
<URL>http://localhost/download/M4.xml</URL>
</Book>
</Books>

I have to fetch only the book name attribute and use it for display .However say for example ,I have got the list of Books ie(C#,Oracle,Archius) ,passing this value to a method should return me an array of URL nodes value within it.

The idea is to display the book names in a list and then on user selection , corresponding URL needs to be fetched.

Was able to get the loop for traversing the nodes

 NodeList nodeList = document.getDocumentElement().getElementsByTagName ("Book");
 for (int i = 0; i < nodeList.getLength(); i++) {...

SO, a) Display the BookNames b) Get the corresponding URL's for the particular book if I pass the Bookname

Alfaromeo
  • 379
  • 2
  • 6
  • 14

1 Answers1

0

That won't work as you expect. You said "Get the corresponding URL's for the particular book if I pass the Bookname", but there might be a same book name exist. So you definitely need additional items, either ISBN or SKU or any kind of stuff you can use it as primary key.

Probably you need to parse more than that if you want to support preview with book image when mouse is hover or something... but anyway if you are going to use just a few items of entire XML.. then it should be SAX parser IMO.

wonhee
  • 1,581
  • 1
  • 14
  • 24