Foxtable(狐表)用户栏目专家坐堂 → XML


  共有2347人关注过本帖树形打印复制链接

主题:XML

帅哥哟,离线,有人找我吗?
bagabaga
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:138 积分:1325 威望:0 精华:0 注册:2014/3/10 19:43:00
XML  发帖心情 Post By:2014/7/30 21:59:00 [只看该作者]

请教以下代码:
        Dim doc As New System.XML.XmlDocument()
        doc.LoadXml("<book xmlns:bk='urn:samples' bk:ISBN='1-861001-57-5'>" & _
                    "<title>Pride And Prejudice</title>" & _
                    "</book>")

        Dim root As System.XML.XmlNode = doc.FirstChild

        'Create a new attribute.
        Dim ns As String = root.GetNamespaceOfPrefix("bk")
        Dim attr As System.XML.XmlNode = doc.CreateNode(System.XML.XmlNodeType.Attribute, "genre", ns)
        attr.Value = "novel"

        'Add the attribute to the document.
        root.Attributes.SetNamedItem(attr)

        ' Save the document to a file and auto-indent the output.
          Dim writer As New System.XML.XmlTextWriter = new.System.XML.XmlTextWriter("d:\桌面\data.xml",Nothing)
          writer.Formatting = Formatting.Indented
          doc.Save(writer)

最后写入怎么做?


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/7/30 22:10:00 [只看该作者]

Dim doc As New System.XML.XmlDocument()
doc.LoadXml("<book xmlns:bk='urn:samples' bk:ISBN='1-861001-57-5'>" & _
"<title>Pride And Prejudice</title>" & _
"</book>")


Dim root As System.XML.XmlNode = doc.FirstChild


'Create a new attribute.
Dim ns As String = root.GetNamespaceOfPrefix("bk")
Dim attr As System.XML.XmlNode = doc.CreateNode(System.XML.XmlNodeType.Attribute, "genre", ns)
attr.Value = "novel"


'Add the attribute to the document.
root.Attributes.SetNamedItem(attr)


' Save the document to a file and auto-indent the output.
Dim stream As new System.Io.FileStream("d:\aaa.xml", System.Io.FileMode.OpenOrCreate, System.Io.FileAccess.Write)
doc.Save(stream)
stream.Close()


 回到顶部