最近客户的一个需要,要求将数据以xml的形式发送。
vb 实现代码
PRivateFunctioncreateXML_old(ByValxmlNameAsString)AsBoolean
Dim SrcPath As String = "c\project\srcXmlFiles\" '产生的xml存放的目录
TryDimwriterAsNewSystem.Xml.XmlTextWriter(SrcPath &xmlName, System.Text.Encoding.UTF8)DimnamespaceUrlAsString="http://www.xxx.com" '验证xsd需要用到的namespaceUrlwriter.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)DimdvAsDataView =cn.getData.DefaultView()Ifdv.Count >0ThenForEachitemAsDataRowViewIndv
writer.WriteStartElement("firstNode7")
writer.WriteElementString("secondNode1", values)
writer.WriteElementString("secondNode2", values)
writer.WriteElementString("secondNode3", values)Dimdv2AsDataView = cn.getData2(item("firstNode6Id")).DefaultView()Ifdv2.Count >0ThenForEachitemRMDetailsAsDataRowViewIndvRMDetails
writer.WriteStartElement("secondNode4")
writer.WriteStartElement("thridNode1")
writer.WriteElementString("thridNode2", values)writer.WriteEndElement()'关闭secondNode4writer.WriteEndElement()'关闭thridNode1NextElsewriter.WriteStartElement("secondNode4")
writer.WriteStartElement("thridNode1")
writer.WriteElementString("thridNode2","")
writer.WriteEndElement()'关闭secondNode4writer.WriteEndElement()'关闭thridNode1EndIfwriter.WriteEndElement()'关闭firstNode7Next
Else
'WriteLog FunctionEndIfwriter.WriteEndElement()
writer.WriteEndDocument()'writer.Close()'将XML写入文件并关闭writerReturnTrueCatchexAsExceptionReturnFalseEndTryEnd Function