你的位置:首页 > ASP.net教程

[ASP.net教程]VB 生成xml文件 并使用xsd验证

最近客户的一个需要,要求将数据以

vb 实现代码

Private Function createByVal As String) As Boolean
    Dim SrcPath As String = "c\project\src Try Dim writer As New System. 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() '将 Return True Catch ex As Exception Return False End Try End Function