Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get the xmlns value from XML file? (XML namespace)

Status
Not open for further replies.

huckfinn19

Programmer
May 16, 2003
90
CA
Hi! I am just trying to get the XML namespace value out of my XML file, but can't seem to get it to work! Anyone can help me?

Here's a sample XML file:

<?xml version="1.0" encoding="utf-8" ?>
<pages xmlns="the_namespace_value_i_want">
<value>5</value>
</pages>

I want to get the value of the xmlns. I tried the following code, but I get values I am not interested in:

Code:
XmlTextReader tr = new XmlTextReader(@"simple.xml");
XmlNamespaceManager nsm = new XmlNamespaceManager(tr.NameTable);
do{
    foreach (String prefix in nsm) {
	Console.WriteLine("Prefix={0}, Namespace={1}", prefix,nsm.LookupNamespace(prefix));
	} 
}
while (nsm.PopScope());

I get:
-----------
Prefix=xml, Namespace=Prefix=xmlns, Namespace=Prefix=, Namespace=
-----------

Anyone can help me?

Thanks!

Huck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top