I have the following XML doc:
<files>
<elements xsi:type="foo:elementType1">
<name>foo1</name>
</elements>
<elements xsi:type="foo:elementType1">
<name>foo2</name>
<other>
<elements>
<data1>data1</data1>
<data2>data2</data2>
</elements>
</other>
</elements>
<elements>
<name>foo3</name>
<affiliates>
<elements xsi:type="foo:elementType1">
<name>foo4</name>
</elements>
</affiliates>
</elements>
</files>
I need to grab only the elements which have type = "foo:elementType1"
. I tried this, but I'm getting empty results.
elems = doc.search("//elements[@type='foo:elementType1']")
What am I missing?
EDIT: Using a trimmed down (SO character constraints) copy of the XML provided by OP, this appears to work properly using Nokogiri v1.5.0:
I never use the xpath syntax because it's never been intuitive for me but using the css selector interface this should work: