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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:37:44+00:00 2026-05-13T13:37:44+00:00

I have XML that is returned by a 3rd party web service in the

  • 0

I have XML that is returned by a 3rd party web service in the following form:

<object>
    <list name="subscriptions">
        <object>
            <string name="id">something</string> 
            <string name="title">something else</string> 
            <list name="categories" /> 
            <number name="timestamp">1252707770116</number> 
        </object>
        ...more 'object'...
    </list>
</object>

I’m having a lot of issues trying to deserialize this data to an object. I wasn’t able to generate a schema using xsd.exe, so I generated the following classes by hand to try and fit this data:

[XmlRoot("object")]
public class ListOfSubscriptions
{
    [XmlElement("list")]
    public Subscription[] items;
}

[XmlRoot("object")]
public class Subscription
{
    [XmlAttribute()]
    public string id;
    [XmlAttribute()]
    public string title;
    [XmlAttribute()]
    public string[] categories;
    [XmlAttribute()]
    public string timestamp;
}

I’m trying to deserialize this with the following code:

XmlSerializer s = new XmlSerializer(typeof(ListOfSubscriptions));
StreamReader r = new StreamReader("out.xml");
ListOfSubscriptions listSubscribe = (ListOfSubscriptions)s.Deserialize(r);
r.Close();

However, when it finishes, listSubscribe has one member and all its fields are null.

How should I be creating my template for deserializing?

Thanks

Update – 2010/01/28

Thanks to everybody’s comments I’ve revised my classes to the following:

[XmlRoot("object")]
public class ListOfSubscriptions
{
    [XmlElement("list")]
    public SubscriptionList[] items;
}
[XmlRoot("list")]
public class SubscriptionList
{
    [XmlElement("object")]
    public Subscription[] items;
}

[XmlRoot("object")]
public class Subscription
{
    [XmlElement("string")]
    public string id;
    [XmlElement("string")]
    public string title;
    [XmlElement("list")]
    public string[] categories;
    [XmlElement("number")]
    public string timestamp;
}

If I comment out the [XmlElement(…)] lines in Subscription, and run, I get that listSubscribe has one SubscriptionList item which has the correct number of Subscriptions, however, all the elements of the subscriptions are null.

If I uncomment the XmlElement lines, I get an error reflecting a Subscription. I imagine its getting confused because there are multiple elements with the same name.

How do I tie the attribute name to the class member?

  • 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-13T13:37:44+00:00Added an answer on May 13, 2026 at 1:37 pm

    You’re on the right track. However, you are only defining two classes. There are actually three classes to define:

    1. The single root object, with an XML name of “object”. This will have only one member:
    2. The list of objects (with an XML name of “list”). This will have one member, an array of:
    3. Subscriptions, with an XML name of “object”.

    Another problem is that you are defining the Subscription fields as attributes. They aren’t attributes, they’re elements.

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

Sidebar

Related Questions

So I have xml that looks like this: <todo-list> <id type=integer>#{id}</id> <name>#{name}</name> <description>#{description}</description> <project-id
My question is the following. I have xml that is versioned by a namespace.
I have an XML file that starts like this: <Elements name=Entities xmlns=XS-GenerationToolElements> I'll have
I have an XML schema that includes multiple addresses: <xs:element name=personal_address maxOccurs=1> <!-- address
I have WCF service that returns an object that contains an array of bytes
I have a matrix that is mapped to a .NET web service via the
I have an XML that I want to load to objects, manipulate those objects
I have an XML that needs to be databound to a WPF TreeView .
I have an xml that looks like this: <Config> <A></A> <Template><B/><C/></Template> </Config> and I
I have an xml that has text within word elements e.g <word>Police</word> <word>confirmed</word> <word>they

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.