0

I have an xml 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..

1
  • Is your XML a string readily available or is it returned via AJAX? Commented Mar 16, 2011 at 22:23

2 Answers 2

1

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/

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.