I guess I just hate having to compile an expression when I do an Evaluate
rather than Select.
XmlNamespaceMan ager nsmgr = new XmlNamespaceMan ager(doc.NameTa ble);
nsmgr.AddNamesp ace("xs",
http://mynamespace.com);
xpExp = nav.Compile("st ring(//xs:person/@name)");
xpExp.SetContex t(xmlNSM);
string name = (string) nav.Evaluate(xp Exp);
if I need to pull another value out I need to compile a new expression,
setcontext and Evaluate again...and so on...
xpExp = nav.Compile("st ring(//xs:person/@department)");
xpExp.SetContex t(xmlNSM);
string department = (string) nav.Evaluate(xp Exp);
I could always wrap it all up in helper functions or a class, but Ideally it
would have been good if I could at least reuse the same expression object
and just the path or SetContext() would remain valid -
nav.SetContext( namespace); // set namespace for xpath
val1 = nav.Evaluate();
val2 = nav.Evaluate();
"Oleg Tkachenko" <oleg@NO_SPAM_P LEASEtkachenko. com> wrote in message
news:%2******** *******@TK2MSFT NGP11.phx.gbl.. .
Steve Robinson wrote:
Just out of interest - is there an easier/quicker way to retrieve values
via Xpath when namespaces are used?
If you mean using NamespaceManage r - no, you cannot avoid using it when
seleting namespaced nodes, unless your XPath expression is
namespace-prefix-neutral, like
//*[local-name='person' and namespace-uri()='http://mynamespace.com ']
instead of
//xs:person
And in fact I don't see any problem with using NamespaceManage r - anyway
must be some way to say what xs namespace prefix you are using points
to, becuase arbitrary XML doc may declare xs namespace prefix twice,
each time binding it to a different namespace URI's:
<xs:foo xmlns:xs="foo">
<xs:bar xmlns:xs="bar"> blah</xs:bar>
</xs:foo>
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel