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

XPath contains function - help needed

Status
Not open for further replies.

loequ

Programmer
Joined
Mar 2, 2004
Messages
3
Location
GB

I am having slight problems using the XPath contains() function. I have to following xml file


<Mod_Spec>
- <Module_Specification>
<Mod_Title>Web Application Development</Mod_Title>
<Mod_Code>COM409J1</Mod_Code>
<Mod_Level>2</Mod_Level>
<Credit_Pts>10</Credit_Pts>
<Semester>1</Semester>
<Mod_Status>Core</Mod_Status>
<Location>Belfast</Location>
<Prerequisite>COM1234</Prerequisite>
<Mod_Coordinator>Mr Bell</Mod_Coordinator>
<Teaching_Staff>Mr Bell</Teaching_Staff>
</Module_Specification>
</Mod_spec>


which consists of multiple Module_Specifications.

I want to return all the Module codes for which the user (session("UserName")) is the module coordinator. I have been trying using the following code, however does not return anything.

set EditList = ObjDOMDoc.selectNodes("Mod_Spec/Module_Specification/Mod_Coordinator[contains(.,'"& Session("UserName") & "')]/Mod_Code")

If I use this code

set EditList = ObjDOMDoc.selectNodes("Mod_Spec/Module_Specification/Mod_Coordinator[contains(.,'"& Session("UserName") & "')]")
it returns all the Module_Coordinator nodes - but this is not what i need.

Does anyone have any ideas???

Thanks in advance
loe
 
In your XPath, you are looking for Mod_Code as a child of Mod_Coordinator. These nodes are siblings. Your XPath should look like this:

Mod_Spec/Module_Specification[Mod_Coordinator = 'xxx']/Mod_Code

Not sure why you need contains() function if the name is an exact match.

Hope this helps.
 
Hi manitoba

Thanks for your suggestion, however Session("UserName") will not always be exact match to the data stored within Mod_Coordinator, therefore i cant see any other alternative but to use the contains function, however i still cant seem to get it working.

Loe
 
Manitoba is right.
Allyou have to do is add your function again:

Set EditList = ObjDOMDoc.selectNodes("Mod_Spec/Module_Specification[contains(Mod_Coordinator,'Bell')]/Mod_Code")
 
Hi guys

Just to let you know that i got a solution. I was treating Mod_Code as a child of Mod_Coordinator rather than a sibling, therefore the correct syntax is:

set EditList =
ObjDOMDoc.selectNodes("Mod_Spec/Module_Specification/Mod_Coordinator[contains(.,'"& Session("UserName") & "')]/ preceding-sibling::Mod_Code")

Thanks for everyones ideas
Loequ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top