How to search by attribute value

Viewed 14008

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?

2 Answers
Related