I'm trying to loop through xml and extract values and persist it to mysql using rest . this is what i have so far.But its only extracting the first string that has value songIts adding to the database but id like to add two at a time.
NodeList artistList = (NodeList)xPath.evaluate("/plist/dict/dict/dict/string[@rollno='artist']", root, XPathConstants.NODESET); for (int i = 0; i < artistList.getLength(); ++i) { Element e = (Element) artistList.item(i); artist= e.getFirstChild().getNodeValue(); book.setIsbn(artist); book.setName(song); returnCode = "200"; em = Resource.getEntityManager(); } This is the xml which i'm trying to parse using xpath i'd like to extract all rollno="song" and persist them one after the other ,any advice or help will mean a lot .Thanks
<plist version="1.0"> <dict> <key>Major Version</key> <integer>1</integer> <key>Application Version</key> <string>7.0.2</string> <key>Show Content Ratings</key> <true /> <key>Tracks</key> <dict> <key>1288</key> <dict > <key>Track ID</key> <integer>1288</integer> <key>Name</key> <string rollno="song">Brighter Than Sush</string> <key>Artist</key> <string rollno="artist">Aqualug</string> <key>Album Artist</key> <string>Aqualung</string> <key>Album</key> <key>Track ID</key> <integer>1288</integer> <key>Name</key> <string rollno="song">james</string> <key>Artist</key> <string rollno="artist">martha</string> <key>Album Artist</key> <string>Aqualung</string> <key>Album</key> </dict> </dict> </dict> </plist>
No comments:
Post a Comment