Advertisement

04.15.2008 at 04:32AM PDT, ID: 23323302
[x]
Attachment Details

XmlDocument - hide empty namespace of created elements

Asked by Velio in C# Programming Language, Extensible Markup Language (XML), Visual Studio .NET 2005

Tags: Microsoft, Visual Studio, 2005, C#, XML

Hi,

Please have a look at the code snippet below, it produces the following XML:

<root xmlns="http://foobar.com">
  <foo xmlns="">
    <bar attribute="value" />
  </foo>
</root>

i don't want to show xmlns="" in the <foo> element.

Any idea how to prevent it from being "rendered"?

This is what i've tried so far (without any success):
- using null as the namespaceURI parameter
- XmlDocument.CreateNode instead of CreateElement
- calling foo.Attributes.RemoveAll();

Thanks in advance.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
XmlDocument document = new XmlDocument();
    XmlElement root = document.CreateElement("root", "http://foobar.com");
    document.AppendChild(root);
    XmlElement foo = document.CreateElement("foo");
    root.AppendChild(foo);
    XmlElement bar = document.CreateElement("bar");
    XmlAttribute attribute = document.CreateAttribute("attribute");
    attribute.Value = "value";
    bar.Attributes.Append(attribute);
    foo.AppendChild(bar);
    document.Save(filename);
[+][-]04.15.2008 at 04:49AM PDT, ID: 21357718

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: C# Programming Language, Extensible Markup Language (XML), Visual Studio .NET 2005
Tags: Microsoft, Visual Studio, 2005, C#, XML
Sign Up Now!
Solution Provided By: PlatoConsultant
Participating Experts: 1
Solution Grade: A
 
 
[+][-]04.15.2008 at 04:52AM PDT, ID: 21357732

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.15.2008 at 04:58AM PDT, ID: 21357759

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628