472,801 Members | 1,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,801 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 1509
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
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.