2

I'm trying to parse xml from SharePoint service (lists) using jquery. I have XMLHttpRequest object xData which contains responseXML property, which is IXMLDOMDocument2.

xData.responseText has following value:

    <?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/"><GetListItemsResult>
<listitems xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
         xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
         xmlns:rs='urn:schemas-microsoft-com:rowset'
         xmlns:z='#RowsetSchema'>
    <rs:data ItemCount="2">
       <z:row ows_Title='Bosna i Hercegovina' ows_MetaInfo='1;#' ows__ModerationStatus='0' ows__Level='1' ows_ID='1' ows_owshiddenversion='1' ows_UniqueId='1;#{05EC6AB5-D1C6-4CCE-8B70-5FF7B922AE6A}' ows_FSObjType='1;#0' ows_Created='2010-10-29 15:59:59' ows_FileRef='1;#sites/state/Lists/CountryOfResidence/1_.000' />
       <z:row ows_Title='Hrvatska' ows_MetaInfo='2;#' ows__ModerationStatus='0' ows__Level='1' ows_ID='2' ows_owshiddenversion='1' ows_UniqueId='2;#{45FA88C3-17AF-4135-A926-6BE0C878EAAF}' ows_FSObjType='2;#0' ows_Created='2010-10-29 16:02:18' ows_FileRef='2;#sites/state/Lists/CountryOfResidence/2_.000' />
    </rs:data>
    </listitems>
</GetListItemsResult>
</GetListItemsResponse>
</soap:Body>
</soap:Envelope>

I use following code:

$(xData.responseXML).find("z:row").each(function () {
    var liHtml = "" + $(this).attr("ows_Title") + "";
    alert(liHtml);
    $("#tasksUL").append(liHtml);
   });

which, in fact does nothing. It is because $(xData.responseXML).find("z:row").length is 0, and only $(xData.responseXML).find("*") has length other than 0 (8 in this case).

So, my problem is jquery find function which does not recognize xml nodes I have, and I cannot find that anyone had similar problem.

2 Answers 2

1

You need to escape the colon. See the docs for more info.

Try this:

$(xData.responseXML).find("z\\:row")

Also, I thought there was an issue with colons in versions of jQuery prior to 1.4.3, but I can't locate that issue right now. If you're still having issues and you're using an older version, try upgrading.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I completely forgot that colon is a meta-character.
1

Also in Safari and Firefox this will not work. You need to use:

$(xData.responseXML).find("[nodeName=z:row]")

Hope this helps someone - took is a while to nut out!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.