VB 生成xml文件 并使用xsd验证

2018-06-18 02:35:54来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

最近客户的一个需要,要求将数据以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

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:.Net 项目代码风格规范

下一篇:开始让自己习惯写文章