怎样读取XML文件!
我有一份XML的文件,但有一个问题,总是出错的,就是每次运行到sXml.sOrderNo = Trim(objChild.Text)这个出现 "对象变量或with块变量未设置 ",请问那个可以帮帮我!
XML文件如下:
<ORDERS>
<ORDER>
<Header>
<OrderNo> 4500018292 </OrderNo>
<OrderDate> 13.04.07 </OrderDate>
<OrderCustomer> TC001 </OrderCustomer>
</Header>
Dim objXML As New DOMDocument
Dim objNODE As IXMLDOMNode
Dim objChild As IXMLDOMNode
Dim sXml As XmlContent
Dim nI As Integer
objXML.Load (sFile)\\\XML文件的路径
Set objNODE = objXML.selectSingleNode( "ORDERS ")
Set objNODE = objNODE.selectSingleNode( "ORDER ")
Set objNODE = objNODE.selectSingleNode( "Header ")
For nI = 0 To objNODE.childNodes.Length - 1
Set objChild = objNODE.childNodes(nI).selectSingleNode( "OrderNo ")
sXml.sOrderNo = Trim(objChild.Text)
Set objChild = objNODE.childNodes(nI).selectSingleNode( "OrderDate ")
If IsDate(objChild.Text) = True Then sXml.sOrderDate = Format(CDate (objChild.Text), "yyyy-mm-dd ") Else sXml.sOrderDate = #1/1/1900#
Next
[解决办法]
先mark下,稍后再看,只是友情提醒,你的XML文件明显都没闭合。
- <ORDERS>
- <Header>
<OrderNo> 4500018292 </OrderNo>
<OrderDate> 13.04.07 </OrderDate>
<OrderCustomer> TC001 </OrderCustomer>
</Header>
</ORDERS>
应该这样子的文件