473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Optimizing size of generated XML

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...

Nov 23 '05 #1
3 1777
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: <Of**************@tk2msftngp13.phx.gbl>
Newsgroups:
microsoft.public.dotnet.xml,microsoft.public.dotne t.framework.webservices
NNTP-Posting-Host: neon.staging.x-rm.com 195.166.37.20
Lines: 1
Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msft ngp13.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

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...
Nov 23 '05 #2
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] wrote:
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: <Of**************@tk2msftngp13.phx.gbl>
Newsgroups:
microsoft.public.dotnet.xml,microsoft.public.dotne t.framework.webservices
NNTP-Posting-Host: neon.staging.x-rm.com 195.166.37.20
Lines: 1
Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msft ngp13.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

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...

Nov 23 '05 #3
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: <Of**************@tk2msftngp13.phx.gbl>
<$R**************@TK2MSFTNGXA01.phx.gbl>
In-Reply-To: <$R**************@TK2MSFTNGXA01.phx.gbl>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Message-ID: <eY*************@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!TK2MSFT NGP10.phx.gbl
Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.webservices:7283
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices

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] wrote:
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: <Of**************@tk2msftngp13.phx.gbl>
Newsgroups:
microsoft.public.dotnet.xml,microsoft.public.dotne t.framework.webservices
NNTP-Posting-Host: neon.staging.x-rm.com 195.166.37.20
Lines: 1
Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msft ngp13.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

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...


Nov 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: ArShAm | last post by:
Hi there Please help me to optimize this code for speed I added /O2 to compiler settings I added /Oe to compiler settings for accepting register type request , but it seems that is not allowed...
3
by: PWalker | last post by:
Hi, I have written code that I would like to optimize. I need to push it to the limit interms of speed as the accuracy of results are proportional to runtime. First off, would anyone know any...
8
by: Hagen | last post by:
Hi, I have a question that you probably shouldn´t worry about since the compiler cares for it, but anyways: When you run your compiler with optimization turned on (eg. g++ with -Ox flag) and...
37
by: Thomas Matthews | last post by:
Hi, My son is writing a program to move a character. He is using the numbers on the keypad to indicate the direction of movement: 7 8 9 4 5 6 1 2 3 Each number has a direction except...
4
by: Flashman | last post by:
A little confusing with setting up optimizing options with 2003 .NET. Under the Optimization Tab. if you set to /O1 or /O2 is the program ignoring the settings for Inline Function expansion,...
7
by: sameer | last post by:
Hi all, Application environment : VB.Net desktop application,.NET 1.1 Framework, VS 2003. communicates between the database and the application is done over webservices using ADO.NEt Datasets....
24
by: Richard G. Riley | last post by:
Without resorting to asm chunks I'm working on a few small routines which manipulate bitmasks. I'm looking for any guidance on writing C in a manner which tilts the compilers hand in, if possible,...
35
by: Brett Romero | last post by:
I'm using MSBUILD to build release and debug versions of a winform project (VS.NET 2005). The project file has conditionals to file reference DLLs depending on the build configuration (debug or...
2
by: Andrea Taverna | last post by:
Hello everyone, I wrote a bunch of recursive functions to operate on multi-dimensional matrices. The matrices are allocated dynamically in a non-contiguous way, i.e. as an array of pointers...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.