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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:53:07+00:00 2026-05-27T11:53:07+00:00

I’m trying to serialize an object that have a duplicate node name using C#,

  • 0

I’m trying to serialize an object that have a duplicate node name using C#, the reason what i need to do this is because i’m building a library that use a third party API.

The request i need to build look like this.

<DATASET>
   <SITE_ID>123</SITE_ID>
   <DATA type=“name”>Secondary List</DATA>
   <DATA type="extra" id="CLICKTHRU_URL">http://my.domain.com/</DATA>
   <DATA type="extra" id="REPLY_FORWARD_EMAIL">support@my.domain.com</DATA>
   <DATA type="extra" id="REPLY_FROM_EMAIL">forward@my.domain.com</DATA>
   <DATA type="extra" id="REPLY_FROM_NAME">8@yahoo.com</DATA>
   <DATA type="extra" id="REPLY_FORWARD_SUBJECT">Customer Replies</DATA>
   <DATA type="extra" id="HANDLE_UNSUBSCRIBE"></DATA>
   <DATA type="extra" id="HANDLE_AUTOREPLY"></DATA>
   <DATA type="extra" id="FOOTER_TEXT">Confidentiality agreement…</DATA>
   <DATA type="extra" id="FOOTER_HTML"> Confidentiality agreement…</DATA>
</DATASET>

My approach is create a class that represent the request and use the XML serialization attributes, the class look like this:

[XmlRoot("DataSet")]
public class AddListCallHolder : BaseCallHolder
{
    private BaseAttributeHolder _name = new BaseAttributeHolder(type: "");

    [XmlElement("DATA")]
    public BaseAttributeHolder Name
    {
        get { return _name; }
        set { _name = value; }
    }

    private BaseAttributeHolder _clickthruUrl = new BaseAttributeHolder(id: "CLICKTHRU_URL");

    [XmlElement("DATA")]
    public BaseAttributeHolder CLICKTHRU_URL
    {
        get { return _clickthruUrl; }
        set { _clickthruUrl = value; }
    }
}

The base class of the attribute is:

public class BaseAttributeHolder
{
    [XmlAttribute("type")]
    public string Type { get; set; }

    [XmlAttribute("id")]
    public string Id { get; set; }

    [XmlText]
    public string Value { get; set; }

    public BaseAttributeHolder(string value, string id, string type = "extra")
    {
        Type = type;
        Value = value;
        Id = id;
    }

    public BaseAttributeHolder(string id, string type = "extra")
    {
        Type = type;
        Id = id;
    }

    public BaseAttributeHolder(string type = "extra")
    {
        Type = type;
    }

    public BaseAttributeHolder()
    {

    }
}

When i try to serialize and object i getting this error:

The XML element ‘DATA’ from namespace ” is already present in the current scope. Use XML attributes to specify another XML name or namespace for the element.

Is there any work around to serialize this object or get the the structure of the request.

  • 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-27T11:53:08+00:00Added an answer on May 27, 2026 at 11:53 am

    What about using an array or list to de-serialize all <DATA>‘s and then add properties which operate on this array?

      [XmlRoot("DataSet")]
      public class AddListCallHolder
      {
          [XmlArrayItem(typeof(BaseAttributeHolder), ElementName = "DATA")]
          public BaseAttributeHolder[] data 
          { 
               get;
               set;
          }
    
          [XmlIgnore]
          public BaseAttributeHolder Name
          {
              get
              {
                 return data.FirstOrDefault(d => d.Type == "name");
              }
          }
    
          [XmlIgnore]
          public BaseAttributeHolder CLICKTHRU_URL
          {
              get
              {
                 return data.FirstOrDefault(d => d.Type == "extra" && d.Id == "CLICKTHRU_URL");
              }
          }
      }
    

    I think you will also be able to come up with the setters.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I am trying to loop through a bunch of documents I have to put
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6

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.