Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Optimizing size of generated XML

3 views
Skip to first unread message

Nick Gilbert

unread,
Jul 20, 2005, 9:16:43 AM7/20/05
to
Hi,

I have to send an array of prices for a list of products over XML.

Currently my XML data looks like this:

<ArrayOfProd>
<Prod Code="productcode001">
<Prices>
<P F="2005-01-01" T="2005-09-09" Q="10" V="27.50" />
<P F="2005-01-01" T="2005-09-09" Q="10" V="27.50" />
<P F="2005-01-01" T="2005-09-09" Q="10" V="27.50" />
<P F="2005-01-01" T="2005-09-09" Q="10" V="27.50" />
<P F="2005-01-01" T="2005-09-09" Q="10" V="27.50" />
<P F="2005-01-01" T="2005-09-09" Q="10" V="27.50" />
</Prices>
</Prod>
</ArrayOfProd>

Is there a way I ca remove the redundant <prices> tag (caused by the
array name of the property) so that the P tags nest directly within the
Prod tag?

Also, can I prevent it from formatting the XML with leading whitespace
somehow? Since a human never has to read it, the whitespace is just a
waste of bandwidth. Even if it just removed the leading spaces - that
would be a lot better.

My classes are below:

[XmlType("Prod")]
public class ProductPriceGroup {
[System.Xml.Serialization.XmlAttribute("Code")]
public string ProductCode;

[System.Xml.Serialization.XmlArrayItemAttribute("P")]
public Price[] Prices;
}

public class Price {
[System.Xml.Serialization.XmlAttribute("F",DataType="date")]
public DateTime FromDate;

[System.Xml.Serialization.XmlAttribute("T",DataType="date")]
public DateTime ToDate;

[System.Xml.Serialization.XmlAttribute("Q")]
public int Quantity;

[System.Xml.Serialization.XmlAttribute("V")]
public decimal Value;
}

Thanks,

Nick...

Steven Cheng[MSFT]

unread,
Jul 20, 2005, 10:28:55 PM7/20/05
to
Hi Nick,

Welcome to ASPNET newsgroup.
From your description, you'd like to perform the following two tasks on
your asp.net webservice:
1.Preventing the asp.net runtime from formatting the response SOAP
message(put whitespace and indent?)

2.Customize your custom class to avoid wrapper element for array property.

If there're anything I didn't quite get, please feel free to let me know.
Based on my research, here are some of my understanding and suggestions on
the two problem:
1. I'm not sure how did you get the underlying SOAP message and found that
it was formated with whitespace and indent. I've used trace utility(in soap
toolkit3) and the .NET soap Extenstion to capture the soap message of
asp.net webservice and didn't find any additional formatting on the
message. So would you tell me the way you capture the message or use which
trace tool?

2. For customizing the serizlized xml content of our classes, we can use
xmlserizliation attributes to adjust our classes. For your scenario, you
can try modify your ProductPriceGroup class's defintion as below:

[XmlType("Prod")]
public class ProductPriceGroup
{
[System.Xml.Serialization.XmlAttribute("Code")]
public string ProductCode;


[System.Xml.Serialization.XmlElement("P")]
public Price[] Prices;
}

which will make the serilized xml of ProductPriceGroup's Prices[] property
without the wrapper element.
Also, for such problem, generally we can first define the XML Schema for
your webservice methods and then use some XML 2 CLASS tools (such as the
.net's xsd.exe) to generate the class file from the schema. Though the
autogenerated class code maynot be perfect, but it'll be much eaiser for us
to do some adjustment based on that generated file. Also, this means can
make our webservice more interopable.

Hope these helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
Date: Wed, 20 Jul 2005 14:16:43 +0100
From: Nick Gilbert <Ni...@newsgroup.nospam>
User-Agent: Mozilla Thunderbird 1.0+ (Windows/20050714)
MIME-Version: 1.0
Subject: Optimizing size of generated XML
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <OfZEH1Sj...@tk2msftngp13.phx.gbl>
Newsgroups:
microsoft.public.dotnet.xml,microsoft.public.dotnet.framework.webservices
NNTP-Posting-Host: neon.staging.x-rm.com 195.166.37.20
Lines: 1
Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.webservices:7263
microsoft.public.dotnet.xml:7780
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices

Nick Gilbert

unread,
Jul 22, 2005, 7:04:40 AM7/22/05
to
Hi Steven,

Thanks for your suggestion with the XML Attributes. I have now got the
XML formatted as I would like it. I found the XML Schema editor in
VS.NET difficult to use and I couldn't understand how to produce the XML
I wanted, but the XML Attributes seem to have solved my problem.

With regards to the whitespace in XML problem: I was testing the
webservice using the "Invoke" button on the test page that you get if
you go to the webservice in a browser. This returned formatted XML with
whitespace indenting. Perhaps a real SOAP call to the webservice causes
it to render XML with no whitespace as it is not trying to be
human-readable?

Thanks,

Nick...

Steven Cheng[MSFT]

unread,
Jul 24, 2005, 9:07:01 PM7/24/05
to
Hi Nick,

As for the building .net serializable classes from xml schema, I'd also
recommend you another tools built by Chris Cells:

#XSDClassesGen
http://www.sellsbrothers.com/tools/#xsdClassesGen

This tool can be installed so as to directly used in VS.NET. You can also
try using this tool to generate class after you create your message contact
schema in VS.NET

In addition, as for the whitespaces you see in the test interface (in
browser) , I think this is because IE explorer will always format the xml
document so as to display in a nice view. As I've mentioned in the former
message, a real SOap call to the webservice will get a unformated (with no
extra whitesspaces ) SOAP response message. You can check it through some
network trace tools such as SOAPTOOLKIT'S trace utility , TCPTrace or
netmon....

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------

Date: Fri, 22 Jul 2005 12:04:40 +0100
From: Nick Gilbert <Ni...@newsgroup.nospam>
User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Subject: Re: Optimizing size of generated XML
References: <OfZEH1Sj...@tk2msftngp13.phx.gbl>
<$ROV7vZj...@TK2MSFTNGXA01.phx.gbl>
In-Reply-To: <$ROV7vZj...@TK2MSFTNGXA01.phx.gbl>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Message-ID: <eYJBq0q...@TK2MSFTNGP10.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.webservices


NNTP-Posting-Host: neon.staging.x-rm.com 195.166.37.20
Lines: 1

Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.webservices:7283
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices

0 new messages