ignore/remove Namespace URI

I have a xml file with NameSpace on the root node let say xmlns="http://www.mysite.com/"
i.e.
<?xml version="1.0" ?>
<customers xmlns="http://www.mysite.com/">
<customer job > ....

I am loading this into xmldocument
whaty I want's is to ignore or remove NameSpaceURI from the Xmldocument
It is making some problem in the parsing of the docuement
What Can I do

I am working on .netframework 1.1

[476 byte] By [Kamii47] at [2007-12-27]
# 1

It does not make much sense usually to try to remove/strip namespaces from an XML document. And the "problem in parsing" a document with namespaces can usually easily be solved as they are usually caused by a lack of understanding of how XPath works or how the DOM works to find or create elements/attributes in a namespace.

So what problems do you have? Let's try to address those problems by properly using the XPath or DOM APIs, not by trying to remove namespaces.

MartinHonnen at 2007-9-3 > top of Msdn Tech,.NET Development,XML and the .NET Framework...
# 2

Let Say following is my XML

<?xml version="1.0" ?>
<customers xmlns="http://www.mysite.com/">

<customer>
<customerid >12345</customerid>

<description>dfhsdfkhsdfkjsdkjfsdkjf</description>

<location>
<region-id>usa.fl.Pensacola/Panama City</region-id>
<city>Pensacola - 32504-0000</city>
<state>FL</state>
<country>USA</country>
</location>

</customer>

<customer>

<customerid >7891</customerid>

<description>dfhsdfkhsdfkjsdkjfsdkjf</description>

<location>
<region-id>Pacific</region-id>
<city>Newyork</city>
<state>NY</state>
<country>USA</country>
</location>

</customer>

</customers>

how get I read the the description ,city and stateof the customer with particular id let say 12345

Kamii47 at 2007-9-3 > top of Msdn Tech,.NET Development,XML and the .NET Framework...
# 3

static void test3()

{

XmlDocument d = new XmlDocument();

d.Load("XmlFile2.xml");

XmlNamespaceManager xnsm = new XmlNamespaceManager(d.NameTable);

xnsm.AddNamespace("c", "http://www.mysite.com/");

string description = d.SelectSingleNode("//c:customers/c:customer[c:customerid='12345']/c:description",xnsm).InnerText;

string city = d.SelectSingleNode("//c:customers/c:customer[c:customerid='12345']/c:location/c:city", xnsm).InnerText;

string state = d.SelectSingleNode("//c:customers/c:customer[c:customerid='12345']/c:location/c:state", xnsm).InnerText;

Debug.WriteLine(description);

Debug.WriteLine(city);

Debug.WriteLine(state);

}

SinanUssakli-MSFT at 2007-9-3 > top of Msdn Tech,.NET Development,XML and the .NET Framework...
# 4

For the example given, the namespace just gets in the way - adding the namespace manager, passing it to all the queries, and worst of all, having to stick it in front of every single component in the XPath query. I know the XML purists will bristle at this, but it's easier to just ignore it. Just change how the document is loaded:

XmlDocument d = new XmlDocument();
using (XmlTextReader tr = new XmlTextReader(path))
{
tr.Namespaces = false;
d.Load(tr);
}

This loads your XML document as if it had no namespace.

/Frank

FrankRacis at 2007-9-3 > top of Msdn Tech,.NET Development,XML and the .NET Framework...
# 5

Seem to be Super Solution.

I will definitely have a go on it in the morning

Thanks Franks

Kamii47 at 2007-9-3 > top of Msdn Tech,.NET Development,XML and the .NET Framework...

.NET Development

Site Classified