Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 8th, 2007, 03:21 AM
Authorized User
 
Join Date: Mar 2006
Location: pune, Maharashtra, India.
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to anup_daware Send a message via MSN to anup_daware Send a message via Yahoo to anup_daware
Default XmlDocument Vs StringBuilder

Hi Group,

You might have found the Title a little strange :); well following is the problem description:
I want to form a SOAP xml request to a servlet, I have my Request xml template ready.
Now I have following options:
1. Load the xml template in an XmlDocument object and manipulate it.
2. Load the xml template in a StringBuilder object, manipulate it and then load it in XmlDocument.
3. Not using any template and creating the xml from scratch.
Following is the sample xml template which I will use:
<?xml version="1.0" encoding="UTF-8"?>
<MT_MaterialSearchRequest>

 <CUSTOMER> CUSTOMER _PLACEHOLDER</CUSTOMER>
 <SALES_ORG> SALES_ORG _ PLACEHOLDER </SALES_ORG>

 <DEFAULT_SORTING> DEFAULT_SORTING _PLACEHOLDER</DEFAULT_SORTING>

<WIDTH> WIDTH _HOLDER</WIDTH>
 <SERIE> SERIE _HOLDER</SERIE>

 <VISIBILITY_ITEM_IN>
  <ITEM> <!—NOTE: Number of <ITEM> nodes is dynamic>
     <MATERIAL></MATERIAL>
 </ITEM>
<ITEM>
 <MATERIAL></MATERIAL>
 </ITEM>
 </VISIBILITY_ITEM_IN>
</MT_MaterialSearchRequest>

My Questions:
1. For this scenario which of the above mentioned options which is more suitable?
2. In General which options is more preferable?
3. I know that second option of using StringBuilder is going to be very easy for implementation, but which option is better in terms of speed of execution and memory considerations?

Hoping to get some expert comments on this :)

Thanks,
Anup Daware
__________________
--Everything you can imagine is real.--
Reply With Quote
  #2 (permalink)  
Old February 8th, 2007, 04:26 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I normally start by loading a template into XmlDocument and then manipulating it.

The big downside with using just StringBuilder is that you have to escape characters such as & and <. This ends up being more trouble than it's worth. The only time I would do that was if I was worried about resources and could dispense with XmlDocument altogether which only really happens on such things as mobile devices.

The third option of doing it completely within XmlDocument can have the merit of being easier to code sometimes, if your document is very repetitive; that doesn't look the case here and creating comments etc. can be tedious using just the DOM.

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #3 (permalink)  
Old February 8th, 2007, 07:34 AM
Authorized User
 
Join Date: Mar 2006
Location: pune, Maharashtra, India.
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to anup_daware Send a message via MSN to anup_daware Send a message via Yahoo to anup_daware
Default

Hi Joe,

If we ignore certain problem of handling characters like < and & with StringBuilder,
is it a better approach in terms of performance?

Thanks,
Anup Daware
Reply With Quote
  #4 (permalink)  
Old February 8th, 2007, 07:40 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Very slightly and only really any difference if you can get rid of XmlDocument altogether. The worst part is instantiating the XmlDocument initially, after that adding new nodes is no real problem.

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #5 (permalink)  
Old February 8th, 2007, 09:54 AM
Authorized User
 
Join Date: Mar 2006
Location: pune, Maharashtra, India.
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to anup_daware Send a message via MSN to anup_daware Send a message via Yahoo to anup_daware
Default

Hi Joe,

Well I can't get rid of XmlDocument altogether, as I have to use it for the loading the request stream i.e.

xmlDocumentObject.Save(ResponseStream);

Thus I think its better to use the XmlDocument altogether and keep away the StringBuilder in this matter :)


Thanks for the reply.
Anup Daware

Best Regards,
Anup
&lt;Today is the first day of your rest of life.. Make most of it&gt;
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
StringBuilder welshboy2005 C# 5 October 20th, 2010 06:19 AM
String And StringBuilder - A Common Mistake Muhammad Zeeshan C# 1 November 23rd, 2007 04:12 AM
StringBuilder select statement GS C# 2005 4 August 26th, 2007 01:42 PM
Examples For String And StringBuilder jayakumar.cj ASP.NET 1.0 and 1.1 Basics 0 July 15th, 2006 07:26 AM
String vs. StringBuilder BSkelding VB.NET 2002/2003 Basics 3 June 30th, 2004 08:05 AM



All times are GMT -4. The time now is 02:06 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.