1

I have following XML:

<article>
    <div class="class1">
        <span>Article header 1</span>
        <div>
            <span>Date</span>
        </div>
    </div>
    <div class="class2">
        <span>Details</span>
        <div class="class3">
            <span>Number</span>
        </div>
    </div>
    <div>
        <span>Price 1</span>
    </div>
    <div class="class3">
        <span>Footer 1</span>
        <div>Footer details</div>
    </div>
</article>
<article>
    <div class="class1">
        <span>Article header 2</span>
        <div>
            <span>Date</span>
        </div>
    </div>
    <div>
        <span>Price 2</span>
    </div>
    <div class="class2">
        <span>Details</span>
        <div class="class3">
            <span>Number</span>
        </div>
    </div>
    <div class="class3">
        <span>Footer 2</span>
        <div>Footer details</div>
    </div>
</article

And I want to select only DIV without class and only from first nesting level In this case

    <div>
        <span>Price 1</span>
    </div>

and

    <div>
        <span>Price 2</span>
    </div>

Note that this div in first article is on 3 place but in second article is on 2 place

I tried to use


//div[not(@class)]

but it find all elements in article, not only from first nest

1 Answers1

1

You were close to the right expression.
This will select what you are looking for:

article/div[not(@class)]

This article/div indicates the direct div child element of the top node article.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
Prophet
  • 32,350
  • 22
  • 54
  • 79