|
-
Jun 2nd, 2006, 07:31 AM
#1
Thread Starter
Fanatic Member
[2005] Adding data to an already existing XML file?
I am having some trouble working with XML files. I have some code that checks if the XML file exists and if not, creates it. If it does exist, it simply loads it. That works fine. Here's the code for that
If Not System.IO.File.Exists("C:\temp\test.xml") Then
'XMLDoc = New XmlDocument()
Dim XMLDeclaration As XmlDeclaration = XMLDoc.CreateXmlDeclaration("1.0", "utf-8", "")
Dim XMLRootNode As XmlElement = XMLDoc.CreateElement("CDLIST")
XMLDoc.InsertBefore(XMLDeclaration, XMLDoc.DocumentElement)
XMLDoc.AppendChild(XMLRootNode)
XMLDoc.Save("C:\temp\test.xml")
Else
XMLDoc.Load("C:\temp\test.xml")
End If
Now, what I want it do is add a section that looks like this
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</CD>
This code sort of works but doesn't really What am I doing wrong?
Dim ParentNode As XmlElement = XMLDoc.DocumentElement.PrependChild(XMLDoc.CreateElement("TEST"))
ParentNode.AppendChild(XMLDoc.CreateElement("Owner"))
ParentNode.AppendChild(XMLDoc.CreateTextNode("asdasd"))
ParentNode.AppendChild(XMLDoc.CreateElement("type"))
ParentNode.AppendChild(XMLDoc.CreateTextNode("123213"))
ParentNode.AppendChild(XMLDoc.CreateElement("test"))
ParentNode.AppendChild(XMLDoc.CreateTextNode("kouewo"))
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|