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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:47:37+00:00 2026-05-11T12:47:37+00:00

So I am still asking questions about this topic :-( So I create an

  • 0

So I am still asking questions about this topic 🙁

So I create an object, decorate it with the Xml Serialization Attributes, from what I have seen I add an empty namespace to the xml serialization namepsace collections so as not to get the superfluous attributes I did not intend to have.

Edit: The attribute I mean are these:

<url xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'; xmlns:xsd='http://www.w3.org/2001/XMLSchema'; xmlns=''> 

so it gives me two extra attributes.

After further investigation if I change the beginning of the document from:**

writer.WriteStartElement('urlset','http://www.sitemaps.org/schemas/sitemap/0.9'); 

to

writer.WriteStartElement('urlset'); 

**Then I do not get the empty xmlns=” attribute in the url tags. This is great BUT I do require that the root element have xmlns='http://www.sitemaps.org/schemas/sitemap/0.9', i.e.:

<urlset xmlns='http://www.sitemaps.org/schemas/sitemap/0.9'> 

But I still get an empty xmlns='' attribute in the serialized type.

[XmlRoot(ElementName = 'url', Namespace='')] public class SitemapNode {     [XmlElement(ElementName = 'loc')]     public string Location { get; set; }     [XmlElement(ElementName = 'lastmod')]     public DateTime LastModified { get; set; }     [XmlElement(ElementName = 'changefreq')]     public SitemapChangeFrequency ChangeFrequency { get; set; }     [XmlElement(ElementName = 'priority')]     public decimal Priority { get; set; }      public SitemapNode()     {         Location = String.Empty;         LastModified = DateTime.Now;         ChangeFrequency = SitemapChangeFrequency.monthly;         Priority = 0.5M;     }      public SitemapNode(string location, DateTime lastModified, SitemapChangeFrequency changeFrequency, decimal priority)     {         Location = location;         LastModified = lastModified;         ChangeFrequency = changeFrequency;         Priority = priority;     } } 

Then I use the following to append to my XmlWriter:

foreach (uk.co.andrewrea.SitemapNode node in List) {     XmlSerializerNamespaces ns = new XmlSerializerNamespaces();     ns.Add(String.Empty, String.Empty);     Serializer.Serialize(Writer, node, ns); } 

This works out fine except I am left with an emtpy xmlns=” like this

<url xmlns=''> 

Anyone any ideas? Again I can achieve this using the XmlTextWriter and the XmlDocument but I need to achieve it using the XmlWriter.

Any help is greatly appreciated.

  • 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. 2026-05-11T12:47:38+00:00Added an answer on May 11, 2026 at 12:47 pm

    This works (you just need them to be in the same namespace and you use the namespaces class so the writter doesn’t confuse):

    [TestMethod] public void TestMethod3() {     var list = new []{new SitemapNode('1', DateTime.Now, 1), new SitemapNode('2', DateTime.Now.AddDays(1), 2)};     var serializer = new XmlSerializer(typeof(SitemapNode));     var st = new MemoryStream();     using (var writer = XmlWriter.Create(st))     {         var ns = new XmlSerializerNamespaces();         ns.Add('', 'test');         writer.WriteStartElement('test', 'test');         foreach (SitemapNode node in list)         {             serializer.Serialize(writer, node, ns);         }         writer.WriteEndElement();     }     st.Position = 0;     TestContext.WriteLine(new StreamReader(st).ReadToEnd()); }   [XmlRoot(ElementName = 'url', Namespace = 'test')] public class SitemapNode {     [XmlElement(ElementName = 'loc')]     public string Location { get; set; }     [XmlElement(ElementName = 'lastmod')]     public DateTime LastModified { get; set; }     [XmlElement(ElementName = 'priority')]     public decimal Priority { get; set; }      public SitemapNode()     {         Location = String.Empty;         LastModified = DateTime.Now;         Priority = 0.5M;     }      public SitemapNode(string location, DateTime lastModified, decimal priority)     {         Location = location;         LastModified = lastModified;         Priority = priority;     } } 

    And the output is (based on your comments that is what you were looking for):

        <?xml version='1.0' encoding='utf-8'?><test xmlns='test'> <url><loc>1</loc><lastmod>2009-03-05T13:35:54.6468-07:00</lastmod><priority>1</priority></url> <url><loc>2</loc><lastmod>2009-03-06T13:35:54.6478-07:00</lastmod><priority>2</priority></url></test> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 193k
  • Answers 193k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No, Apple does not allow third-party developers to write Spotlight… May 12, 2026 at 6:37 pm
  • Editorial Team
    Editorial Team added an answer I think you'd have to use jQuery to do the… May 12, 2026 at 6:37 pm
  • Editorial Team
    Editorial Team added an answer Based on the auto_increment column, I guess your target database… May 12, 2026 at 6:37 pm

Related Questions

There seems to be no shortage of questions out there about this, but it's
I have been asking a lot of questions about a project I have been
In the current C++0x draft I've noticed they introduced some new explicit keywords to
There is another recent Project Euler question but I think this is a bit

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.