Hullo.

I need some help with this one. Ok, I want to create an xml file of all my mp3 files on my home pc.:S

I am using the code as follows:-

Public Class Form1
  Dim myWriter As New System.Xml.XmlTextWriter
 
  myWriter = New System.Xml.XmlTextWriter("C:\music_stuff.xml", Nothing)
 
 With myWriter
      .Indentation = 4
      .IndentChar = " "
      .Formatting = . Indentation
 
      .WriteStartDocument()
      .WriteComment ("my freaking music yay")
 
      .WriteStartElement("mp3")
      .WriteElementString("id","1")
      .WriteElementString("title","blah blah")
      .WriteElementString("description", "wah wah wah")
      .WriteEndElement()
 
       .WriteEndDocument()
 End With
 myWriter.Flush()
 myWriter.Close()
End Class

It gives output something like:-

<?xml version="1.0" ?>
  <!-- my freaking music yay -->
  <mp3>
     <id>1</id>
     <title>blah</title>
     <description>wah wah wah</description>
   </mp3>

And that just works fine for one record, but I want to append to this one file all my mp3s. But I just don't know how to append, well I have an idea but it is long winded. What's gonna be the best way?

Hmm...I don't remember if there is a specific way to do it with the code and the objects themselves.

But, in theory, could you read whatever is in the document into a variable, then create the new data and then write it all back in one huge chunk at the end?

I was googling before and came across that same link. But it didn't really help me. I didn't think appending an xml file would be so hard.

Argh, I might even have to write my own api.

This article has been dead for over six months. Start a new discussion instead.