473,799 Members | 3,185 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Appending XML

I know this question has been asked several times over. For some reason I
cannot get it to sink in.

I would like to create a xml document fragment (<--I think that's what I
want, tell me if I'm wrong) that "looks" like this:

<Level1 att=? att2=? att3=?>
<Level2a>
<Level3a/>
<Level3b/>
</Level2a>
<Level2b>
<Level3a/>
<Level3b/>
</Level2b>
<Level2c>
<Level3a/>
<Level3b/>
</Level2c>
</Level1>

Then I append the above to an existing file, of course.

Now, the only way I've figured out how to do this is to...

Dim xmlDoc as new XMLDocument(), etc

docFrag.InnerXM L = "<Level1></Level1>"
SelectSingleNod e("/Level0").Append Child(docFrag)

docFrag.InnerXM L = "<Level2a></Level2a><Level2 b></Level2b>" etc
SelectSingleNod e(...) you get the idea.
This seems like a terrible waste of effort, not to mention just an ugly way
to go about things. Is there anyway to build that tree without all that
"manual" effort?

Thanks for your help.

ArmsTom
Nov 11 '05 #1
3 5011
ArmsTom wrote:
This seems like a terrible waste of effort, not to mention just an ugly way
to go about things. Is there anyway to build that tree without all that
"manual" effort?

Generally speaking XML document cannot be updated without parsing the whole
document to find the right place to insert new portion or some ugly hacks.
An appendable alternative is using XML fragment:
<root1/>
<root2/>
Above is not XML document, it's XML fragment. It can be apended easily without
any parsing - just write elements to the end of the file. Then this XML
fragment could be parsed using XmlTextReader or can be incorporated to another
XML document using entity.
See "Log file in XML format?" at
http://www.tkachenko.com/blog/archives/000053.html for more info.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2
I can see you're manually creating the hierarchy. In cases like this one,
you're better off using XmlTextWriter, IMO.
It's faster and FAR less resource intensive. If you happen to need to load
the document, you can do so later.

--
.../d:cazz
Daniel Cazzulino
DEVerest - Lagash
Tel +54 (0) 11 4247 7396
www.deverest.com.ar
www.lagash.com
dotnetopensrc.s ourceforge.net

Coauthor of:
Beginning C# Web Applications with Visual Studio .NET
Beginning Web Programming using VB.NET and Visual Studio .NET
Professional ASP.NET Server Controls: Building Custom Controls with C#
ASP.NET Components Toolkit

"He who is good for making excuses, is seldom good for anything else."

"Oleg Tkachenko" <oleg@NO_SPAM_P LEASEtkachenko. com> wrote in message
news:ef******** ******@TK2MSFTN GP12.phx.gbl...
ArmsTom wrote:
This seems like a terrible waste of effort, not to mention just an ugly way to go about things. Is there anyway to build that tree without all that
"manual" effort? Generally speaking XML document cannot be updated without parsing the

whole document to find the right place to insert new portion or some ugly hacks.
An appendable alternative is using XML fragment:
<root1/>
<root2/>
Above is not XML document, it's XML fragment. It can be apended easily without any parsing - just write elements to the end of the file. Then this XML
fragment could be parsed using XmlTextReader or can be incorporated to another XML document using entity.
See "Log file in XML format?" at
http://www.tkachenko.com/blog/archives/000053.html for more info.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #3
Thanks a lot for responding. I've played around with XmlTextWriter and
it seems to be what I want. Hopefully, it'll work out for me. :)

ArmsTom

Oleg Tkachenko <oleg@NO_SPAM_P LEASEtkachenko. com> wrote in
news:ef******** ******@TK2MSFTN GP12.phx.gbl:
ArmsTom wrote:
This seems like a terrible waste of effort, not to mention just an
ugly way to go about things. Is there anyway to build that tree
without all that "manual" effort?

Generally speaking XML document cannot be updated without parsing the
whole document to find the right place to insert new portion or some
ugly hacks. An appendable alternative is using XML fragment:
<root1/>
<root2/>
Above is not XML document, it's XML fragment. It can be apended easily
without any parsing - just write elements to the end of the file. Then
this XML fragment could be parsed using XmlTextReader or can be
incorporated to another XML document using entity.
See "Log file in XML format?" at
http://www.tkachenko.com/blog/archives/000053.html for more info.


Nov 11 '05 #4

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

Similar topics

4
59617
by: Bharat Bhushan | last post by:
Hi, I need to generate random bytes for x number of times and keep appending it to a bigger byte array. How can I do this ? for (int lctr=0; lctr < main.Main.NoOfattributes(); lctr=lctr+1){ // This line below generates the random bits for a given length byte intervals = RandomFunctions.makeRandomGeneBits(length);
3
2272
by: ketulp_baroda | last post by:
Hi I am having a problem in appending to sys.path I am doing it this way: >>> sys.path >>> sys.path.append(r'D:\Python23\Lib\site-packages\code') >>> sys.path But when I close the shell and now again open it & do sys.path , it
4
3212
by: bucket79 | last post by:
Hi is there anyway appending to dictionary? list has this feature >>>a = >>>a.append(1) >>>print a but dictionary can't
1
3254
by: Thomas Heller | last post by:
I want to append/insert additional data to an xml file. Context: I use gccxml to parse C header files. gccxml creates an xml file containing all the definitions from the header files. The xml files may be somewhat largish, for 'windows.h' it has more than 5 MB. Since the xml does not contain #define statements, I want to run gccxml again with the --preprocess and -dM flags, which dumps out the #define'd symbols.
5
1892
by: rbt | last post by:
I know how to setup an empty list and loop thru something... appending to the list on each loop... how does this work with dicts? I'm looping thru a list of files and I want to put the file's name and its sha hash into a dict on each loop. Many thanks, rbt
1
2121
by: dmiller23462 | last post by:
Hey guys.... I put an error-handling in my page and have it posted at the complete end of the code, see below(when people were putting in 's I was getting the delimiter errors). Great, I understand that now and it seems to be fixed but the data I'm pulling from the HTML fields is not being appended correctly do my Access DB....The field in the DB now reads " ' ". I understand why it does that (my function) but what I need it to read is...
3
1933
by: MLH | last post by:
I have a query, qryAppend30DayOld260ies that attempts to append records to tblCorrespondence. When run, it can result in any of the following: appending no records, appending 1 record or appending many records. Two of the target fields in tblCorrespondence receiving values in the append operation are and . For any given VehicleJobID value, I want only ONE record in correspondence table to have an value of "01". This query blindly appends...
4
1671
by: John A Grandy | last post by:
could someone explain the following to me : Appending the literal type character I to a literal forces it to the Integer data type. Appending the identifier type character % to any identifier forces it to Integer.
1
3967
by: Frank | last post by:
Hi, Let's say I have a file named myFile.xml Within that file I have blocks of data which I'd like to add at different times during the day. e.g. <LogEntry>
2
1513
by: sarada purkait | last post by:
hii i have to write into a file from the start and then go on appending to it .. i tried using ( ios::out|ios::app) but by this the file keeps on appending every time i run the program and the file ends up containing valuers from the previous runs as well... actually i am using a loop , which generates different values which are to be added to the file . can some1 help me with this i am fairly new to c++
0
9685
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
10247
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...
0
10023
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
9067
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
6803
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5459
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5583
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2935
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.