Thanks, I was looking for a workaround as well as I could not get mine =
to work. However despite the fact that what you have come up with below =
works, in my opinion this is a blatant bug.
To be specific if you have a DefaultNamespace you have to fudge an XPath =
search to make it work:
If your XML "xmlfile1.xml" has:
<?xml version=3D"1.0" encoding=3D"utf-8" ?><myObject =
xmlns=3D"
http://tempuri.org/MyObject.xsd"><Object1> ...etc
which has a default namespace, instead of one with a named namespace =3D =
"anamespace":
<?xml version=3D"1.0" encoding=3D"utf-8" ?><myObject =
xmlns:anamespace=3D"
http://tempuri.org/MyObject.xsd"><Object1> ...etc
then the following code will not work!!!!
Dim xdd As XmlDocument =3D New XmlDocument
xdd.Load("..\xmlfile1.xml")
Dim nod As XmlNode
Dim nsmgr As XmlNamespaceManager =3D New =
XmlNamespaceManager(xdd.NameTable)
nsmgr.AddNamespace(String.Empty, "
http://tempuri.org/MyObject.xsd") ' =
Add a default namespace
nod =3D xdd.SelectSingleNode("//Object1", nsmgr)
The node is not found despite the fact that the documentation for .NET =
says that it will.
Fudging the last two lines works:
nsmgr.AddNamespace("fakenamespace", "
http://tempuri.org/MyObject.xsd") =
' Add a default namespace
nod =3D xdd.SelectSingleNode("//fakenamespace:Object1", nsmgr)
This bug is probably very closely related to 324996=20
BUG: XmlNamespaceManager Does Not Correctly Atomize Strings During =
Namespace Lookups
However it isn't quite the same bug and if they fix 324996 they may not =
fix this one. If anyone that has MSDN Universal or some other means of =
logging a bug with Microsoft wants to be the first to log a new one, go =
ahead. I neither know how, nor have any premium support from Microsoft.=20
Note that one of the reasons this may not be a trivial bug is that =
Visual Studio itself uses default namespaces. An XSD file that is used =
for a dataset leads to an XML data file with a default namespace. So =
XPath's searches don't work on XMLDataDocuments.
Wray Smallwood
[quoted text, click to view] "Andreas H=E5kansson" <andreas@selfinflicted.org> wrote in message =
news:uk1ImGeiDHA.2984@TK2MSFTNGP11.phx.gbl...
Nevermind.. figured it out..=20
Create a fake namespace alias in the XmlNamespaceManager and prefix you =
node in the
XPath with it..
XmlNamespaceManager manager =3D new XmlNamespaceManager();
manager.AddNamespace("test", "
http://www.w3.org/2000/09/xmldsig#");
XmlNode n =3D doc.SelectSingleNode("//test:Signature");
=3D)
--=20
ANDREAS H=C5KANSSON
STUDENT OF SOFTWARE ENGINEERING
andreas (at) selfinflicted.org
[quoted text, click to view] "Andreas H=E5kansson" <andreas@selfinflicted.org> wrote in message =
news:OKUHludiDHA.1368@TK2MSFTNGP12.phx.gbl...
I have a price of XML that looks like this
<Root>
<SomeNode>
.....
</SomeNode>
<Signature xmlns=3D"
http://www.w3.org/2000/09/xmldsig#"> ...
</Signature>
</Root>
If I load this into an XmlDocument object and try calling
SelectSingleNode("//Signature") to
determine if the signature has been added or not, then it alwasy return
null. I have managed
to get it that I probably need a XmlNamespaceManager object and pass it =
to
the method
as well, however I do not know how to set this up since the new =
namespace
declared in
the <Signature> node doesn't use a prefix and I can not alter the XML to
setup a prefix
either since the <Signature> section is generated by some other code and
need to comply
with a W3C schema =3D)
Any suggestions on how to be able to tell if the <Signature> node it =
present
or not, using
XPath and a XmlNamespaceManager object ? =3D)
--=20
ANDREAS H=C5KANSSON
STUDENT OF SOFTWARE ENGINEERING