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

  • SEARCH
  • Home
  • 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 8677629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:30:34+00:00 2026-06-12T20:30:34+00:00

I know that it doesn’t look like best practice but I need to generate

  • 0

I know that it doesn’t look like best practice but I need to generate xml with same namespaces

for example:

<ns1:root xsi:schemaLocation=""http://schemalocation""
xmlns:ns1=""http://schema""
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xmlns=""http://schema"">
...
</ns1:root>

I also added namespaces to serializer:

var xmlSerializerNamespaces = new XmlSerializerNamespaces();
xmlSerializerNamespaces.Add("ns1", "http://schema");
xmlSerializerNamespaces.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
xmlSerializerNamespaces.Add(string.Empty, "http://schema");

And this is class itself:

[XmlRoot(ElementName = "request", Namespace = "http://schema")]
    [Serializable]
    public class Request 
    {
        [XmlAttributeAttribute("schemaLocation", Namespace = XmlSchema.InstanceNamespace)]
        public string SchemaLocation
        {
            get { return _schemaLocation; }
            set { _schemaLocation = value; }
        }

        ...

        private string _schemaLocation = "http://schemalocation";   }

So everything is great but default xmlns isn’t in generated xml.
I’ve also played with XmlWriterSettings with no result.
Have anybody ideas how to do it without string replacement?)

  • 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-12T20:30:37+00:00Added an answer on June 12, 2026 at 8:30 pm

    The default namespace is set based on which namespace you use to add the XML fragment e.g.

    XNamespace defaultNs = @"http://schema";
    var result = new XDocument(new XElement(defaultNs + "root"));
    

    Would produce the following output:

    <rootNode xmlns="http://schema">
    </rootNode>
    

    So all you have to do is add your other named ones to the document i.e.

    XNamespace defaultNs = @"http://schema";
    var root = new XElement(defaultNs + "root",
        new XAttribute("xsi", "schemaLocation", "http://schemaLocation"),
        new XAttribute(XNamespace.Xmlns + "ns1", defaultNs"),
        new XAttribute(XNamespace.Xmlns + "xsi", "http://www.w3.org/2001/XMLSchema-instance")
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yes, I know that the FAQ pretends to answer this, but it doesn't really.
I know that my problem is the trivial one, but I need some help.
I know that it does consider ' ' as NULL , but that doesn't
I know that javascript doesn't have pointers in terms of a variable referring to
I know that OpenCL doesn't have support for complex numbers, and by what I've
I know that the title doesn't really say what I'm actually looking for, as
So we know that the standard doesn't force pointer sizes to be equal. (
When I type ctags -e it returns an error saying it doesn't know that
I think I read that the delete trigger doesn't know what data was deleted
I want to know that does apple's Push Notification Server generate new device token

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.