最近客户的一个需要,要求将数据以xml的形式发送。
vb 实现代码
PRivate Function createXML_old(ByVal xmlName As String) As Boolean
Dim SrcPath As String = "c/project/srcXmlFiles/" '产生的xml存放的目录
Try Dim writer As New System.Xml.XmlTextWriter(SrcPath & xmlName, System.Text.Encoding.UTF8) Dim namespaceUrl As String = "http://www.xxx.com" '验证xsd需要用到的namespaceUrl writer.Formatting = Formatting.Indented writer.WriteStartDocument() writer.WriteStartElement("root", "test", namespaceUrl) writer.WriteElementString("firstNode1", "values") writer.WriteElementString("firstNode2", "values") writer.WriteElementString("firstNode3", "values") writer.WriteElementString("firstNode4", "values) writer.WriteElementString("firstNode5", values) writer.WriteElementString("firstNode6Id", values) Dim dv As DataView = cn.getData.DefaultView() If dv.Count > 0 Then For Each item As DataRowView In dv writer.WriteStartElement("firstNode7") writer.WriteElementString("secondNode1", values) writer.WriteElementString("secondNode2", values) writer.WriteElementString("secondNode3", values) Dim dv2 As DataView = cn.getData2(item("firstNode6Id")).DefaultView() If dv2.Count > 0 Then For Each itemRMDetails As DataRowView In dvRMDetails writer.WriteStartElement("secondNode4") writer.WriteStartElement("thridNode1") writer.WriteElementString("thridNode2", values) writer.WriteEndElement() '关闭secondNode4 writer.WriteEndElement() '关闭thridNode1 Next Else writer.WriteStartElement("secondNode4") writer.WriteStartElement("thridNode1") writer.WriteElementString("thridNode2", "") writer.WriteEndElement() '关闭secondNode4 writer.WriteEndElement() '关闭thridNode1 End If writer.WriteEndElement() '关闭firstNode7 Next
Else
'WriteLog Function End If writer.WriteEndElement() writer.WriteEndDocument() ' writer.Close() '将XML写入文件并关闭writer Return True Catch ex As Exception Return False End Try End Function
新闻热点
疑难解答