Jump to content

XPATH Limiting search beyond level 1


srikanthmm

Recommended Posts

Hello, I have the following xml

    <XMLDataPersistence>       <Duration>30</Duration>       <HistoryFields>            <Id>                <Mandatory>True</Mandatory>                <Modifiable>True</Modifiable>                <Type>Text</Type>            </Id>        </HistoryFields></XMLDataPersistence>

I am able to query upon duration as selectNodes("//XMLDataPersistence[Duration=30]") which gives coresponding XMLDataPersistence node. But similarly if I try to query selectNodes("//XMLDataPersistence/HistoryFields/Id[Mandatory=True]") does not return anything. But selectNodes("//XMLDataPersistence/HistoryFields/Id") or selectNodes("//XMLDataPersistence/HistoryFields/Id/Mandatory") returns respective nodes. I can then compare each mandatory node's text but ideally I would like the search do it for me.I even tried to get the HistoryFields nodes and do selectNodes("//Id[Mandatory=True]"); - no luck - returns nothing.Any help will be much appreciated.

Link to comment
Share on other sites

I added single quotes around true, seems to work

<html><xml id="Activities">	<XMLDataPersistence>		<Duration>30</Duration>		<HistoryFields>		<Id>			<Mandatory>True</Mandatory>			<Modifiable>True</Modifiable>			<Type>Text</Type>		</Id>		</HistoryFields>	</XMLDataPersistence></xml><script>	var oNode = Activities.selectSingleNode("//XMLDataPersistence[Duration=30]")	document.write(oNode.xml)	document.write("<br>")	oNode = Activities.selectSingleNode("//XMLDataPersistence/HistoryFields/Id[Mandatory='True']")	document.write(oNode.xml)</script></html>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...