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 7743683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:35:51+00:00 2026-06-01T09:35:51+00:00

I need to generate XML in the following form: <ns1:root xmlns:ns1=http://example.com/xmlns1 xmlns:ns2=http://example.com/xmlns2> <ns2:item ns2:param=value

  • 0

I need to generate XML in the following form:

<ns1:root xmlns:ns1="http://example.com/xmlns1" xmlns:ns2="http://example.com/xmlns2">
    <ns2:item ns2:param="value" />
</ns1:root>

I use this code:

XmlDocument xDoc = new XmlDocument();
XmlElement xRootElement = (XmlElement)xDoc.AppendChild(xDoc.CreateElement("ns1:root"));
xRootElement.SetAttribute("xmlns:ns1", "http://example.com/xmlns1");
xRootElement.SetAttribute("xmlns:ns2", "http://example.com/xmlns2");
XmlElement xElement = (XmlElement)xRootElement.AppendChild(xDoc.CreateElement("ns2:item"));
xElement.SetAttribute("ns2:param", "value");

But the result is the following:

<root xmlns:ns1="http://example.com/xmlns1" xmlns:ns2="http://example.com/xmlns2">
    <item param="value" />
</root>

Thanks for the advice.

  • 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-06-01T09:35:52+00:00Added an answer on June 1, 2026 at 9:35 am

    XmlElement xElement = (XmlElement)xRootElement.AppendChild(xDoc.CreateElement(“ns2:item”, “http://example.com/xmlns2”));

    Gave me:

    <root xmlns:ns1="http://example.com/xmlns1" xmlns:ns2="http://example.com/xmlns2">
      <ns2:item param="value" />
    </root>
    

    By the way, "ns2:param" is not necessary. XML attributes belong to the same namespace as the element.

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

Sidebar

Related Questions

I need so generate XML like the following: <?xml version=1.0 encoding=UTF-8 standalone=yes?> <urlset xmlns=http://www.sitemaps.org/schemas/sitemap/0.9
I have the following xml I need to read the values of: <po-response xmlns=http://test.com<
I need to generate the following XML: <Learner xmlns=some.domain.api> <ActivationDate>1999-05-31T11:20:00</ActivationDate> <EmailAddress>String content</EmailAddress> <ExpirationDate>1999-05-31T11:20:00</ExpirationDate> <FederalId>String
I need to generate the following XML with SOAP: ... <InternationalShippingServiceOption> <ShippingService>StandardInternational</ShippingService> <ShippingServiceCost currencyID=USD>39.99</ShippingServiceCost>
I need to generate a node in a XML file with the following structure:
What tool do I need to generate XML intellisense help file as shown below?
I'm working in a .net application where we need to generate XML files on
I need to generate an XML file in C#. I want to write the
Flex has an issue with hyphens in xml. I need to generate an xml
I need to generate an editable xml file to supply content to a flash

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.