码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-08-26 13:45:06      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

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

 

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

标签:

原文地址:http://www.cnblogs.com/zzglyl/p/4760066.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!