Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All
I have loaded an Xml file as a DOM called myPlayersDOM. I now want to add a new player to the Xml file. I have used this code.
VB
Private Sub Players_List_Update(curComboItem As String, curTeleNo As String)
        MsgBox("Adding Player to file")
        Dim newPlayer As Xml.XmlElement = myPlayersDOM.CreateElement("Player")
        Dim newName As Xml.XmlElement = myPlayersDOM.CreateElement("Name")
        newName.InnerText = curComboItem
        newPlayer.AppendChild(newName)
        Dim NewTele As Xml.XmlElement = myPlayersDOM.CreateElement("TeleNo")
        NewTele.InnerText = curTeleNo
        newPlayer.AppendChild(NewTele)
        myPlayersDOM.DocumentElement.AppendChild(newPlayer)
        Dim tr As XmlTextWriter = New XmlTextWriter("D:\My Documents on D\Visual Studio Projects\Match Management Application\Players.xml", Nothing)
        tr.Formatting = Xml.Formatting.Indented
        myPlayersDOM.WriteContentTo(tr)
        tr.Close()
    End Sub

But get this error when I try to defined 'tr'
Type 'XmlTextWriter' is not defined.
Can anyone help.
PS do not know if the code will actually work.

Thanks Dave
Posted
Updated 7-Mar-15 12:52pm
v2

1 solution

XmlTextWriter[^] is defined in System.Xml namespace. Did you import it? More precisely, do you have a
VB
Imports System.Xml
near the top of your .vb file?

If you do not want to import this namespace, you have to use the fully qualified name of the class to use it:
VB
Dim tr As System.Xml.XmlTextWriter = New System.Xml.XmlTextWriter("D:\My Documents on D\Visual Studio Projects\Match Management Application\Players.xml", Nothing)
 
Share this answer
 
Comments
Dave the Golfer 8-Mar-15 3:28am    
phil.o

Thanks
I am very new to this. I have added Imports System.Xml above the form class and all works okay.

Again thank you very much

Dave
phil.o 8-Mar-15 6:06am    
You're welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900