M
Martin
Hi,
I am using xmldocument.selectsinglenode to query an xml document.
This works perfectly when the document to be queried has no namespace,
however as some as i put a namespace in then null is returned from
selectsinglenode.
I think I am not creating the namespace manager correctly.
I have created a very small sample piece of code (see below) that
demonstates the problem.
If anybody could point out my mistake based on the code below then I would
be extremly greatful.
many thanks in advance.
cheers
martin.
//paste the code below into the main function of a console app.
XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(@"<?xml version=""1.0""?><Addresses
xmlns:xsd=""http://www.w3.org/2001/XMLSchema""
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xmlns=""http://mydomain.com/TimeSeriesSchema.xsd""><Address>38 some
road</Address></Addresses>");
//comment the line above and uncomment the line below and everything
works fine.
//xmldoc.LoadXml(@"<?xml version=""1.0""?><Addresses><Address>38 some
road</Address></Addresses>");
XmlNamespaceManager namespaceManager = new
XmlNamespaceManager(xmldoc.NameTable);
namespaceManager.AddNamespace("","http://www.w3.org/2001/XMLSchema");
Console.WriteLine(xmldoc.SelectSingleNode("Addresses/Address").OuterXml.ToSt
ring() , namespaceManager);
//xmldoc.Save(Console.Out);
return;
I am using xmldocument.selectsinglenode to query an xml document.
This works perfectly when the document to be queried has no namespace,
however as some as i put a namespace in then null is returned from
selectsinglenode.
I think I am not creating the namespace manager correctly.
I have created a very small sample piece of code (see below) that
demonstates the problem.
If anybody could point out my mistake based on the code below then I would
be extremly greatful.
many thanks in advance.
cheers
martin.
//paste the code below into the main function of a console app.
XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(@"<?xml version=""1.0""?><Addresses
xmlns:xsd=""http://www.w3.org/2001/XMLSchema""
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xmlns=""http://mydomain.com/TimeSeriesSchema.xsd""><Address>38 some
road</Address></Addresses>");
//comment the line above and uncomment the line below and everything
works fine.
//xmldoc.LoadXml(@"<?xml version=""1.0""?><Addresses><Address>38 some
road</Address></Addresses>");
XmlNamespaceManager namespaceManager = new
XmlNamespaceManager(xmldoc.NameTable);
namespaceManager.AddNamespace("","http://www.w3.org/2001/XMLSchema");
Console.WriteLine(xmldoc.SelectSingleNode("Addresses/Address").OuterXml.ToSt
ring() , namespaceManager);
//xmldoc.Save(Console.Out);
return;