"ree32" <re***@hotmail.com> wrote in message news:76*************************@posting.google.co m...
"xmlns="http://tempuri.org/nameOfRoot.xsd"
I have no idea what its pointing to & what is tempuri.org?
It's not pointing to anything. Namespaces in XML are supposed
to be URI's (Universal Resource Identifiers), and URI's can be
either URN's (Universal Resource Names) or URL's (Universal
Resource Locators). You're seeing a namespace URI that is
a URL, that's why it resembles something you'd type into the
Address bar of your favorite web browser.
Despite the fact that it may look like a URL, it is not intended
to be dereferenced. It may be, and frequently is, a totally
fictitious location.
tempuri.org (temp ... uri, and not stir-fried Japanese noodles)
is just a fictitious domain name that's used when Microsoft's
tools are autogenerating a namespace URI for you (often
because the developer didn't specify one on their own).
So when this tag is in my xml tag my xpath query never works.
But when I delete it work fine.
Your XPath expressions are probably not written to use name-
space prefixes, which means the XPath expression is querying
for nodes in the empty namespace. However, when this xmlns
declaration is in your XML the nodes are in the tempuri.org
namespace URI, not in the empty namespace. That's why it
looks to XPath as if you have nothing there to query against
and it never finds anything.
Can someone please tell me what that tag is any why its
affecting my Xpath queries?
I think I've covered these, on to the unmentioned question of
what to do about it. Without the xmlns namespace declaration
in the XML, you'll encounter problems later trying to read an
XML instance document into a DataSet. Therefore, I'd advise
writing a namespace-aware XPath Expression.
Let's assume right now that you're querying for the someCol
child elements of someRow, as in this example,
XmlNodeList nodes = doc.SelectNodes( "//someRow/someCol");
In order to write a namespace-aware XPath Expression using
prefixes you must first add ( prefix, namespaceURI) pairs to
an XmlNamespaceManager. Next, you write the XPath
Expression to use the prefix to qualify each local element
name. Finally, in the call to SelectNodes( ) you must pass
the XmlNamespaceManager that knows about these prefixes
so the XPath processor can resolve them to namespace URIs.
Here is what the updated code looks like,
XmlNamespaceManager nsMan = new XmlNamespaceManager( doc.NameTable);
nsMan.AddNamespace( "tns", "http://tempuri.org/nameOfRoot.xsd");
XmlNodeList nodes = doc.SelectNodes( "//tns:someRow/tns:someCol");
If you use code similar to this for your XPath expressions then
you should be able to find nodes within the DataSet's XML w/o
removing it's xmlns namespace declaration.
Derek Harmon