473,799 Members | 2,723 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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><CustomFie ld1>field 1 data here</CustomField1><C ustomField2>fie ld 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 SelectSingleNod e 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 1543
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!P LEASEtkachenko. com> wrote in message
news:uX******** ******@TK2MSFTN GP09.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
3090
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 comes up "This page is accessing information that is not under it's control. . . " How can I avoid this message. It is a great anoyance to the users. Do I need to create some time of certificate to pass... Help! Need direction.
1
17140
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 characters like &#x1;. Using the CreateTextNode method I create a text node containing "\u0001a" (C# string literal notation). As far as I understand the DOM allows that and an implementation is not required to throw an error. When OuterXml is...
4
4848
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 XmlMessageFormatter class. But it isn't working -- specifically, receiving isn't working. What am I doing wrong here? I begin by creating a MessageQueue object and setting up its XmlMessageFormatter to handle XmlDocument objects: System.Type...
2
6044
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 XmlDocument TransformXmlDoc(XmlDocument docToTransform, string xsltFilePath) { //load the xslt
2
6211
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 XmlNodeList nodeList = doc1.SelectNodes("//row"); foreach (XmlNode nodeCode in nodeList) { sb.Append(nodeCode.OuterXml);
8
6166
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 required for databinding. Am happy to work with the XmlNodeList but I can't shake the feeling I'm missing something <blush> Thanks, Pete
1
9699
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
10166
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 error "The Root Element is Missing" ... any help would be appreciated. Thanks, Rob Panosh
2
13597
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) { this.Url = url;
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9543
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10488
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10257
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10237
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10029
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9077
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5588
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4144
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.