How to use jQuery for XML parsing with namespaces

后端 未结 20 1659
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 10:17

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:



        
20条回答
  •  迷失自我
    2020-11-22 10:42

    just replaced the namespace by empty string. Works fine for me. Tested solution across browsers: Firefox, IE, Chrome

    My task was to read and parse an EXCEL-file via Sharepoint EXCEL REST API. The XML-response contains tags with "x:" namespace.

    I decided to replace the namespace in the XML by an empty string. Works this way: 1. Get the node of interest out of the XML-response 2. Convert the selected node XML-Response (Document) to String 2. Replace namespace by empty string 3. Convert string back to XML-Document

    See code outline here -->

    function processXMLResponse)(xData)
    {
      var xml = TOOLS.convertXMLToString("", "",$(xData).find("entry content")[0]);
      xml = xml.replace(/x:/g, "");            // replace all occurences of namespace
      xData =  TOOLS.createXMLDocument(xml);   // convert string back to XML
    }
    

    For XML-to-String conversion find a solution here: http://www.sencha.com/forum/showthread.php?34553-Convert-DOM-XML-Document-to-string

提交回复
热议问题