By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,934 Members | 1,677 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,934 IT Pros & Developers. It's quick & easy.

xpath fails : "Parameter" have special meaning ?

P: n/a
Is there something special in XML about the name "Parameter" ... I am not
able to XPATH query for nodes named "Parameter"

<Root>
<Category CategoryID="1">
<Elements>
<Element ElementID="1"></Element>
<Element ElementID="2"></Element>
<Element ElementID="3"></Element>
</Elements>
<Parameters>
<Parameter ParameterID="1"></Parameter>
<Parameter ParameterID="2"></Parameter>
<Parameter ParameterID="3"></Parameter>
</Parameters>
</Category>
<Category CategoryID="2">
</Category>
</Root>
XMLDocument xmldoc = New XMLDocument;
xmldoc.Load("<path to above file>");
string xpath = "/Root/Category[@CategoryID='1']/Elements/Element";
XMLNodeset nodes = xmldoc.SelectNodes(xpath);
//nodes.Count = 3

xpath = "/Root/Category[@CategoryID='1']/Parameters/Parameter";
nodes = xmldoc.SelectNodes(xpath);
//nodes.Count = 0
Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hello!
XMLDocument xmldoc = New XMLDocument;
xmldoc.Load("<path to above file>");
string xpath = "/Root/Category[@CategoryID='1']/Elements/Element";
XMLNodeset nodes = xmldoc.SelectNodes(xpath);
//nodes.Count = 3

xpath = "/Root/Category[@CategoryID='1']/Parameters/Parameter";
nodes = xmldoc.SelectNodes(xpath);
//nodes.Count = 0


Is this really your code? Maybe you have a typo in the original?

Does this work:
XmlElement params =
xmldoc.SelectSingleNode("/Root/Category[@CategoryID='1']/Parameters") as
XmlElement;
params.SelectNodes("Parameter").Count...

--
Pascal Schmitt
Nov 12 '05 #2

P: n/a
The following vbscript can get correct result, maybe you need to double
check your code.

Set xmlDoc = CreateObject("Msxml2.DOMDocument.4.0")
xmlDoc.async = false
xml_path = "onega.xml"
xmlDoc.load xml_path
xmlDoc.setProperty "SelectionLanguage", "XPath"
xpath_str = "/Root/Category[@CategoryID='1']/Parameters/Parameter"
set objNodeList = xmlDoc.documentElement.selectNodes(xpath_str)
WScript.Echo CStr(objNodeList.length)

"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:em****************@TK2MSFTNGP12.phx.gbl...
Is there something special in XML about the name "Parameter" ... I am not
able to XPATH query for nodes named "Parameter"

<Root>
<Category CategoryID="1">
<Elements>
<Element ElementID="1"></Element>
<Element ElementID="2"></Element>
<Element ElementID="3"></Element>
</Elements>
<Parameters>
<Parameter ParameterID="1"></Parameter>
<Parameter ParameterID="2"></Parameter>
<Parameter ParameterID="3"></Parameter>
</Parameters>
</Category>
<Category CategoryID="2">
</Category>
</Root>
XMLDocument xmldoc = New XMLDocument;
xmldoc.Load("<path to above file>");
string xpath = "/Root/Category[@CategoryID='1']/Elements/Element";
XMLNodeset nodes = xmldoc.SelectNodes(xpath);
//nodes.Count = 3

xpath = "/Root/Category[@CategoryID='1']/Parameters/Parameter";
nodes = xmldoc.SelectNodes(xpath);
//nodes.Count = 0

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.