Itunes Xml Parsing using XPath Java

![1]: “Xml File Sample”

Hi guys, I try to parse xml library using XPath. The following expression returns me the name of the track (What’s up)

String exp = "//dict/dict/key[. = 'Name']/following-sibling::*[1]/text()";
String name =  (String) this.xpath.compile(exp).evaluate(this.doc, XPathConstants.STRING);

How can I loop through dict to get all track name,artist,album, I tried to do something like this but then I was stuck.

String baseExp = "//dict/dict"; // returns me 2084 node (the number of songs I have in my library)
NodeList nodeList = (NodeList) this.xpath.compile(baseExp).evaluate(this.doc, XPathConstants.NODESET);
for(int i=0;i<nodeList.getLength();i++) {
  // need do something here?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s