Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6134423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:21:13+00:00 2026-05-23T17:21:13+00:00

New here, looking to get a little help with my XmlDocument. Is it possible

  • 0

New here, looking to get a little help with my XmlDocument. Is it possible to have string data in my root element AND remove the xmlns= attribute from being shown? I’m looking for something like this:

<Rulebase author=yadda datetime=bingbang version=1.x </Rulebase>

When I try to use my string data by doing:

xmlDom.AppendChild(xmlDom.CreateElement("", "Rulebase", data));
XmlElement xmlRoot = xmlDom.DocumentElement;

It ends up looking like this:

<Rulebase xmlns="version=0 author=username date=7/13/2011 </Rulebase>

and it also appends xmlns=”” to all my other nodes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:21:14+00:00Added an answer on May 23, 2026 at 5:21 pm

    The CreateElement overload you’re using takes a prefix as it’s first argument, local name as second, and namespace as third. If you don’t want a namespace, don’t use this overload. Just use the one that takes a local name as the one and only argument. Then add your data separately as child elements and attributes.

    var xmlDom = new XmlDocument();
    XmlElement root = xmlDom.CreateElement("Rulebase");
    xmlDom.AppendChild(root);
    XmlElement data = xmlDom.CreateElement("Data");
    root.AppendChild(data);
    
    XmlAttribute attribute = xmlDom.CreateAttribute("author");
    attribute.Value = "username";
    data.Attributes.Append(attribute);
    
    attribute = xmlDom.CreateAttribute("date");
    attribute.Value = XmlConvert.ToString(DateTime.Now, XmlDateTimeSerializationMode.RoundtripKind);
    data.Attributes.Append(attribute);
    
    Console.WriteLine(xmlDom.OuterXml);
    

    Creates (formatting added)

    <Rulebase>
        <Data author="username" date="2011-07-13T22:44:27.5488853-04:00" />
    </Rulebase>
    

    Using XmlDocument to generate XML is pretty tedious though. There are many better ways in .NET, like XmlSerializer and DataContractSerializer. You can also use Linq-to-Xml and XElement. Or you can use an XmlWriter.Create(). Lots of options.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

New to jQuery/javascript here and looking for a little help. I am writing a
I'm new here and I hope anyonte can help me. I have WCF Service
I'm new around here and i have a little problems with a C# application.
am new here. i have a slight problem; PLease look at the following code
I'm new here to stackoverflow, so bear with me. I have a book that
I am new to PyTables, and am looking at using it to process data
I am new here so first of all my greetings to you I am
I am new here. I would like to know how can I display HTML
I'm starting a new project here (Windows Forms). What's the best option today for
fairly new iPhone developer here. Building an app to send RS232 commands to a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.