声明XmlTextWriter [英] Declaring a XmlTextWriter

查看:94
本文介绍了声明XmlTextWriter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我已经将一个Xml文件加载为名为myPlayersDOM的DOM。我现在想要在Xml文件中添加一个新的播放器。我已经使用了这段代码。

 私有  Sub  Players_List_Update(curComboItem  As   String ,curTeleNo  As  字符串
MsgBox( 添加播放器
Dim newPlayer As Xml.XmlElement = myPlayersDOM。 CreateElement( Player
Dim newName As Xml.XmlElement = myPlayersDOM.CreateElement( 名称
newName.InnerText = curComboItem
newPlayer.AppendChild(newName)
Dim NewTele As Xml.XmlElement = myPlayersDOM.CreateElement( TeleNo
NewTele.InnerText = curTeleNo
newPlayer.AppendChild(NewTele)
myPlayersDOM.DocumentElement.AppendChild(newPlayer)
< span class =code-keyword> Dim tr As XmlTextWriter = XmlTextWriter(< span class =code-string> D:\我在D \ Visual Studio项目上的文档\Match Management Application \Players.xml Nothing
tr.Formatting = Xml.Formatting.Indented
myPlayersDOM.WriteContentTo(tr)
tr.Close( )
结束 Sub



但是当我尝试定义'tr'

Type时会出现此错误XmlTextWriter未定义。

任何人都可以提供帮助。

PS不知道代码是否真的有效。



谢谢Dave

解决方案

XmlTextWriter [ ^ ]在 System.Xml 命名空间中定义。你导入了吗?更准确地说,你有一个

  Imports  System.Xml 

附近.vb文件的顶部?



如果您不想导入此命名空间,则必须使用该类的完全限定名称来使用它:

  Dim  tr  As  System.Xml.XmlTextWriter =  System.Xml.XmlTextWriter(  D:\\ \\我在D \ Visual Studio项目上的文档\Match Management Application \Players.xml Nothing 


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.

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

解决方案

XmlTextWriter[^] is defined in System.Xml namespace. Did you import it? More precisely, do you have a

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:

Dim tr As System.Xml.XmlTextWriter = New System.Xml.XmlTextWriter("D:\My Documents on D\Visual Studio Projects\Match Management Application\Players.xml", Nothing)


这篇关于声明XmlTextWriter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆