Solved

write to XML

Posted on 2004-08-08
4
296 Views
Last Modified: 2010-08-05
Hi !

i need a sample to add element or node in XML in a specific
location that i want in the xml using Xml.XmlDocument

10x's a lot
0
Comment
Question by:bwz
4 Comments
 
LVL 1

Accepted Solution

by:
Shatai earned 100 total points
ID: 11750306
It all depends on how you want to go about inserting the new node.

What you'll probably want is the InsertBefore and InsertAfter methods.  Below is the sample code from the InsertBefore method in the VB.NET help files.  This'll insert the new node (elem) as the first node in root's ChildNodes.

If you wanted to insert it as the second node, you could use either
    root.InsertAfter(elem, root.FirstNode)  ' As long as there is a FirstNode
or
   root.InsertBefore(elem, root.ChildNodes(1)  ' As long as ChildNodes.Count >=2, so that there is a ChildNodes(1)

Hope this helps.

Sample code:-
Option Strict
Option Explicit

Imports System
Imports System.IO
Imports System.Xml

Public Class Sample
   
    Public Shared Sub Main()
       
        Dim doc As New XmlDocument()
        doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" & _
                    "<title>Pride And Prejudice</title>" & _
                    "</book>")
       
        Dim root As XmlNode = doc.DocumentElement
       
        'Create a new node.
        Dim elem As XmlElement = doc.CreateElement("price")
        elem.InnerText = "19.95"
       
        'Add the node to the document.
        root.InsertBefore(elem, root.FirstChild)
       
        Console.WriteLine("Display the modified XML...")
        doc.Save(Console.Out)
    End Sub 'Main
End Class 'Sample
0
 

Author Comment

by:bwz
ID: 11750332
thank's alot ,
i'm finally used CreateDocumentFragment but its look more simple
i will try it .
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question