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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:59:14+00:00 2026-05-26T08:59:14+00:00

I am trying to create an XML document with multiple namespaces using System.Xml.Xmlwriter in

  • 0

I am trying to create an XML document with multiple namespaces using System.Xml.Xmlwriter in C# and am recieving the following error on compile:

The prefix ” cannot be redefined from ” to ‘http://www.acme.com/BOF’ within the same start element tag.

The entirety of my code is below:

        XmlWriterSettings settings = new XmlWriterSettings { Encoding = Encoding.UTF8, Indent = true };

        XmlWriter writer = XmlWriter.Create("C:\\ACME\\xml.xml", settings);

        writer.WriteStartDocument();

        writer.WriteStartElement("BOF");
        writer.WriteAttributeString("xmlns", null, null, "http://www.acme.com/BOF");  //This is where I get my error
        writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
        writer.WriteAttributeString("fileName", null, null, "test.xml");
        writer.WriteAttributeString("date", null, null, "2011-10-25");
        writer.WriteAttributeString("origin", null, null, "MYORIGIN");
        writer.WriteAttributeString("ref", null, null, "XX_88888");
        writer.WriteEndElement();

        writer.WriteStartElement("CustomerNo");
        writer.WriteString("12345");
        writer.WriteEndElement();

        writer.WriteEndDocument();

        writer.Flush();
        writer.Close();

What am I doing wrong?

Thanks

John

  • 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-26T08:59:15+00:00Added an answer on May 26, 2026 at 8:59 am
    writer.WriteStartElement("BOF"); // write element name BOF, no prefix, namespace ""
    writer.WriteAttributeString("xmlns", null, null, "http://www.acme.com/BOF");  //Set namespace for no prefix to "http://www.acme.com/BOF".
    

    The second line makes no sense, because you’re assigning the default (no-prefix) namespace to something other than what it is, in the same place as it is that.

    Replace those two lines with writer.WriteStartElement("BOF", "http://www.acme.com/BOF")

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

Sidebar

Related Questions

I am trying to create the following XML document- FileStream fs = new FileStream(path,
I am trying to load a xml document I created using PHP and DOM
I'm trying to create an xml entry that looks like this using python and
I'm trying to create an XML sitemap using CakePHP, from a table which has
I'm trying to create a xls from a xml document (Its actually a xml
I am trying to select specific values from a xml document using XPath. The
I am trying to select specific values from a xml document using XPath. The
I'm trying to create an xml document in python, however some of the strings
I am new to java and I am trying to create an XML document
I'm trying to generate an XML document using a class generated by the xsd.exe

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.