473,387 Members | 2,436 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.

XmlDocument Vs StringBuilder

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 Data -->
<CUSTOMERCUSTOMER _PLACEHOLDER</CUSTOMER>
<SALES_ORGSALES_ORG _ PLACEHOLDER </SALES_ORG>
<!-- Limit on the size of the search result -->
<DEFAULT_SORTINGDEFAULT_SORTING _PLACEHOLDER</DEFAULT_SORTING>
<!-- Material Data -->
<WIDTHWIDTH _HOLDER</WIDTH>
<SERIESERIE _HOLDER</SERIE>
<!-- Material List -->
<VISIBILITY_ITEM_IN>
<ITEM<!-NOTE: Number of <ITEMnodes 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

Feb 8 '07 #1
1 3514
Rule #1
Don't use stringbuilder (or concat strings together before .NET) to build
XML.
Rule #2 See Rule #1.

Look for the XmlWriter class. This is your fastest... non-string-building
way to build xml.
http://msdn.microsoft.com/library/de...ClassTopic.asp

"Anup Daware" <an*********@gmail.comwrote in message
news:11**********************@h3g2000cwc.googlegro ups.com...
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 Data -->
<CUSTOMERCUSTOMER _PLACEHOLDER</CUSTOMER>
<SALES_ORGSALES_ORG _ PLACEHOLDER </SALES_ORG>
<!-- Limit on the size of the search result -->
<DEFAULT_SORTINGDEFAULT_SORTING _PLACEHOLDER</DEFAULT_SORTING>
<!-- Material Data -->
<WIDTHWIDTH _HOLDER</WIDTH>
<SERIESERIE _HOLDER</SERIE>
<!-- Material List -->
<VISIBILITY_ITEM_IN>
<ITEM<!-NOTE: Number of <ITEMnodes 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

Feb 8 '07 #2

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

Similar topics

2
by: Jim Lewis | last post by:
After everything I have read and some of my own testing I am convinced that XPathDocument are more efficient if you are only using XML for read only and not modifying the XML. However, I have been...
3
by: TnaG | last post by:
Can someone answer this probably obvious question. I have an xmldocument that i want to apply an xslt file to. All the examples i find assume u are applying the xslt to an xml file you've read...
3
by: Gustaf Liljegren | last post by:
I think I must use MemoryStream, but whenever I search for examples of MemoryStream, I get lots byte-per-byte reading, buffers and so on. It's hard to understand and seem overkill for my case...
1
by: Waldemar FEM | last post by:
What is an easy way of making a deep copy of an XmlDocument object? Right now I'm doing something like this: XmlDocument inputDoc; XmlDocument copyDoc; ..... StringBuilder builder = new...
1
by: Philip Townsend | last post by:
I am attempting to parse through an XML document using the XmlDocument object. I keep getting a NullReferenceException. I have even tried using the fully qualified name, but with no luck. Here is...
0
by: Dan | last post by:
I have built an XSLT extension C# class where a function receives as input a text and transforms some of its charcodes into entities, e.g. A with acute accent becomes &Aacute; and so forth. The...
3
by: CodeRazor | last post by:
Hello, Simple question this one. How can I manually build a simple xmldocument in code. Lets say for example <Products> <Boat id="1"> <Price>9000</Price> </Boat>
3
by: ShayHk | last post by:
I have An XMLDocument and I want to add a new Element. I want that the element will be shaped like this : <event> <X>1</X> <Y>2</Y> </event> thanks
0
by: Anup Daware | last post by:
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....
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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.