问题描述
由于工作需要,需要用到可以导入Testlink制式的XML文件,请问要如何做?对VBA精通的大神在哪里?主要是在原先在Testlink中导出的XML数据文档中有CDATA;而自己从Excel导出的XML却没有CDATA。求大神指点指点!期望效果如下:<?xmlversion="1.0"encoding="UTF-8"?><testcases><testcaseinternalid="5"name="拨号盘界面键盘验证"><node_order><![CDATA[0]]></node_order><externalid><![CDATA[1]]></externalid><version><![CDATA[1]]></version><summary><![CDATA[]]></summary><preconditions><![CDATA[]]></preconditions><execution_type><![CDATA[1]]></execution_type><importance><![CDATA[2]]></importance><steps><step><step_number><![CDATA[1]]></step_number><actions><![CDATA[<p>在IDLE界面点击拨号打开拨号盘,或者程序列表中点击拨号,进入拨号盘</p>]]></actions><expectedresults><![CDATA[<p>可以正常进入拨号盘</p>]]></expectedresults><execution_type><![CDATA[1]]></execution_type></step>
Issue如下:<?xmlversion="1.0"encoding="GB2312"standalone="yes"?><!--来源:export2XML.xls--><export2XML><Sheet1><internalid>5</internalid><name>拨号盘界面键盘验证</name><node_order>0</node_order><externalid>1</externalid><version>1</version><summary></summary><preconditions></preconditions><execution_type>1</execution_type><importance>2</importance><step_number>1</step_number><actions><p>在IDLE界面点击拨号打开拨号盘,或者程序列表中点击拨号,进入拨号盘</p></actions><expectedresults><p>可以正常进入拨号盘</p></expectedresults><execution_type2>1</execution_type2>
解决方案
本帖最后由 u010777776 于 2014-01-16 14:37:58 编辑
解决方案二:
读取每一行,替换![CDATA[和]]为空,再保存
解决方案三:
读取有CDATA的XML里的数据,再存新的XML用XmlDocument读取有CDATA,可直接读取CDATA里的数据,DimdocAsXmlDocument=NewXmlDocument()doc.Load("test.xml")DiminterAsXmlNode=doc.SelectSingleNode("//testcases/testcase")DiminternalidAsString=inter.Attributes("internalid").InnerTextDimnameAsString=inter.Attributes("name").InnerTextDimnode_orderAsXmlNode=doc.SelectSingleNode("//testcases/testcase/node_order")Dimnode_order1AsString=node_order.InnerTextDimexternalidAsXmlNode=doc.SelectSingleNode("//testcases/testcase/externalid")Dimexternalid1AsString=externalid.InnerTextDimversionAsXmlNode=doc.SelectSingleNode("//testcases/testcase/version")Dimversion1AsString=version.InnerTextDimsummaryAsXmlNode=doc.SelectSingleNode("//testcases/testcase/summary")Dimsummary1AsString=version.InnerTextDimpreconditionsAsXmlNode=doc.SelectSingleNode("//testcases/testcase/preconditions")Dimpreconditions1AsString=preconditions.InnerTextDimexecution_typeAsXmlNode=doc.SelectSingleNode("//testcases/testcase/execution_type")Dimexecution_type1AsString=execution_type.InnerTextDimimportanceAsXmlNode=doc.SelectSingleNode("//testcases/testcase/importance")Dimimportance1AsString=importance.InnerTextDimstep_numberAsXmlNode=doc.SelectSingleNode("//testcases/testcase/step/step_number")Dimstep_number1AsString=step_number.InnerTextDimactionsAsXmlNode=doc.SelectSingleNode("//testcases/testcase/step/actions")Dimactions1AsString=actions.InnerTextDimexpectedresultsAsXmlNode=doc.SelectSingleNode("//testcases/testcase/step/expectedresults")Dimexpectedresults1AsString=expectedresults.InnerTextDimexecutionAsXmlNode=doc.SelectSingleNode("//testcases/testcase/step/execution_type")Dimexecution1AsString=execution.InnerTextDimwriterAsXmlTextWriter=NewXmlTextWriter("new.xml",System.Text.Encoding.GetEncoding("utf-8"))writer.Formatting=Xml.Formatting.Indentedwriter.WriteRaw("<?xmlversion=""1.0""encoding=""GB2312""standalone=""yes""?>")'书写根元素()writer.WriteStartElement("export2XML")'添加次级元素writer.WriteStartElement("Sheet1")'添加子元素()writer.WriteElementString("internalid",internalid)writer.WriteElementString("name",name)writer.WriteElementString("node_order",node_order1)writer.WriteElementString("externalid",externalid1)writer.WriteElementString("version",version1)writer.WriteElementString("summary",summary1)writer.WriteElementString("preconditions",preconditions1)writer.WriteElementString("execution_type",execution_type1)writer.WriteElementString("importance",importance1)writer.WriteElementString("step_number",step_number1)writer.WriteElementString("actions",actions1)writer.WriteElementString("expectedresults",expectedresults1)writer.WriteElementString("execution_type2",execution1)writer.WriteEndElement()'关闭根元素writer.WriteFullEndElement()'将XML写入文件并关闭writerwriter.Close()
解决方案四:
多谢!我试试