HighTechTalks DotNet Forums  

Howto: Ommit empty xmlns specs?

Dotnet XML microsoft.public.dotnet.xml


Discuss Howto: Ommit empty xmlns specs? in the Dotnet XML forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Harald
 
Posts: n/a

Default Howto: Ommit empty xmlns specs? - 10-17-2007 , 12:53 PM






Hi,
I generate Xml with the XmlDocument methods. Now I have the problem, that a node has a namespace declaration but the child text nodes shall not have a namespace specification.

The XML should look as follows:

<root xmlns="anyURI">
<child 1>My Text</child 1>
...

But when generation the XLM, the nodes look like that:

<root xmlns="anyURI">
<child 1 xmlns="">My Text</child 1>

How can I suppress the xmlns="" in child 1 ???

Thanks for any help!
Regards, hd



..PS: C#, VS2005

Generation like this:

XmlElement root = _doc.CreateElement("Root", "anyURI");
root.AppendChild(_doc.CreateElement("child 1")).InnerText = "My Text";

Output is generated with an Xml-Writer and the following settings:

settings.Indent = true;
settings.IndentChars = (" ");
settings.Encoding = Encoding.GetEncoding("iso-8859-1");



Reply With Quote
  #2  
Old   
Martin Honnen
 
Posts: n/a

Default Re: Howto: Ommit empty xmlns specs? - 10-18-2007 , 08:23 AM






Harald wrote:

Quote:
root xmlns="anyURI"
child 1>My Text</child 1
..

But when generation the XLM, the nodes look like that:

root xmlns="anyURI"
child 1 xmlns="">My Text</child 1

How can I suppress the xmlns="" in child 1 ???
You need to create each element in the namespace it belongs to

Quote:
XmlElement root = _doc.CreateElement("Root", "anyURI");
root.AppendChild(_doc.CreateElement("child 1")).InnerText = "My Text";
ropt.AppendChild(_doc.CreateElement("child_1", "anyURI"))

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.