By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,190 Members | 1,412 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,190 IT Pros & Developers. It's quick & easy.

Appending XML

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.