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:
- to download the referenced document,
- 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.
精彩评论