For the XML segment
"<ns0:BusCar_Request xmlns:ns0="http://BTSDG_SQL">
<ns0:sync>
<ns0:after>
<ns0:BusinessCards NameOnCard="NameOnCard_1"
TitleOnCard="TitleOnCard_1" Quantity="10" />
<ns0:BusinessCards NameOnCard="NameOnCard_2"
TitleOnCard="TitleOnCard_2" Quantity="10" />
<ns0:BusinessCards NameOnCard="NameOnCard_3"
TitleOnCard="TitleOnCard_3" Quantity="10" />
</ns0:after>
</ns0:sync>
</ns0:BusCar_Request>
"
I wrote the following code to get the suitable 'ns0:BusinessCards' element,
but everytime the compile return type returns boolean, could you help please
XPathDocument doc=new XPathDocument(dataFile);
XPathNavigator navigator=doc.CreateNavigator();
XmlNamespaceManager nsmgr= new XmlNamespaceManager(navigator.NameTable);
nsmgr.AddNamespace("ns0",@"http://BTSDG_SQL");
XPathExpression
exp=navigator.Compile(@"//BusinessCards/@TitleOnCard='TitleOnCard_3'");
exp.SetContext(nsmgr);
Console.WriteLine(exp.ReturnType);
"Pascal Schmitt" wrote:
Hello!
How to use XmlDocument and XPathNavigator (preferable) to do XPath query to
get the element with 'TitleOnCard' value equals to 'TitleOnCard_3'
Thanks in advance.
You need to Compile the XPath-String into an XPathExpression and assign
an XmlNamespaceManager to its context (untested):
XPathExpression ex = doc.Compile("/a:BusCar_Request/b:something");
XmlNamespaceManager mgr = new XmlNamespaceManager( doc.NameTable );
mgr.AddNamespacePrefix( "a", "urn:foo:a" );
mgr.AddNamespacePrefix( "b", "urn:foo:b" );
ex.Context = mgr;
doc.Evaluate( ex );
--
Pascal Schmitt