0

I have received a specification for a webservice call which looks like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<methodResponse>
    <params>
        <param>
            <value>
                <array>
                    <data>
                        <value>
                            <struct>
                                <member>
                                    <name>OrderNumber</name>
                                    <value>
                                        <string>101</string>
                                    </value>
                                </member>
                                <member>
                                    <name>Created</name>
                                    <value>
                                        <string>2010-11-01 11:00:00</string>
                                    </value>
                                </member>
                                <member>
                                    <name>Rows</name>
                                    <value>
                                        <array>
                                            <data>
                                                <value>
                                                    <struct>
                                                        <member>
                                                            <name>ProductNumber</name>
                                                            <value>
                                                                <string>prod1</string>
                                                            </value>
                                                        </member>
                                                        <member>
                                                            <name>Title</name>
                                                            <value>
                                                                <string>Produkt 1</string>
                                                            </value>
                                                        </member>
                                                    </struct> 
                                                </value>

Is this some kind of standard serialize format? (I think the service is written in php)

Any good ideas how to extract the information into a .net class?

Edit:

I solved it with an xslt transform which creates a more "normal" xml file

<Orders>
    <struct>
        <OrderNumber>101</OrderNumber>
        <Created>2010-11-01 11:00:00</Created>
        <Rows>
            <struct>
                <ProductNumber>prod1</ProductNumber>
                ...

From the result it was easy to create a schema and generate a .net class with xsd.exe.

The transform looks like:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                              xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:output method="xml" indent="yes"/>

<xsl:strip-space elements="*"/>
<xsl:preserve-space elements="struct"/>

<xsl:template match="/">
    <Orders>
      <xsl:apply-templates/>
    </Orders>
</xsl:template>

<xsl:template match="struct">
    <struct>
        <xsl:apply-templates/>
    </struct>
</xsl:template>

<xsl:template match="value/string|value/double">
    <xsl:value-of select="self::*"/>
</xsl:template>

<xsl:template match="//member">
    <xsl:element name="{name}">
        <xsl:apply-templates/>
    </xsl:element>
</xsl:template>

<xsl:template match="text()"/>
</xsl:stylesheet>
2
  • 1
    TRWTF = the XML format? There's more nesting than actual data. Commented Nov 17, 2010 at 14:23
  • @delnan: This could be worse than Extensible XML Commented Nov 17, 2010 at 14:57

2 Answers 2

1

Is this some kind of standard serialize format?

I really hope not, it is horrible. Deserving of publicity at http://thedailywtf.com/

Any good ideas how to extract the information into a .net class?

Assuming the sample is incomplete and the real thing is valid XML, any of the .NET XML APIs will be able to do it. (The XML serialisers, including Data Contract, are unlikely to work without a lot of effort to create wrapper types for all the extra levels of elements being seen there.)

Perhaps pointing the writers of this "service" at OData to show what is possible rather than reinventing it extremely badly.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. Do you have any suggestions on how to use the XML APIs. Can I somehow avoid deep code nesting to get the information out?
@adrianm: I would want to look up multiple examples before making a choice, but I would probably either pre-process with XSLT to remove the noise or look to XPath (i.e. XPathDocument/XPathNavigator) to do the extract. However my first priority would be to try to see why this is the format being generated and see if something with less structure generated.
1

I found out that it is a standard format called XML-RPC which got its own tag here on SO. Official site Wikipedia

There is a .Net library available

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.