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

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.InnerXML = "<Level1></Level1>"
SelectSingleNode("/Level0").AppendChild(docFrag)

docFrag.InnerXML = "<Level2a></Level2a><Level2b></Level2b>" etc
SelectSingleNode(...) 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 4954
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.sourceforge.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_PLEASEtkachenko.com> wrote in message
news:ef**************@TK2MSFTNGP12.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_PLEASEtkachenko.com> wrote in
news:ef**************@TK2MSFTNGP12.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
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){ ...
3
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...
4
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
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...
5
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...
1
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...
3
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...
4
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...
1
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
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...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
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...
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.