Ian Piper
Ian Piper

Reputation: 21

Handling xml namespaces in jQuery

I have to parse an xml stream that contains a range of namespaces like this:

<zs:searchRetrieveResponse xmlns="http://www.directoryofchoice.co.uk"
xmlns:zs="http://www.loc.gov/zing/srw/" xmlns:diag="http://www.loc.gov/zing/srw/diagnostic/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.directoryofchoice.co.uk schema/content_node.xsd"
xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:lom="http://ltsc.ieee.org/xsd/LOM">
<zs:version>1.1</zs:version>
<zs:numberOfRecords>1066</zs:numberOfRecords>
<zs:records>
    <zs:record>
        <zs:recordSchema>info:srw/schema/1/dc-v1.1</zs:recordSchema>
        <zs:recordPacking>xml</zs:recordPacking>
        <zs:recordData>
            <srw_dc:dc xmlns:srw_dc="info:srw/schema/1/dc-schema">
                <dc:title>Mathematics subject leader development materials: Summer

Obviously this is just an indicative chunk of the code. The key point is that I have read about a number of methods (using dc\:title, using "[nodeName=dc:title]" and variations on these, and none of them work at all. I have demonstrated this by taking an xml stream like the one above and changing all the ":" to "-". Then it parses just fine. Is jQuery (I'm using 1.5.1) really not able to handle xml namespaces? That seems an amazing flaw given how common namespaces are nowadays. I don't want to learn another JavaScript toolkit, but is there another one that will handle namespaces?

Ian.

Upvotes: 2

Views: 374

Answers (1)

guido
guido

Reputation: 19194

You have to double-escape the colon ( dc\\:title ) and/or check this article (and the comments) to get some directions: http://www.xml.com/pub/a/2007/10/10/jquery-and-xml.html?page=2

Upvotes: 1

Related Questions