Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referring to the first element, or to the second element 1

Status
Not open for further replies.

Bilberry

Programmer
Dec 17, 2007
111
NL
Hi all,

I have a xml document and a part is look like:

<LINEITEMS>
<LINEITEM>
<LINEITEMFIELD>1</LINEITEMFIELD>
<LINEITEMFIELD>125.65</LINEITEMFIELD>
<LINEITEMFIELD>test</LINEITEMFIELD>
</LINEITEM>
<LINEITEM>
<LINEITEMFIELD>2</LINEITEMFIELD>
<LINEITEMFIELD>129.65</LINEITEMFIELD>
<LINEITEMFIELD>test12323</LINEITEMFIELD>
</LINEITEM>
</LINEITEMS>

Im going to loop through the LINEITEM element. But all the LINEITEMFIELD doesnt have an attrbute, how can i refer to the first LINEITEMFIELD or to the second LINEITEMFILED within the LINEITEM node with a XPath expression...

TIA
 
Are these inspiring? If not, you really have to do some basic: that would save you more time in the long and even short run.
[tt]
LINEITEMS/LINEITEM[1]/LINEITEMFIELD[1]
LINEITEMS/LINEITEM[1]/LINEITEMFIELD[2]
LINEITEMS/LINEITEM[1]/LINEITEMFIELD[3]
LINEITEMS/LINEITEM[2]/LINEITEMFIELD[1]
LINEITEMS/LINEITEM[2]/LINEITEMFIELD[2]
LINEITEMS/LINEITEM[2]/LINEITEMFIELD[3]
[/tt]
 
I pretty sure what your trying to do goes against the basic rules of XML.

Your xpath may read the data in a different order from what is listed in your xml.

You could use a sort but again this would be unpredictable.

The point being if you want the fields read in a particular order rename them i.e. LINEITEMS1, LINEITEMS2 etc of add an attribute to allow you to sort realiably.

Regards

Chris
 
/LINEITEMS/LINEITEM[LINEITEMFIELD='1']
/LINEITEMS/LINEITEM[LINEITEMFIELD='2']
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top