以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 求助:生成xml文件怎样才能在每一个要素之后都加上一个vbcrlf实现回车 空行呢? (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=92114) |
-- 作者:李孝春 -- 发布时间:2016/10/26 13:49:00 -- 求助:生成xml文件怎样才能在每一个要素之后都加上一个vbcrlf实现回车 空行呢? 求助:生成xml文件怎样才能在每一个要素之后都加上一个vbcrlf实现回车 空行呢? 代码如下: Dim xls As String = "D:/收案信息.xls" Dim book As new XLS.Book(xls) Dim sheet As XLS.Sheet= book.Sheets(0) Dim xml As String = "D:/收案信息.xml" Try Dim writer As New Xml.XmlTextWriter(xml, System.Text.Encoding.GetEncoding("utf-8")) \'书写根元素() writer.WriteStartElement("case") For i As Integer = 1 To sheet.Rows.count -1 \'添加次级元素 writer.WriteStartElement("caseRegistration") For j As Integer = 0 To sheet.Cols.count -1 \'添加子元素() writer.WriteElementString(sheet(0,j).value,sheet(i,j).value) Next \'关闭次级元素DatabaseSetting writer.WriteEndElement() Next \'关闭根元素 writer.WriteFullEndElement() \'将XML写入文件并关闭writer writer.Close() Catch ex As Exception MsgBox(ex.Message & vbCrLf & ex.StackTrace) End Try 生成后的效果为: <case><caseRegistration><suitDocNumber>1</suitDocNumber><number1>221</number1><name1>22</name1><submittedDate>2016/10/26</submittedDate><number>222</number><name>22</name><suggestedProcedure>普通程序</suggestedProcedure><penalty>死刑</penalty><minDuration>2</minDuration><maxDuration>2</maxDuration><involvedAmount>2</involvedAmount><isTeen>1</isTeen><description>222</description><path>2222</path></caseRegistration></case> 怎么样才能实现为下面的格式呢? <case> <caseRegistration> <suitDocNumber>1</suitDocNumber> <number1>221</number1> <name1>22</name1> <submittedDate>2016/10/26</submittedDate> <number>222</number> <name>22</name> <suggestedProcedure>普通程序</suggestedProcedure> <penalty>死刑</penalty> <minDuration>2</minDuration> <maxDuration>2</maxDuration> <involvedAmount>2</involvedAmount> <isTeen>1</isTeen> <description>222</description> <path>2222</path> </caseRegistration> </case> [此贴子已经被作者于2016/10/26 13:50:01编辑过]
|
-- 作者:blackzhu -- 发布时间:2016/10/26 13:52:00 -- writer.Formatting = Xml.Formatting.Indented |
-- 作者:李孝春 -- 发布时间:2016/10/26 14:49:00 -- 回复:(blackzhu) writer.Formatting = Xml.Fo... 不得行啊 还得麻烦各位大大继续指导 谢谢! |
-- 作者:有点蓝 -- 发布时间:2016/10/26 15:10:00 -- 测试没有问题,2楼的方式可以自动缩进 Dim writer As New Xml.XmlTextWriter(xml, System.Text.Encoding.GetEncoding("utf-8")) writer.Formatting = System.Xml.Formatting.Indented \'书写根元素() writer.WriteStartElement("case") For i As Integer = 1 To sheet.Rows.count -1 如果XML不需要人工处理,缩进不缩进都没有关系的
|
-- 作者:李孝春 -- 发布时间:2016/10/27 20:57:00 -- 回复:(有点蓝)测试没有问题,2楼的方式可以自动缩进... 谢谢 原来上面的少了这个红色部分 writer.Formatting = System.Xml.Formatting.Indented
|