Search code examples
javascriptrhinoe4xmirth

JavaScript / Rhino: Can I use a regular expression in an E4X query to select certain nodes only?


I'm working on Rhino (Mirth), and I've got to process / parse an XML with the following structure:

<root>
<row>
<foo-1 />
<foo-2 />
<foo-3 />
<foo-4 />
...
<bar-1 />
<bar-2 />
<bar-3 />
<bar-4 />
...
<something-else-1 />
<something-else-2 />
</row>
</root>

I want to get all the "foo" nodes only, avoiding the use of loops if possible. I've been trying somenthing like:

xml.row.(new RegExp("foo[1-4]").test()))

and a few variations of the same line, but it does not seem to work. Is there any E4X syntax / method to get this done?? I've been googling for a while, and i've read the ECMAS documentation, but i can't get this done.

Thanks in advance!


Solution

  • xml.row.*.( /foo-[1-4]/.test(function::localName()) )