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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XPath Question 1

Status
Not open for further replies.

woogoo

Programmer
Feb 14, 2004
247
GB
Hi All,

I have been given a file in the following format:
Code:
<ItemInformation xmlns="[URL unfurl="true"]http://tempuri.org/ItemInfo.xsd">[/URL]
  <ItemDetails>
    <Title>This is the item title</Title>
    <State>This is the item state</State>
    <ItemCost ... />
    <ItemCost ... />
    <ReOrder>
       <MinLevel>25000</MinLevel>
       <MaxLevel ... />
    </ReOrder>
  </ItemDetails>
</ItemInformation>
The ItemInfo.xsd does not exist. But how do I extract the Title element using XPath from this file? I've tried all manner of syntax but never get any results, can anyone help here please.


woogoo
 
[1] With the minimal concern on the missing info of the environment, you can do this.
[tt] //*[local-name()='Title'][/tt]

[2] Making use of the additional knowledge of its ancestors, this is a much more clumsy looking reasoning.
[tt] /*[local-name()='ItemInformation']/*[local-name()='ItemDetails']/*[local-name()='Title'][/tt]

[2.1] For each component, you can even use position index such as [1] ([position()=1]) for each of them to pick up unique Title which is the first encounter.

[3] If it is in some xslt document with some prefix pointing to the "[ignore][/ignore]" you can then use that prefix to form QName in the xpath sparing the clumsy looking of predicating all the time.

[4] >The ItemInfo.xsd does not exist.
The physical copy of ItemInfo.xsd is _never_ a concern of the namespace uri.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top