Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
169
rated 0 times [  171] [ 2]  / answers: 1 / hits: 67578  / 15 Years ago, tue, may 12, 2009, 12:00:00

I'm new to jQuery and would like to parse an XML document.



I'm able to parse regular XML with the default namespaces but with XML such as:



<xml 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>
<s:Schema id=RowsetSchema>
<s:ElementType name=row content=eltOnly rs:CommandTimeout=30>
<s:AttributeType name=ows_ID rs:name=ID rs:number=1>
<s:datatype dt:type=i4 dt:maxLength=4 />
</s:AttributeType>
<s:AttributeType name=ows_DocIcon rs:name=Type rs:number=2>
<s:datatype dt:type=string dt:maxLength=512 />
</s:AttributeType>
<s:AttributeType name=ows_LinkTitle rs:name=Title rs:number=3>
<s:datatype dt:type=string dt:maxLength=512 />
</s:AttributeType>
<s:AttributeType name=ows_ServiceCategory rs:name=Service Category rs:number=4>
<s:datatype dt:type=string dt:maxLength=512 />
</s:AttributeType>
</s:ElementType>
</s:Schema>
<rs:data>
<z:row ows_ID=2 ows_LinkTitle=Sample Data 1 />
<z:row ows_ID=3 ows_LinkTitle=Sample Data 2 />
<z:row ows_ID=4 ows_LinkTitle=Sample Data 3 />
</rs:data>
</xml>


All I really want are the <z:row>.



So far, I've been using:



$.get(xmlPath, {}, function(xml) {
$(rs:data, xml).find(z:row).each(function(i) {
alert(found zrow);
});
}, xml);


with really no luck. Any ideas?


More From » jquery

 Answers
10

I got it.



Turns out that it requires \ to escape the colon.



$.get(xmlPath, {}, function(xml) {
$(rs\:data, xml).find(z\:row).each(function(i) {
alert(found zrow);
});
}, xml);


As Rich pointed out:



The better solution does not require escaping and works on all modern browsers:



.find([nodeName=z:row])

[#99553] Thursday, May 7, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
iyannae

Total Points: 147
Total Questions: 88
Total Answers: 120

Location: Japan
Member since Sat, Jun 6, 2020
4 Years ago
;