0

Bear with me, I'm new to manipulating XML using jQuery.

Say I have an XML document that looks something like this:

<sitemap>
  <products name="products" url="/products.html">
     <shirts name="women's shirts" url="/womens-shirts.html">
     <shoes name="women's shoe" url="/womens-shoes.html">
     <pants....>
  </products>
  <services>
     <shopping>
     <consultation>
  </services>
</sitemap>

etc., where each child node of has both a name and a URL (I'm populating a breadcrumb based on window.location.pathname). I want to search for a specific URL (it should match whatever page you're on), which can be in any node, either parent or child. How do I do this without specifying the node I am searching under?

Thanks!

1 Answer 1

1

To specify any element name, use an asterisk:

*[url='/products.html']
Sign up to request clarification or add additional context in comments.

1 Comment

$(document).ready(function() { $.ajax({ type: "GET", url: "/_assets/xml/sitemap.xml", dataType: "xml", error: function(){alert('Error loading XML document');}, success: parseXML }); function parseXML(xml) { var pathname = window.location.pathname; $(xml).find(*[url=pathname]).each(function() { alert(url); }); } });

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.