开发者

Jquery xml parse question

开发者 https://www.devze.com 2023-02-18 10:23 出处:网络
I have an xml开发者_StackOverflow社区 which contains reference to internal vocabulary How can I use jquery to resolve this reference and parse successfully..

I have an xml开发者_StackOverflow社区 which contains reference to internal vocabulary

How can I use jquery to resolve this reference and parse successfully..

XML

<something>
<element reference="../../../../test"/>
</something>

Any ideas would be much appreciated..


Using the latest version of jQuery (1.5.1), yes.

var XML = '<something><element reference="../../../../test"/></something>';
var xmlDoc = $( $.parseXML(XML) );

//Alerts out "../../../../test"
alert( xmlDoc.find("element").attr("reference") );

jsFiddle: http://jsfiddle.net/nKAGP/


You need:

  1. to download the referenced document,
  2. to parse this document.

You may perform an AJAX request with jQuery, which will do both steps:

$.ajax({
  type: "GET",
  url: "URL of the document (possibly relative)",
  dataType: "xml",
  success: function(xml) {
    $(xml). ...  // now you may use jQuery functions to explore the document
  }
}

EDIT: The URL document may be retrieved from your first XML document using motionman95's answer. Then you pass it to the above and you get the referenced XML document.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号