How to change an xml file elements attributes in vb.net

后端 未结 2 839
慢半拍i
慢半拍i 2021-01-28 04:45

Hi I have a class Booking that stores booking information, I have to have BOOKING to look like this



        
2条回答
  •  清歌不尽
    2021-01-28 05:33

          Dim swLineItem As New IO.StringWriter()
            Dim xmlWriter As New System.Xml.XmlTextWriter(swLineItem)
    
     xmlWriter.WriteStartDocument()
       xmlWriter.WriteStartElement("YourOuterMostElement")
         xmlWriter.WriteStartElement("Booking") 
           xmlWriter.WriteAttributeString("partner", "CompanyName")
           xmlWriter.WriteAttributeString("transaction", "BOOKING")
           xmlWriter.WriteAttributeString("version", "1.0")
    
         xmlWriter.WriteEndElement()
        xmlWriter.WriteEndElement()
     xmlWriter.WriteEndDocument() 
    

提交回复
热议问题