tags:

views:

40

answers:

2

Can I split a level of an XML document with an XPath expression into a list? I have this, for example:

<root>
  <test1 />
  <testX />
  <test2 />
  <test21 />
  <testX />
  <test3 />
</root>

so running it on this returns a list with <test1 />, <test2 /><test21 /> and <test3 />.

There is not necessarily just one node between <testX />, there can be a varying number.

+2  A: 

Find the first element under root, and the first element that follows each "testX" element. Excepting those elements that are named "testX".

(/root/*[1] | /root/*['testX' = name(preceding-sibling::*[1]))[name() != 'testX']

Some MSDN links on XPath:

Lachlan Roche
It is not necessarily every second node. There can be a verying number of elements between the textX elements
Per Stilling
I've elaborated my initial question
Per Stilling
A: 
/root/*[not(self::testX)]

would select

<test1 />
<test2 />
<test21 />
<test3 />
Tomalak