|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Append to XML?Hi,
I use VS 2005. How would I append XML elements to the end of an existing XML file programmatically? "Amjad" <Am***@discussions.microsoft.com> schrieb: Take a look at the 'XmlDocument' class and other classes in the 'System.Xml' > I use VS 2005. > How would I append XML elements to the end of an existing XML file > programmatically? namespace. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> "Amjad" <Am***@discussions.microsoft.com> wrote in message Assume you have the following xml document in a file named Tree.xml:news:B420CE51-C814-488D-914A-817C0DC541CF@microsoft.com... : : Hi, : : I use VS 2005. : How would I append XML elements to the end of an existing XML file : programmatically? <Root> <Branch> <Leaf/> <Leaf/> </Branch> <Branch> <Leaf/> </Branch> </Root> And let's assume you want to add a <Graft /> node to this tree so that the end result looks like this: <Root> <Branch> <Leaf/> <Leaf/> </Branch> <Branch> <Leaf/> </Branch> <Graft/> </Root> Here is one approach you can take: Imports System.XML '... Dim TreeXml As XMLDocument Dim graftNode As XMLNode TreeXml = New XMLDocument TreeXml.Load("Tree.xml") graftNode = TreeXml.CreateElement("Graft") TreeXml.selectSingleNode("/Root").AppendChild(graftNode) Console.WriteLine(TreeXml.InnerXMl) This will generate the following output: <Root> <Branch> <Leaf /> <Leaf /> </Branch> <Branch> <Leaf /> </Branch> <Graft /> </Root> HTH Ralf -- -- ---------------------------------------------------------- * ^~^ ^~^ * * _ {~ ~} {~ ~} _ * * /_``>*< >*<''_\ * * (\--_)++) (++(_--/) * ---------------------------------------------------------- There are no advanced students in Aikido - there are only competent beginners. There are no advanced techniques - only the correct application of basic principles.
Display the contents of a folder in a listbox?
How do I extract a page from word and insert into a new word document using VB OFF TOPIC: Famous failed IT projects Webbrowser & XML Reading dll-Functions and execute them how to kill a thread Enter key vs Return key Question on VB.Net security for the application to run on network drive Comm Ports Code for Convert RTF Text to HTML |
|||||||||||||||||||||||