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

The Archive Base Latest Questions

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

I am serializing the following entity into XML to send to our Google Search

  • 0

I am serializing the following entity into XML to send to our Google Search Appliance:

[Serializable]
[XmlType("record")]
public class GSADocumentRecord
{
    public enum RecordActions
    {
        Add,
        Delete
    }

    [XmlAttribute(AttributeName = "url")]
    public string URL { get; set; }

    [XmlAttribute(AttributeName = "mimetype")]
    public string MimeType { get; set; }

    [XmlAttribute(AttributeName = "last-modified")]
    public string LastModified { get; set; }

    [XmlAttribute(AttributeName = "action")]
    public string Action { get; set; }

    [XmlArray(ElementName = "metadata", Order = 0)]
    public List<GSADocumentRecordMeta> MetaData { get; set; }

    [XmlElement(ElementName = "content", Order = 1, Type = typeof(CDATA))]
    public CDATA Content { get; set; }
}

The problem is that when this is serialzied without any MetaData entries, it adds <metadata /> to the xml. This is a problem because GSA (for whatever reason) errors out if there is an empty metadata node when used for some actions.

I am serializing this class with the following code:

        var ms = new System.IO.MemoryStream();
        XmlSerializer xml = new XmlSerializer(this.GetType());

        StreamWriter sw = new StreamWriter(ms);
        XmlWriter xw = new XmlTextWriter(sw);

        xw.WriteStartDocument();
        xw.WriteDocType("gsafeed", "-//Google//DTD GSA Feeds//EN", null, null);

        XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
        ns.Add("", "");

        xml.Serialize(xw, this, ns);

        ms.Position = 0;

How can I tell the XmlWriter to ignore this element if the list is empty?

  • 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:29:18+00:00Added an answer on June 1, 2026 at 9:29 am

    Having a self-closing tag certainly seems legal, it sounds like the parser on their side is causing the problem. You could write the XML out to a string first, and then do a .Replace("<metadata />", "").

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

Sidebar

Related Questions

I'm serializing to XML my class where one of properties has type List<string>. public
I am serializing objects to XML with the following code: public static string SerializeToString<T>(T
I'm serializing class which contains DateTime property. public DateTime? Delivered { get; set; }
I am serializing a class using simple-xml ( http://simple.sourceforge.net/ ) but when i try
I'm de/serializing an object like so: public class myClass : ISerializable { public List<OType>
I have the following XML which needs deserializing/serializing: <instance> <dog> <items> <item> <label>Spaniel</label> </item>
When I serialize the following class, the ContentPageId XML element is missing from the
I have the following XML Parsing code in my application: public static XElement Parse(string
Following my question on serializing a System.Array to a Xml string, I would like
I'm serializing a class like this public MyClass { public int? a { get;

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.