xml writer

Yes I am using in vb visual studio 2003 xmlwriter. Is there anyway that i can just add tags instead of rewriting the xml document.  In other words I do not want to erase everything everytime i click add but just add additional elements.

Dim objXMLWriter As XmlTextWriter
        objXMLWriter = New XmlTextWriter(strXMLPath, Nothing)
        'Keep Indented to display for the human eye lol
        objXMLWriter.Formatting = Formatting.Indented
        objXMLWriter.Indentation = 3
        objXMLWriter.WriteComment("Created using an XmlTextWriter - " & Now())
        'add attributes to this element's opening tag
        objXMLWriter.WriteAttributeString("ID", "")
        objXMLWriter.WriteAttributeString("case.size", "")
        objXMLWriter.WriteAttributeString("pack", "")
        objXMLWriter.WriteAttributeString("pack.size", "")
        objXMLWriter.WriteElementString("company", "")
        objXMLWriter.WriteElementString("description", "")
        objXMLWriter.WriteElementString("unit_price", "")
        objXMLWriter.WriteElementString("case_price", "")
        objXMLWriter.WriteElementString("SRP", "")

Open in new window

Seven priceFull StackAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
You can use an XmlDocument to load the document, and then use CreateElement and AppendChild to create and add a child element to a parent element.

Seven priceFull StackAuthor Commented:
Appendchild that is the syntex I was looking for never used it before only writer can i modify the code i have above for Appendchild. And example on how that is used. thats it.
Bob LearnedCommented:
  Public Sub AppendNameToXmlDocument(ByVal fileName As String, ByVal name As String)
    Dim document As New XmlDocument()
    Dim nameElement As XmlElement = document.CreateElement("name")
    nameElement.InnerText = name
  End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Seven priceFull StackAuthor Commented:
very accurate Thanks
Seven priceFull StackAuthor Commented:
Appending to an xml file instead of creating new
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.