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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:10:06+00:00 2026-05-28T15:10:06+00:00

We need to use a web service which communicates extremely ugly XML. It is

  • 0

We need to use a “web service” which communicates extremely ugly XML. It is not developed by us and there is zero chance to make its developers understand proper XML.

FYI, this web service also accepts the same kind of XML in a HTTP GET URL parameter (not the request body) – and the guys who developed it don’t understand why that is a bad practice.

So, what is the fastest way to map an XML such as this:

<foo id="document">
    <foo id="customer">
        <bar name="firstname" value="Joe"/>
        <bar name="lastname" value="Smith"/>
        <foo id="address">
            <bar name="city" value="New York"/>
            <bar name="country" value="USA"/>
        </foo>
    </foo>
    <bar name="somemoredata1" value="123"/>
    <bar name="somemoredata2" value="abc"/>
</foo>

into classes like this:

public class Document
{
    public Customer Customer { get; set; }

    public int SomeMoreData1 { get; set; }

    public string SomeMoreData2 { get; set; }
}

public class Customer
{
    public Address Address { get; set; }

    public string FirstName { get; set; }

    public string LastName { get; set; }
}


public class Address
{
    public string City { get; set; }

    public string Country { get; set; }
}

using eg. XML Serializer attributes or any other way that needs as little boilerplate code as possible.

I made up the foo and bar element names, but the structure of the XML I need to parse is based on the exact same convention.

I could of course implement IXmlSerializable manually in these classes or just make Foo and Bar classes and use those with the XmlSerializer, but none of these options seem to be a good solution.

Thanks in advance for your answers!

  • 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-28T15:10:07+00:00Added an answer on May 28, 2026 at 3:10 pm

    You can’t do it with XML serializer attributes: there is just no way to make it take a field name out of a specified attribute. You will have to deserialize manually (possibly generating the boilerplate) or pre-process the XML — a simple XSLT along the following lines will do the trick:

    <xsl:template match="foo">
      <xsl:element name="{@id}">
        <xsl:apply-templates/>
      </xsl:element>
    </xsl:template>
    
    <xsl:template match="bar">
      <xsl:element name="{@name}">
        <xsl:value-of select="@value"/>
      </xsl:element>
    </xsl:template>
    

    Update: for the reverse transformation:

    <xsl:template match="*[count(child::text())=1]">
      <bar value="{text()}" name="{local-name()}"/>
    </xsl:template>
    
    <xsl:template match="*">
      <foo id="{local-name()}">
        <xsl:apply-templates/>
      </foo>
    </xsl:template>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am forced to use SharePoint web services. I need a web service which
I'm planning to develop a web service, i need to use in memory cache,
I need to develop a WCF server (basically a web service which will eventually
I need to create web service (.NET) which will be used by other system.
I have created a web service which has a couple of methods developed using
I have a web service which returns a string representing an Xml file. The
I have a Web Service ( model-layer ) which communicates with Database. This module
I need to consume a web service which was built under Https in java.
I need to write a WSDL file to an existing web service which is
In my client application I have to use web service UserNameOverTransport, so I need

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.