Skip to main content
Participant
September 4, 2013
Question

Get all the XML elements in document with a given tag.

  • September 4, 2013
  • 1 reply
  • 669 views

I have a document marked up with XML Tags. I want an array or collection of all the elements in the document with the tag "red."

I've tried both of these functions, neither seem to work right:

var redElements = myDocument.xmlElements.itemByName("red");

var redElements = myDocument.xmlTags.itemByName("red").getElements();

What is the correct way to do this?

Many thanks.

This topic has been closed for replies.

1 reply

Participant
September 4, 2013

Is there a function to do this, or should I just loop through all the elements in the document and test them to see if they have the right tag?

Vamitul
Legend
September 4, 2013

use xpah:

var myRoot=doc.xmlElements.item(0);

var myRedElements=myRoot.evaluateXPathExpression("//red");  // myRedElements is now an array

Participant
September 7, 2013

That works great. Thanks!