473,549 Members | 2,719 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to remove xmlns attribute from XML document (.net)

I am relatively new to XML and C#. So, forgive me if this question is
too newbie. :-)

While assuming this is an easy programming task, I couldn't find a
single reference anywhere for how to do it. Here is the situation:

I am given an XML file like the one below from other group in my
company to load the data into our database.

<root xmlns="the-namespace">
....
data here...
....
</root>

I was able to load the file into an XmlDocument object and then into db
tables only when I removed 'xmlns="the-namespace'. However, if I
didn't remove it, The dataset in the XmlDocument was empty and there
was no exception thrown. I'd like to find a way of programmaticall y
removing the xmlns attribute. BTW, the namespace in the file was not
referenced anywhere in the XML document.

Thanks in advance.

Frank

May 6 '06 #1
6 24466
<fz****@calamos .com> wrote in message
news:11******** **************@ y43g2000cwc.goo glegroups.com.. .
I am relatively new to XML and C#. So, forgive me if this question is
too newbie. :-)

While assuming this is an easy programming task, I couldn't find a
single reference anywhere for how to do it. Here is the situation:

I am given an XML file like the one below from other group in my
company to load the data into our database.

<root xmlns="the-namespace">
...
data here...
...
</root>

I was able to load the file into an XmlDocument object and then into db
tables only when I removed 'xmlns="the-namespace'. However, if I
didn't remove it, The dataset in the XmlDocument was empty and there
was no exception thrown. I'd like to find a way of programmaticall y
removing the xmlns attribute. BTW, the namespace in the file was not
referenced anywhere in the XML document.

Thanks in advance.

Frank


Namespaces in XML are used in exactly the same way as namespaces in C#, to
disambiguate things.

Imagine you had an XML document descibing river navigation you much have an
element called "channel". If you have a document about TV programs you might
have an element called "channel". The problem comes when you have a document
about a TV program about river navigation - how do you tell the two channel
elements apart? XML namespaces.

There are two syntaxes for XML namespaces: one explicitly sets elements into
the namespace

<x:program xmlns:x="uri-TV">
<x:channel />
</x:program>

the other does it implicitly

<program xmlns="uri-TV>
<channel />
</program>

in the second example the program and channel elements are in the namespace
because the namespace is said to be the default for program element and all
its children.

Now to your question: what makes you think that the XML document you hahve
received hasn't been loaded into your XmlDocument instance?

Also you are using the terms DataSet and XmlDocument seemingly
interchangeably - where does the DataSet some from?

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
May 6 '06 #2
Thanks for your reply. I understand what 'namespace' is. However, in
our particular case, the data files (in XML) are generated by someone
else. That particular namespace may mean something to them but nothing
to us. As I mentioned in my previous post, if I manually removed
'xmlns="the-namespace"' from the XML data file, my program could parse
and load the data to the XmlDataDocument object without any problem.
However, if I didn't, the dataset in the XmlDataDocument object was
empty.

Here is my code (We have a schema and a data files ready for data
loading)
........
m_xDataDoc = new XmlDataDocument ();
Debug.Assert(m_ xDataDoc != null);
m_xDataDoc.Data Set.ReadXmlSche ma(m_SchemaFile );

Debug.Assert(m_ DataFile != null);
m_xDataDoc.Load (m_DataFile);
........

If I don't remove the namespace, m_xDataDoc.Data Set is empty. If I
manually remove the namespace, m_xDataDoc.Data Set properly contains
data from the XML file.

I just would like to know if we can programmaticall y remove the
namespace to make the data (XML) file loadable.

Frank

May 8 '06 #3

<fz****@calamos .com> wrote in message
news:11******** **************@ u72g2000cwu.goo glegroups.com.. .
Thanks for your reply. I understand what 'namespace' is. However, in
our particular case, the data files (in XML) are generated by someone
else. That particular namespace may mean something to them but nothing
to us. As I mentioned in my previous post, if I manually removed
'xmlns="the-namespace"' from the XML data file, my program could parse
and load the data to the XmlDataDocument object without any problem.
However, if I didn't, the dataset in the XmlDataDocument object was
empty.

Here is my code (We have a schema and a data files ready for data
loading)
........
m_xDataDoc = new XmlDataDocument ();
Debug.Assert(m_ xDataDoc != null);
m_xDataDoc.Data Set.ReadXmlSche ma(m_SchemaFile );

Debug.Assert(m_ DataFile != null);
m_xDataDoc.Load (m_DataFile);
........

If I don't remove the namespace, m_xDataDoc.Data Set is empty. If I
manually remove the namespace, m_xDataDoc.Data Set properly contains
data from the XML file.

I just would like to know if we can programmaticall y remove the
namespace to make the data (XML) file loadable.

Frank


What's your schema file?
The namespace in the schema should match the document.
You can probably make it work by setting the namespace in the schema.
May 8 '06 #4
What's weird is that the particular namespace is not in the schema
file. It's a separate issue why this namespace even gets in the data
file but I won't go there. :-(

Anyway, since this namespace is useless to us and I can get the file
loaded properly after I manually removed it, I am not interested in
this particular namespace at all. All I need is a programmatic way of
removing it.

Thanks.

Frank

May 8 '06 #5

<fz****@calamos .com> wrote in message
news:11******** **************@ i40g2000cwc.goo glegroups.com.. .
What's weird is that the particular namespace is not in the schema
file. It's a separate issue why this namespace even gets in the data
file but I won't go there. :-(
But that's your problem:

Your schema describes elements in an unnamed namespace whereas your data is
declared to be in a named namespace hence the schema cannot possibly match
the document.

Add a namespace to the schema to match elements and your problem will go
away. Your proposed solution of hacking the document is precisely that - a
hack.

Anyway, since this namespace is useless to us and I can get the file
loaded properly after I manually removed it, I am not interested in
this particular namespace at all. All I need is a programmatic way of
removing it.


It's not useless because it defines the namespace.
What you are saying is the equivalent of a C# attempt to instantiate a class
called ArrayList - There is no such thing. There is only
System.Collecti ons.ArrayList. You can get away with calling it ArrayList but
only because you say "using System.Collecti ons;" which is the C# equivalent
of the xmlns in your document.

[Actually you are doing the opposite - Your schema is the equivalent of
declaring a class called ArrayList outside any namespace - You then try to
instantiate a System.Collecti ons.ArrayList]

namespaces in XML are not just decoration - they are fundamental.
May 8 '06 #6
Ok, could you show me how to programmaticall y add the namespace to the
schema? While I understand the namespace concept and theory, I have to
find a solution of the existing situation -- a schema file that does
not contain the particular namespace.

I tried the following before but it did not work.

XmlNamespaceMan ager nsm = new
XmlNamespaceMan ager(m_xDataDoc .NameTable);
nsm.AddNamespac e("xmlns", "the-namespace");
Frank

May 8 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5662
by: Hyunchan Kim | last post by:
To indent xml file, I made an instance of Transformer from Templates using following. <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xslt" version="1.0"> <xsl:output method="xml" indent="yes" xalan:indent-amount="4"/> <xsl:template match="/">
4
3582
by: David S. Alexander | last post by:
I am trying to transform XML to XML using an XSLT in C#, but the root node of my XML is not being matched by the XSLT if it has an xmlns attribute. Am I handling my namespaces incorrectly? My C# code is, // Create an XSLT transform object XslTransform xslTransform = new XslTransform(); // Load the stylesheet
0
2009
by: Ewan Fairweather | last post by:
Hi, I'm generating the below XML in c# for an asp.net application When i've generated this XML the <LaboratoryDetails xmlns=""> element has a blank xmlns set. How do i either a) remove this attribute or b) prevent it from happening in the first place. To generate the xml I've got two template files which i've included at the bottom...
1
2985
by: Ewan Fairweather | last post by:
Hi, I'm generating the below XML in c# for an asp.net application When i've generated this XML the <LaboratoryDetails xmlns=""> element has a blank xmlns set. How do i either a) remove this attribute or b) prevent it from happening in the first place. To generate the xml I've got two template files which i've included at the bottom...
6
693
by: fzhang | last post by:
I am relatively new to XML and C#. So, forgive me if this question is too newbie. :-) While assuming this is an easy programming task, I couldn't find a single reference anywhere for how to do it. Here is the situation: I am given an XML file like the one below from other group in my company to load the data into our database.
3
3895
by: =?Utf-8?B?R3JlZw==?= | last post by:
If I have an XmlDocument with a deep hierarchy of nodes, with a documentElement having an attribute xmlns="http://someurl.com" and all children inheriting that namespace (but not having the xmlns attribute explicitly declared), then why is it that when I perform appendChild(someNode) on an existing node deep in the hierarchy, where someNode...
1
3825
by: C.W.Holeman II | last post by:
I have an xmlns attribute that produces an XHTML validation error and I do not understand why it is considered an error.The file displays as expected on Firefox and IE7. http://emle.sourceforge.net/emle020100/lab/ng20070625_emle_lab_001-e.xml.html <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus...
2
20425
by: =?ISO-8859-1?Q?Norbert_P=FCrringer?= | last post by:
Hello, I use Xml serialization to serialize an object into an xml file. My root tag is defined as following:
0
1756
by: rajat teotia | last post by:
Hi, i have created a simple web service using Php Nusoap. its working correctly but the only thing missing is to add the default xmlns attribute to the response tag. Here is the copy of Response : <?xml version="1.0" encoding="ISO-8859-1"?> <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"...
0
7957
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7809
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3500
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3481
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1941
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1059
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.