`
newand
  • 浏览: 36646 次
  • 性别: Icon_minigender_1
  • 来自: nj
最近访客 更多访客>>
社区版块
存档分类
最新评论

写xml文件的方法(vb.net)

    博客分类:
  • .net
阅读更多

一:XmlWriter的形式

 

Dim myXmlSettings As New XmlWriterSettings
        myXmlSettings.Indent = True
        myXmlSettings.NewLineOnAttributes = True

        Using ProductWriter As XmlWriter = XmlWriter.Create("path\XMLFile2.xml", myXmlSettings)

            ProductWriter.WriteComment("product product ")
            ProductWriter.WriteStartElement("All")
            ProductWriter.WriteStartElement("Product")
            ProductWriter.WriteAttributeString("Id", "101")
            ProductWriter.WriteAttributeString("COunt", "10")
            ProductWriter.WriteElementString("P1", "P2")
            ProductWriter.WriteEndElement()

            ProductWriter.WriteStartElement("Product")
            ProductWriter.WriteAttributeString("Id", "102")
            ProductWriter.WriteAttributeString("COunt", "10")
            ProductWriter.WriteElementString("P1", "P2")
            ProductWriter.WriteEndElement()

            ProductWriter.WriteStartElement("Product")
            ProductWriter.WriteAttributeString("Id", "103")
            ProductWriter.WriteAttributeString("COunt", "10")
            ProductWriter.WriteElementString("P1", "P2")
            ProductWriter.WriteEndElement ()
            ProductWriter.WriteEndElement()
        End Using

 二:XmlDocument的形式

 

 

Dim Doc As New XmlDocument()
 Dim dec As XmlDeclaration = Doc.CreateXmlDeclaration("1.0", _
                                         Nothing, Nothing)
        Doc.AppendChild(dec)
        Dim DocRoot As XmlElement = Doc.CreateElement("Orders")
        Doc.AppendChild(DocRoot)

        Dim Order As XmlNode = Doc.CreateElement("Order")
        newAtt = Doc.CreateAttribute("Quantity")

        newAtt.Value = "100"
        Order.Attributes.Append(newAtt)
        DocRoot.AppendChild(Order)
Doc.Save("path\XMLFile2.xml") 

 

 

 

 

 

 

 

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics