Dim ds As New DataSet
Dim strurl As String = Server.MapPath(”mod1.xml”)
ds.ReadXml(strurl)
Dim Writer As New XmlTextWriter(Server.MapPath(”mod3.xml”), System.Text.Encoding.UTF8)
Writer.Formatting = System.Xml.Formatting.Indented
Writer.Indentation = 4 // 這個比較重要,這個屬性說明xml文件裡面的內容是按級別縮進的。
//下面開始生成文件的內容
Writer.WriteStartDocument() //開始寫xml,在最後有一個與之匹配的
Writer.WriteStartElement(”MapDefinition”)//生成一個節點
Writer.WriteAttributeString(”xmlns:xsi”, “http://www.w3.org/2001/XMLSchema-instance“) //MapDefinition節點的屬性
Writer.WriteAttributeString(”xmlns:xsd”, “http://www.w3.org/2001/XMLSchema“)
Writer.WriteAttributeString(”xsi:noNamespaceSchemaLocation”, “MapDefinition-1.0.0.xsd”)
For Each dr1 As DataRow In ds.Tables(0).Rows
Writer.WriteStartElement(”Name”)//節點的開始
Writer.WriteString(dr1(”Name”).ToString)//節點的內容
Writer.WriteEndElement()//關閉節點
Writer.WriteStartElement(”CoordinateSystem”)
Writer.WriteString(dr1(”CoordinateSystem”).ToString)
Writer.WriteEndElement()
Next
Writer.WriteStartElement(”Extents”)
For Each dr1 As DataRow In ds.Tables(1).Rows
Writer.WriteStartElement(”MinX”)
Writer.WriteString(dr1(”MinX”).ToString)
Writer.WriteEndElement()
Writer.WriteStartElement(”MaxX”)
Writer.WriteString(dr1(”MaxX”).ToString)
Writer.WriteEndElement()
Writer.WriteStartElement(”MinY”)
Writer.WriteString(dr1(”MinY”).ToString)
Writer.WriteEndElement()
Writer.WriteStartElement(”MaxY”)
Writer.WriteString(dr1(”MaxY”).ToString)
Writer.WriteEndElement()
Next
Writer.WriteEndElement()
Writer.WriteStartElement(”BackgroundColor”)
Writer.WriteString(”ffc0d5ff”)
Writer.WriteEndElement()
Writer.WriteEndElement()
Writer.Flush()
Writer.Close()//完成xml文件的輸出,關閉
ds.Dispose()
留言列表