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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:53:10+00:00 2026-06-15T11:53:10+00:00

I am creating a service using Microsoft ASP.NET Web API with the following requirements:

  • 0

I am creating a service using Microsoft ASP.NET Web API with the following requirements:

  1. Input must be in XML (no json)
  2. XML will follow a standard (cannot add custom element names/attributes to the input xml)
  3. When encountering exceptions in deserialization (i.e. data values in bad format) they must be logged as warnings and parsing of the input xml must continue
  4. The XML will contain collections of elements in which the elements need to be
    deserialized into types derived from a base type

Requirements 1 and 2 simply define my input. I started developing my solution by using the built-in System.Xml.Serialization.XmlSerializer class, but had to abandon it because it could not handle requirement #3.

Alternately, I found YAXLib which provided a very useful way to handle requirement #3.

YAXLib also handles requirement #4, but only by utilizing custom attributes in the XML:

  <ListOfObjects>
    <Object yaxlib:realtype="System.Int32">7</Object>
    <Object yaxlib:realtype="System.Double">3.14</Object>
    <Object yaxlib:realtype="System.String">Congrats</Object>
    <Object yaxlib:realtype="System.StringSplitOptions">RemoveEmptyEntries</Object>
  </ListOfObjects>

Because of requirement #2, I cannot use this approach. I need something like the System.Xml.Serialization.XmlElementAttribute so I can instruct the serializer in code, not in the data. Is there an existing solution out there that will handle all of these requirements?

Example:

Input

<DEALS>
    <DEAL>
        <COLLATERALS>
            <COLLATERAL>xyz</COLLATERAL>
            <COLLATERAL>1.2</COLLATERAL>
            <COLLATERAL>4.5</COLLATERAL>
        </COLLATERALS>
        <LOANS>
            <LOAN>
                <CLOSING_INFORMATION />
            </LOAN>
        </LOANS>
    </DEAL>
</DEALS>

C# Classes

public class DEAL
{
    [System.Xml.Serialization.XmlElementAttribute("COLLATERALS", typeof(COLLATERALS))]
    [System.Xml.Serialization.XmlElementAttribute("LOANS", typeof(LOANS))]
    [YAXCollection(YAXCollectionSerializationTypes.RecursiveWithNoContainingElement)]
    public object[] Items
    {
        get
        {
            return this.itemsField;
        }
        set
        {
            this.itemsField = value;
        }
    }

    // Remaining implementation details omitted..
}

public class COLLATERALS { /* details omitted.. */ }
public class LOANS { /* details omitted.. */ }

public class COLLATERAL
{
    [System.Xml.Serialization.XmlTextAttribute()]
    public decimal Value { get; set; }
}

Expected Output

Objects in the Items collection of the DEALS class should be deserialized into their respective types: COLLATERALS and LOANS. Also, the first collateral with the value ‘xyz’ will not get deserialized (since the type is decimal) but the remaining valid COLLATERAL items would get deserialized. The error parsing ‘xyz’ to decimal should be logged somehow.

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

    You can use an XML Schema (an XSD file) to define what the valid format of an XML file is. There are existing tools which will validate whether or not a particular file complies with a schema or not.

    By providing this schema publicly you will be able to allow your clients to validate their own requests without needing to actually interact with your web service. It will allow them to see if their inputs are valid, and if they need to perform complex analysis on what specifically needs to be changed to comply they would be capable of doing that on their own.

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

Sidebar

Related Questions

I'm creating REST service using ASP.NET Web API. How can I return 401 status
Background: I'm in the process of creating a web service using ASP.NET 2.0. This
I am creating a REST Web Service using Java and Jersey API. The basic
I'm creating a small service using api-libraries, such as Twitter. Is it possible to
I am creating an application which involves so many web-service calls. I am using
I'm investigating in using Microsoft's WCF WebHttp Services for creating a RESTful API. In
I'm creating a pretty simple HTTP service using OpenRasta. For HEAD requests, the HTTP
I am creating Schema using Core Service in SDL Tridion 2011 SP1. In the
Guyz facing problems with creating a push notification service (for android) using Google C2DM
I'm creating a link shortening service and I'm using base64 encoding/decoding of an incremented

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.