473,231 Members | 1,675 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

XML Elements have the same attributes

Hello,

I am creating an XML Document using XmlDocument.
I can create my top node no problem

However when I add child nodes they seem to inherit the xmlns=""
attribute (see xml below).
How can I stop this?

-------------------------
Code snippet
-------------------------

n = xmlDoc.CreateElement("nl", "MyXML", "http://www.myurl.com");
XmlAttribute nns = xmlDoc.CreateAttribute( "xmlns" );
nns.InnerText = @"www.myurl.com/xml";n.Attributes.SetNamedItem( nns );
xmlDoc.AppendChild(n);

XmlNode TemplateNode;
TemplateNode = xmlDoc.CreateElement("Template");
n.AppendChild(TemplateNode);

---------------------
Resulting XML
---------------------

<?xml version="1.0" encoding="UTF-8"?>
<nl:MyXML xmlns="http://www.myurl.com/xml"
xmlns:vl="http://www.myurl.com">
<Template xmlns="">

</Template>
</vl:VNETList>

Feb 1 '06 #1
1 1360


ll**********@yahoo.com wrote:

n = xmlDoc.CreateElement("nl", "MyXML", "http://www.myurl.com");
That is fine if you want to have that element in a certain namespace.
XmlAttribute nns = xmlDoc.CreateAttribute( "xmlns" );
nns.InnerText = @"www.myurl.com/xml";n.Attributes.SetNamedItem( nns );
That does not help, consider removing that.
xmlDoc.AppendChild(n);

XmlNode TemplateNode;
TemplateNode = xmlDoc.CreateElement("Template");


If you want that Template element to be in the namespace with the URI
then use the proper overload of CreateElement e.g.
TemplateNode = xmlDoc.CreateElement(
"",
"Template",
"www.myurl.com/xml"
)
You have to do that for each element to be created in a certain
namespace. Later when the DOM document is being serialized the
serializer will take care of adding namespace declaration attributes.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Feb 1 '06 #2

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

Similar topics

3
by: Stephan Brunner | last post by:
Hi I have created two flavors of an XSLT stylesheet to transform all attributes of an XML document to elements: They both work as expected with MSXML and XMLSPY but throw an exception ...
2
by: Novice | last post by:
Hi all, I have to decide on an XML structure going forward. The structure is going to house a large amount of data. In the past I've always just used the philosophy of "when in doubt use...
7
by: grwalker | last post by:
I have some classes that have the <Serializable()> attribute applied, which of course by default serializes the class properties as elements. What I would like to do is to be able to override this...
0
by: jts2077 | last post by:
I am trying to create a large nested XML object using E4X methods. The problem is the, the XML I am trying to create can only have xmlns set at the top 2 element levels. Such as: <store ...
2
by: Ken Fine | last post by:
In code, I'm adding javascript attributes to form elements on an ASP.NET page: body.Attributes.Add("onClick", "highlight(event);"); body.Attributes.Add("onKeyUp", "highlight(event);");...
6
by: Jakub.Bednarczuk | last post by:
Hallo everybody I have the problem with getting attributes values and also attributes names. I am reading an xml file with DOM. Lets see an example: file I read <root> <Def></Def>...
10
by: Andy Fish | last post by:
Hi, I would like to include extra "hidden" information in a generated HTML page that can be used by javascript functions. I realise that most browsers seem to ignore any tags and attributes...
7
by: mavigozler | last post by:
IE7 does not appear to set an event on contained text inside SPAN elements whose 'onclick', 'onmouseover', and 'onmouseout' events, defying the HTML recommendation. Firefox appears to conform. ...
0
by: David Lozzi | last post by:
Howdy, I just had a small explosion in my brain, and now i'm a little more confused than I was before. I'm fairly new to XML, but understand it for the most part in regards to formatting. I have...
2
by: doozer1979 | last post by:
Hello, I'm having a bit of difficulty transforming xml elements into attributes. I want to loop through all of the <person> elements in the document and turn all of its child elements into...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.