473,586 Members | 2,681 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xmlElement and namespace

I'm using the following code to create what will be the root element of my
XML document.

XmlDocument controlDocument = new XmlDocument();
//add root node
XmlElement rootNode = controlDocument .CreateElement( "ns0:MyRootElem ent" );
rootNode.SetAtt ribute( "xmlns:ns0" , "http://my.namespace.ur i" );
controlDocument .AppendChild(ro otNode);

I'm trying to get it so that it comes out as follows:

<ns0:MyRootElem ent xmlns:ns0="http ://my.namespace.ur i">
</ns0:MyRootEleme nt>

however, when I'm print out the XML document, it's only printing out as
such:

<MyRootElemen t xmlns:ns0="http ://my.namespace.ur i">
</MyRootElement>

Why is it getting rid of the beginning 'ns0:'? And what can I do to keep it
in there?

thnx,
Christoph
Nov 17 '05 #1
2 7241
try to change you code to the following:

XmlDocument controlDocument = new XmlDocument();

//add root node, ADD THE NAMESPACE IN THE CREATE ELEMENT method

XmlElement rootNode = controlDocument .CreateElement( "ns0:MyRootElem ent",
"http://my.namespace.ur i" );

//don't do this
//rootNode.SetAtt ribute( "xmlns:ns0" , "http://my.namespace.ur i" );

controlDocument .AppendChild(ro otNode);
Hope that helps
Mark.
"Christoph" wrote:
I'm using the following code to create what will be the root element of my
XML document.

XmlDocument controlDocument = new XmlDocument();
//add root node
XmlElement rootNode = controlDocument .CreateElement( "ns0:MyRootElem ent" );
rootNode.SetAtt ribute( "xmlns:ns0" , "http://my.namespace.ur i" );
controlDocument .AppendChild(ro otNode);

I'm trying to get it so that it comes out as follows:

<ns0:MyRootElem ent xmlns:ns0="http ://my.namespace.ur i">
</ns0:MyRootEleme nt>

however, when I'm print out the XML document, it's only printing out as
such:

<MyRootElemen t xmlns:ns0="http ://my.namespace.ur i">
</MyRootElement>

Why is it getting rid of the beginning 'ns0:'? And what can I do to keep it
in there?

thnx,
Christoph

Nov 17 '05 #2
> try to change you code to the following:
XmlDocument controlDocument = new XmlDocument();
//add root node, ADD THE NAMESPACE IN THE CREATE ELEMENT method
XmlElement rootNode = controlDocument .CreateElement( "ns0:MyRootElem ent",
"http://my.namespace.ur i" );
//don't do this
//rootNode.SetAtt ribute( "xmlns:ns0" , "http://my.namespace.ur i" );
controlDocument .AppendChild(ro otNode);
Hope that helps


That was an incredible help!
Thank you so very much! :) It is very much appreciated.

thnx,
Christoph
Nov 17 '05 #3

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

Similar topics

6
1913
by: Timothy V | last post by:
Hi, I have and XmlElement from within an XmlDocument. I wish to RemoveAll() from within the XmlElement plus itself. For example: <Notes> <Note id="n1"> <Info>A message</Info> </Note> <Note id="n2"> <Info>another message</Info>
1
3528
by: nibble | last post by:
I'm doign the following: XmlElement myElem....; string name = "xmlns:"+"abc"; string value = "http://www.abc.com"; myElem.SetAttribute(name, value); I get an exception saying that name cannot have ':' in it. However, MSDN usage doc for this method explicitly says that ':' will be parsed and the prefix would be retrieved.
2
4111
by: Anirudh | last post by:
Hi, i wanted to know if there is any way to convert an object to XMlText to XMLElement. Thanks in advance.
1
4738
by: andrej | last post by:
hi, ich habe eine anwendung, welche ein xml document erstellt. um festzustellen, ob ein element bereits vorhanden ist, verwende ich die funktion selectsinglenode( ....) diese funktion liefert mir ein element des typs node.
3
10427
by: phil | last post by:
I have written a little application that can grab part of a page from a web site. I then want to take this result and be able to serialize it so that it can be stored as XML. I am storing these "ResultNodes" as System.Xml.XmlElements but when I try and serialize (serialise) my result object I get the following exception: ...
1
1469
by: funkymp | last post by:
im trying to create a user interface that allows a user to upload there own mixes which are then added to a itunes podcast. basically, my problem is. when it updates the podcast.xml file, i need it to display author/subtitle etc as itunes:author/itunes:subtitle so on XmlElement newElem = doc.CreateElement("item"); ...
2
9031
by: nygiantswin2005 | last post by:
Hi I have wrote a method in my C# class with the following code, to create an XMl file. The root element is suppose to have 3 attibutes. I can not get attributes to appear correctly. XmlDocument document = new XmlDocument();
2
2663
by: Tony Johansson | last post by:
Hello! I know the get property for the XmlElement.InnerXml but how does the set property work. I mean if you have several child elements and you use the set how will this affect all the child elements ? //Tony
0
1719
by: kiraente | last post by:
Hi all, If anyone can give some ideas on this issue i've been trying to figure out. here's the generic codes public class ABC private id as long public lastname as string
0
7912
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8338
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...
1
7959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5710
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
5390
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
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
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
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.