"Bob" <anonymous (AT) discussions (DOT) microsoft.com> wrote
Quote:
Below is some code that use to work. Now it is not
: :
The only thing I can figure is it broke when I added my schema.
: :
?xml version="1.0" encoding="utf-8"?><IADSNOTES xmlns="notes.xsd" count="4" |
Technically, you haven't added a schema, only declared a default namespace.
As you've discovered, this can break the XPath expression if the instance
document had previously not used a namespace.
: :
Quote:
User>Joe</User><Title>GENENTITIES</Title><Text>Frame 2 Public
Note</Text></Note></IADSNOTES
I am wanting to delete "joe" in a test. |
While evidently not the problem, remember that XPath expressions
are case-sensitive. "Joe" exists in the instance document, but "joe"
does not.
: :
Quote:
strFind = string.Concat("'",myDataRow["Name"].ToString(),"'");
strTemp = string.Concat("/IADSNOTES/Note[User = ",strFind,"]"); |
Immediately before these two lines of code, you must declare an
XmlNamespaceManager and associate a prefix, for instance, "ns".
XmlNamespaceManager xmlNs = new XmlNamespaceManager(
myXmlDataDocument.NameTable);
xmlNs.AddNamespace( "ns", "notes.xsd");
Then use this prefix in the XPath expression,
strFind = string.Concat("'",myDataRow["Name"].ToString(),"'");
strTemp = string.Concat("/ns:IADSNOTES/ns:Note[ns:User = ",strFind,"]");
It's necessary to use a prefix in the XPath expression, because an
empty string cannot be used as a prefix. As long as the underlying
namespace URI matches, what prefix is chosen for the XPath
Expression doesn't matter.
Derek Harmon