473,320 Members | 1,990 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,320 software developers and data experts.

Avoiding the use of XmlDocument

I have an application which sends messages to an external application. All data is submitted as a string in an Xml format specified by the other application, along with some custom elements we have added to assist in trouble shooting. The format is below

<AppName><Data><![CDATA[our data goes here]]></Data><CustomField1>field 1 data here</CustomField1><CustomField2>field 2 data here</CustomField2></AppName

Currently this Xml is being created dynamically each time a message is being sent, using an XmlTextWriter. What I would like to do is define the skeleton Xml once (when our component is first initialised), and simply set the element values and send this

I can see that I could do this with an XmlDocument, perhaps loading it from an Xml file when initialised, and then working on a Clone of the doc, and setting the value of each node by calling SelectSingleNode for each

In some simple tests, the above is very slow. Does anyone have a better solution

Thanks for your hel
Dan
Nov 12 '05 #1
3 1520
Dan Kelley wrote:
Currently this Xml is being created dynamically each time a message
is being sent, using an XmlTextWriter. What I would like to do is
define the skeleton Xml once (when our component is first
initialised), and simply set the element values and send this.


You can create a class (either by hands or using xsd.exe) and serialize
object of this class with values set using XmlSerializer instead.

--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com
Nov 12 '05 #2
Although xml serialization is the approach I take for all my business
objects, I sometimes use simple string substitution as I have seen done by
some applications also. I guess it depends on your requirement but if your
xml - assuming *string* - to be sent is not too big and you could just use
String.Format.

I usually don't do this for "objects" but for "formatted messages" where the
format is usually static and don't really require a lot of my classes to
manipulate during the course of processing. Usually one method takes an
object or some values and fills in the blanks for the message and sent.

Oleg,
do you see any issues with this kind of approach?

"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:uX**************@TK2MSFTNGP09.phx.gbl...
Dan Kelley wrote:
Currently this Xml is being created dynamically each time a message
is being sent, using an XmlTextWriter. What I would like to do is
define the skeleton Xml once (when our component is first
initialised), and simply set the element values and send this.


You can create a class (either by hands or using xsd.exe) and serialize
object of this class with values set using XmlSerializer instead.

--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com

Nov 12 '05 #3
Jiho Han wrote:
Although xml serialization is the approach I take for all my business
objects, I sometimes use simple string substitution as I have seen done by
some applications also. I guess it depends on your requirement but if your
xml - assuming *string* - to be sent is not too big and you could just use
String.Format.

I usually don't do this for "objects" but for "formatted messages" where the
format is usually static and don't really require a lot of my classes to
manipulate during the course of processing. Usually one method takes an
object or some values and fills in the blanks for the message and sent.

Oleg,
do you see any issues with this kind of approach?


Well, the only issue with working with XML as with string is XML syntax
issue. It's a way easy to build a string, which isn't well-formed XML.
XML API, such as XmlDocument or XmlWriter help here a lot, so when
whoever doing this by hands (I mean not using XML API) should take care
of XML syntax details, such as escaping of < and & (CDATA helps here),
characters not allowed in XML, encoding etc. No big deal actually, but a
bit fragile stuff. You are right, it depends on requirements and
sometimes (usually simple cases) String.Format is just fine, sometimes -
not.
--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com
Nov 12 '05 #4

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

Similar topics

6
by: kermit | last post by:
I asp.net pages that run on an intranet IIS server. Some op the pages use XLM DOM doc.Load(sPath) to open and parse a XML file. Every time the doc.Load(sPath) executes in IE6 a warning message...
1
by: Martin Honnen | last post by:
With both .NET 1.0 and 1.1 I have found the following strange behaviour where System.Xml.XmlDocument.LoadXml doesn't throw an error when parsing a text node with a character reference to an invalid...
4
by: Robert Rossney | last post by:
I'm trying to send and receive XmlDocument objects using the System.Messaging.dll functions. The code I've written follows, as best I can tell, the methodology used in the sample code for the...
2
by: Graham Pengelly | last post by:
Hi I am trying to transform on System.Xml.XmlDocument into another using XslTransform without writing the object out to a file. I am guessing it should work something like this... public...
2
by: Dave | last post by:
Hi, Is there an easier way to pull a subset of nodes from one XmlDocument to another? I have the code below but would like to know if there is a more streamlined method. Thanks, Dave ...
8
by: pete | last post by:
Hi there, Can someone explain to me why I can't bind to an XmlDocument but I can bind to an XmlNodeList. It's my understanding that they both implement the IEnumerable interface which is...
1
by: Peter Nofelt | last post by:
Hey All, I'm running into this issue with parsing through an xml document by tag name. Below is an example xml document: File Name: things.xml <things> <people> <name>Peter</name>
5
by: Rob Panosh | last post by:
Hello, I am trying to create a xmlDocument from as dataset. My code is listed below. All seems to go well until xmlDocument.Load(CType(ms, System.IO.Stream)) ... I keep getting the following...
2
by: John Smith | last post by:
I'm writing webervice client using .Net 2.0. I have this class: public class MyWebService : SoapHttpClientProtocol { public XmlDocument validate(string url, XmlDocument xmlDocument) {...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.