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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:20:59+00:00 2026-06-08T17:20:59+00:00

I’m working on a WP7 app which gets and updates data on a web

  • 0

I’m working on a WP7 app which gets and updates data on a web server. If any updates need a response, I get a list of errors that needs to be dealt with, and a list of possible choices for each error. The issue I’m having is assigning each object its appropriate list of choices. As of now I get a list of errors, and another list of all possible choices for all errors. I’d like the error object to contain the list of only its options so I can handle that.

So here’s an example response:

<?xml version="1.0" encoding="utf-8"?>
<response xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <response_error_dialogs>
        <error_dialog_list>
            <error_dialog_choice>
                <error_dialog_id>1301</error_dialog_id>
                <error_dialog_message>You have changed the phone number.  Select which phone number to make the primary contact number.</error_dialog_message>
                <error_dialog_title>Phone Number Changed</error_dialog_title>
                <error_dialog_is_set>false</error_dialog_is_set>
                <error_dialog_choice_option_list>
                    <error_dialog_choice_option>
                        <error_dialog_choice_option_id>1</error_dialog_choice_option_id>
                        <error_dialog_choice_option_title>Home</error_dialog_choice_option_title>
                    </error_dialog_choice_option>
                    <error_dialog_choice_option>
                        <error_dialog_choice_option_id>2</error_dialog_choice_option_id>
                        <error_dialog_choice_option_title>Mobile</error_dialog_choice_option_title>
                    </error_dialog_choice_option>
                    <error_dialog_choice_option>
                        <error_dialog_choice_option_id>3</error_dialog_choice_option_id>
                        <error_dialog_choice_option_title>Work</error_dialog_choice_option_title>
                    </error_dialog_choice_option>
                </error_dialog_choice_option_list>
            </error_dialog_choice>
            <error_dialog_choice>
                <error_dialog_id>1303</error_dialog_id>
                <error_dialog_message>You have changed the account email address.  Would you like this to be the new default email?</error_dialog_message>
                <error_dialog_title>Email Address Changed</error_dialog_title>
                <error_dialog_is_set>false</error_dialog_is_set>
                <error_dialog_choice_option_list>
                    <error_dialog_choice_option>
                        <error_dialog_choice_option_id>1</error_dialog_choice_option_id>
                        <error_dialog_choice_option_title>No</error_dialog_choice_option_title>
                    </error_dialog_choice_option>
                    <error_dialog_choice_option>
                        <error_dialog_choice_option_id>2</error_dialog_choice_option_id>
                        <error_dialog_choice_option_title>Yes</error_dialog_choice_option_title>
                    </error_dialog_choice_option>
                </error_dialog_choice_option_list>
            </error_dialog_choice>
        </error_dialog_list>
    </response_error_dialogs>
</response>

And here’s the classes used:

public class ErrorDialog
{
    XElement self;

    public ErrorDialog() { }

    public ErrorDialog(XElement errorDialog)
    {
        self = errorDialog;
    }

    public int errorDialogId
    {
        get { return (int)(self.Element("error_dialog_id")); }
    }
    public string errorDialogMessage
    {
        get { return (string)(self.Element("error_dialog_message")); }
    }
    public string errorDialogTitle
    {
        get { return (string)(self.Element("error_dialog_title")); }
    }
    public bool errorDialogIsSet
    {
        get { return (bool)(self.Element("error_dialog_is_set")); }
    }
    public List<ErrorDialogChoice> errorDialogChoice
    {
        get { return (List<ErrorDialogChoice>)(errorDialogChoice); }
    }
    public int errorDialogSelectedOption
    {
        get { return (int)(self.Element("error_dialog_selected_option")); }
    }
}

class ErrorDialogChoice
{
    XElement self;

    public ErrorDialogChoice() { }

    public ErrorDialogChoice(XElement errorDialogChoice)
    {
        self = errorDialogChoice;
    }

    public int errorDialogChoiceOptionId
    {
        get { return (int)(self.Element("error_dialog_choice_option_id")); }
    }
    public string errorDialogChoiceOptionTitle
    {
        get { return (string)(self.Element("error_dialog_choice_option_title")); }
    }
}

And here’s how I’m parsing it:

XElement response = XElement.Parse(data);  

ErrorDialog[] dialogs = response
    .Element("response_error_dialogs")
    .Element("error_dialog_list")
    .Elements("error_dialog_choice")
    .Select(e => new ErrorDialog(e))
    .ToArray();

ErrorDialogChoice[] edChoices = response
    .Element("response_error_dialogs")
    .Element("error_dialog_list")
    .Element("error_dialog_choice")
    .Element("error_dialog_choice_option_list")
    .Elements("error_dialog_choice_option")
    .Select(e => new ErrorDialogChoice(e))
    .ToArray();

So with this example, the first error_dialog_choice object will have a List containing 3 error_dialog_choice_option objects, the second has the two error_dialog_choice_option objects, and any more that may come back. Any help is appreciated. Thanks.

  • 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-08T17:21:00+00:00Added an answer on June 8, 2026 at 5:21 pm

    You can use XML serialization to achieve this much easier:

    var reader = new StringReader(xmlString);
    var ser = new XmlSerializer(typeof(Response));
    var result = (Response) ser.Deserialize(reader);
    

    Using these class definitions.

    [XmlType("response")]
    public class Response
    {
        [XmlElement("response_error_dialogs")]
        public ErrorDialog ErrorDialog;
    }
    
    [XmlType("response_error_dialogs")]
    public class ErrorDialog
    {
        [XmlArray("error_dialog_list")]
        public List<ChoiceErrorDialog> ChoiceList;
    }
    
    [XmlType("error_dialog_choice")]
    public class ChoiceErrorDialog
    {
        [XmlElement("error_dialog_id")]
        public int Id;
    
        [XmlElement("error_dialog_message")]
        public string Message;
    
        [XmlElement("error_dialog_title")]
        public string Title;
    
        [XmlElement("error_dialog_is_set")]
        public bool IsSet;
    
        [XmlArray("error_dialog_choice_option_list")]
        public List<Option> OptionList;
    }
    
    [XmlType("error_dialog_choice_option")]
    public class Option
    {
        [XmlElement("error_dialog_choice_option_id")]
        public int Id;
    
        [XmlElement("error_dialog_choice_option_title")]
        public string Title;
    }
    

    I am guessing there can be more types of error dialogs, and <error_dialog_choice> is just one of the possible types. In this case you could use subclassing, and list the subclasses with XmlArrayItem attributes.


    You could also generate the class definitions with xsd.exe or svcutil.exe, from an .xsd or .wsdl file. xsd.exe can even infer the schema from a sample .xml file.

    xsd.exe /?
    svcutil.exe /?
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
link Im having trouble converting the html entites into html characters, (&# 8217;) i
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&#8217;Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.