Link to home
Create AccountLog in
Avatar of Steve Hougom
Steve HougomFlag for United States of America

asked on

parsing xml in javascript

I was wondering how to parse out the following values in the "title" tag in the xml using javascript.
Its some xml I get back from a sharepoint list.  I want to put them in some sort of container I can us for binding or displaying.  
 
Values are:
orange,
peach,
cherry

And put them in some sort of container I can use later.
<?xml version="1.0" encoding="utf-8"?><feed xml:base="https://somesite/sites/cs/_api/" xmlns="http://
www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://
schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://
www.opengis.net/gml"><id>bd62831a-2c0f-4118-9268-e3dfff241615</id><title /><updated>2016-03-09T14:41:07Z</
updated><entry m:etag="&quot;4&quot;"><id>Web/Lists(guid'cece37e3-206b-4021-8c2b-f91c41c62602')/Items(1)</
id><category term="SP.Data.POC_x005f_FruitListItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/
scheme" /><link rel="edit" href="Web/Lists(guid'cece37e3-206b-4021-8c2b-f91c41c62602')/Items(1)" /><title /
><updated>2016-03-09T14:41:07Z</updated><author><name /></author><content type="application/
xml"><m:properties><d:Title>Orange</d:Title></m:properties></content></entry><entry m:etag="&quot;3&quot;"><id>Web/
Lists(guid'cece37e3-206b-4021-8c2b-f91c41c62602')/Items(2)</id><category term="SP.Data.POC_x005f_FruitListItem"
scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /><link rel="edit" href="Web/
Lists(guid'cece37e3-206b-4021-8c2b-f91c41c62602')/Items(2)" /><title /><updated>2016-03-09T14:41:07Z</
updated><author><name /></author><content type="application/xml"><m:properties><d:Title>Apple</d:Title></
m:properties></content></entry><entry m:etag="&quot;1&quot;"><id>Web/Lists(guid'cece37e3-206b-4021-8c2bf91c41c62602')/
Items(3)</id><category term="SP.Data.POC_x005f_FruitListItem" scheme="http://schemas.microsoft.com/
ado/2007/08/dataservices/scheme" /><link rel="edit" href="Web/Lists(guid'cece37e3-206b-4021-8c2b-f91c41c62602')/
Items(3)" /><title /><updated>2016-03-09T14:41:07Z</updated><author><name /></author><content type="application/
xml"><m:properties><d:Title>Peach</d:Title></m:properties></content></entry><entry m:etag="&quot;1&quot;"><id>Web/
Lists(guid'cece37e3-206b-4021-8c2b-f91c41c62602')/Items(4)</id><category term="SP.Data.POC_x005f_FruitListItem"
scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /><link rel="edit" href="Web/
Lists(guid'cece37e3-206b-4021-8c2b-f91c41c62602')/Items(4)" /><title /><updated>2016-03-09T14:41:07Z</
updated><author><name /></author><content type="application/xml"><m:properties><d:Title>Cherry</d:Title></
m:properties></content></entry></feed>

Open in new window



Thanks
ASKER CERTIFIED SOLUTION
Avatar of Am P
Am P
Flag of India image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Steve Hougom

ASKER

Ive been to that exact page already.  Still trying to figure it out.

Im even just trying to get the first occurrence and this spits out nothing. (I know I need a for loop)

function myFunction(xml) {
      
    var xmlDoc = xml.responseXML;
    var test;
   
     //document.getElementById("demo").innerHTML =
     test = xmlDoc.getElementsByTagName("d:Title")[0].childNodes[0].nodeValue;
       alert(test);
 }