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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:55:02+00:00 2026-06-02T11:55:02+00:00

I’m querying an API which returns a response in XML, so I’ve been looking

  • 0

I’m querying an API which returns a response in XML, so I’ve been looking into Controlling XML Serialization Using Attributes .

The API response looks like this:
enter image description here
What I want to do is takes all the CampaignDTO elements (0..*) and put them in a list. How could this be done? I keep running into errors because of the Totalcount element at the end.

public class Campaign
    {
        #region CTor
        public Campaign()
        {
        }
        #endregion

        #region Properties

        [XmlElement(ElementName = "Id_campaign")]
        public string ID_Campaign { get; set; }
        [XmlElement(ElementName = "Campaignname")]
        public string ElementName { get; set; }
        [XmlElement(ElementName = "Websiteurl")]
        public string WebsiteUrl { get; set; }
        [XmlElement(ElementName = "Privacypolicyurl")]
        public string PrivacyPolicyUrl { get; set; }
        [XmlElement(ElementName = "Termsurl")]
        public string TermsUrl { get; set; }
        [XmlElement(ElementName = "Pricepageurl")]
        public string PricepageUrl { get; set; }
        [XmlElement(ElementName = "Maxcredit")]
        public Int32 MaxCredit { get; set; }
        [XmlElement(ElementName = "Fk_id_currency")]
        public string FK_ID_Currency { get; set; }
        [XmlElement(ElementName = "Maxscans")]
        public short MaxScans { get; set; }
        [XmlElement(ElementName = "Startdate")]
        public DateTime Startdate { get; set; }
        [XmlElement(ElementName = "Enddate")]
        public DateTime Enddate { get; set; }
        [XmlElement(ElementName = "Starthour")]
        public short Starthour { get; set; }
        [XmlElement(ElementName = "Endhour")]
        public short Endhour { get; set; }
        [XmlElement(ElementName = "Pmam")]
        public string PMAM { get; set; }
        [XmlElement(ElementName = "Language")]
        public string Language { get; set; }
        [XmlElement(ElementName = "Fk_id_merchantapp")]
        public string FK_ID_MerchantApp { get; set; }
        [XmlElement(ElementName = "Campaigntype")]
        public string CampaignType { get; set; }
        [XmlElement(ElementName = "Createtimestamp")]
        public DateTime CreateTimestamp { get; set; }
        [XmlElement(ElementName = "Lastupdate")]
        public DateTime LastUpdate { get; set; }
        [XmlElement(ElementName = "Lastupdateby")]
        public string LastUpdateBy { get; set; }
        [XmlElement(ElementName = "Status")]
        public short Status { get; set; }

        #endregion
    }
  • 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-02T11:55:03+00:00Added an answer on June 2, 2026 at 11:55 am

    You must define the object model corresponding to the xml correctly. Based on the sample xml above, I’ve come up with the below model

    [XmlRoot("CampaignListXml")]
    public class CampaignList
    {
        [XmlElement]
        public Allcampaign Allcampaign;
    
        [XmlElement]
        public int TotalCount;
    }
    
    public class Allcampaign
    {
        [XmlElement("CompaignDTO", typeof(Campaign))]
        public Campaign[] CampaignArray;
    }
    
    public class Campaign
    {
        #region CTor
        public Campaign()
        {
        }
        #endregion
    
        #region Properties
    
        [XmlElement(ElementName = "Id_campaign")]
        public string ID_Campaign { get; set; }
        [XmlElement(ElementName = "Campaignname")]
        public string ElementName { get; set; }
        [XmlElement(ElementName = "Websiteurl")]
        public string WebsiteUrl { get; set; }
        [XmlElement(ElementName = "Privacypolicyurl")]
        public string PrivacyPolicyUrl { get; set; }
        [XmlElement(ElementName = "Termsurl")]
        public string TermsUrl { get; set; }
        [XmlElement(ElementName = "Pricepageurl")]
        public string PricepageUrl { get; set; }
        [XmlElement(ElementName = "Maxcredit")]
        public Int32 MaxCredit { get; set; }
        [XmlElement(ElementName = "Fk_id_currency")]
        public string FK_ID_Currency { get; set; }
        [XmlElement(ElementName = "Maxscans")]
        public short MaxScans { get; set; }
        [XmlElement(ElementName = "Startdate")]
        public DateTime Startdate { get; set; }
        [XmlElement(ElementName = "Enddate")]
        public DateTime Enddate { get; set; }
        [XmlElement(ElementName = "Starthour")]
        public short Starthour { get; set; }
        [XmlElement(ElementName = "Endhour")]
        public short Endhour { get; set; }
        [XmlElement(ElementName = "Pmam")]
        public string PMAM { get; set; }
        [XmlElement(ElementName = "Language")]
        public string Language { get; set; }
        [XmlElement(ElementName = "Fk_id_merchantapp")]
        public string FK_ID_MerchantApp { get; set; }
        [XmlElement(ElementName = "Campaigntype")]
        public string CampaignType { get; set; }
        [XmlElement(ElementName = "Createtimestamp")]
        public DateTime CreateTimestamp { get; set; }
        [XmlElement(ElementName = "Lastupdate")]
        public DateTime LastUpdate { get; set; }
        [XmlElement(ElementName = "Lastupdateby")]
        public string LastUpdateBy { get; set; }
        [XmlElement(ElementName = "Status")]
        public short Status { get; set; }
    
        #endregion
    }
    

    Now you can construct the object from xml as below

    using (StringReader reader = new StringReader(xml))
    {
        XmlSerializer serializer = new XmlSerializer(typeof(CampaignList));
        CampaignList x1 = serializer.Deserialize(reader) as CampaignList;
        Compaign[] compaignArray = x1.Allcompaign.CompaignArray; //This will have all the compaign list
    }
    

    Hope this helps.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I would like to run a str_replace or preg_replace which looks for certain words
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm making a simple page using Google Maps API 3. My first. One marker
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,

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.