Jarek Lupinski
Jarek Lupinski

Reputation: 45

Getting Data under Complex Namespaces in Javascript

I have the following XML that I need to be able to pull specific fields from:

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
<id>Cases</id>
<title type="text">CaseList</title>
<updated>2013-04-04T15:32:56Z</updated>
<author>
<name/>
</author>
<link href="CaseList" rel="self" title="CaseList"/>
<entry>
    <id>291</id>
    <title type="text">CaseList('291')</title>
    <updated>2013-04-04T15:32:56Z</updated>
    <category term="S.Cases" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
        <content type="application/xml">
            <m:properties>
                <d:case_id>291</d:case_id>
                <d:case_title>Global Case</d:case_title>
                <d:case_type>Meso</d:case_type>
        </m:properties>
    </content>
</entry>
<entry>
    <id>291</id>
    <title type="text">CaseList('292')</title>
    <updated>2013-04-04T15:38:56Z</updated>
    <category term="S.Cases" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
        <content type="application/xml">
            <m:properties>
                <d:case_id>292</d:case_id>
                <d:case_title>Global Case 2</d:case_title>
                <d:case_type>Meso 2</d:case_type>
        </m:properties>
    </content>
</entry>
</feed>

I've tried almost everything, but I feel that there is a core XML concept I'm missing that would help me extract nodes such as d:case_id. Is there a simple way of pulling out one or more nodes using Javascript? The other namespace questions don't include a namespace within another namespace... here, the values I'm interested in are behind m:properties.

Upvotes: 1

Views: 155

Answers (1)

user2310605
user2310605

Reputation: 36

I have used this

parentNode.getElementsByTagNameNS("*", "name");

and it worked fine for me in chrome and IE10 browser.

Please follow the below link for details:

jQuery XML parsing with namespaces

Upvotes: 1

Related Questions