0
我想用VBA解析xml以獲得來自電氣測試系統的測試結果。這是一個什麼樣的系統是給我一個例子:從<Prop Type='Obj' TypeName='NI_CriticalFailureStackEntry' Flags='0x0'> <Value>Brady Detection</Value>
用VBA解析XML
我
<Reports>
<Report Type='UUT' Title='UUT Report' Link='-1-2013-11-20-10-2-46-867' UUTResult='Failed' StepCount='132'>
<Prop Name='UUT' Type='Obj' TypeName='UUT' Flags='0x0'>
<Prop Name='SerialNumber' Type='String' Flags='0x0'>
<Value>02</Value>
</Prop>
<Prop Name='PartNumber' Type='String' Flags='0x0'>
<Value>1009433</Value>
</Prop>
<Prop Name='LotNumber' Type='String' Flags='0x0'>
<Value>1234567</Value>
</Prop>
<Prop Name='CriticalFailureStack' Type='Array' LBound='[0]' HBound='[1]' ElementType='Obj' Flags='0x0'>
<ArrayElementPrototype Type='Obj' TypeName='NI_CriticalFailureStackEntry' Flags='0x0'>
<Prop Name='StepName' Type='String' Flags='0x0'>
<Value></Value>
</Prop>
<Prop Name='SequenceName' Type='String' Flags='0x0'>
<Value></Value>
</Prop>
<Prop Name='SequenceFileName' Type='String' Flags='0x0'>
<Value></Value>
</Prop>
<Prop Name='ResultId' Type='Number' Flags='0x0'>
<Value>0</Value>
</Prop>
</ArrayElementPrototype>
<Value ID='[0]'>
<Prop Type='Obj' TypeName='NI_CriticalFailureStackEntry' Flags='0x0'>
<Prop Name='StepName' Type='String' Flags='0x0'>
<Value>Brady Detection</Value>
</Prop>
<Prop Name='SequenceName' Type='String' Flags='0x0'>
<Value>MainSequence</Value>
</Prop>
<Prop Name='SequenceFileName' Type='String' Flags='0x0'>
<Value>1009450 AT ILR Final-test_app.seq</Value>
</Prop>
<Prop Name='ResultId' Type='Number' Flags='0x0'>
<Value>44</Value>
</Prop>
</Prop>
</Value>
<Value ID='[1]'>
<Prop Type='Obj' TypeName='NI_CriticalFailureStackEntry' Flags='0x0'>
<Prop Name='StepName' Type='String' Flags='0x0'>
<Value>Number of Brady Beats</Value>
</Prop>
<Prop Name='SequenceName' Type='String' Flags='0x0'>
<Value>Brady Detection</Value>
</Prop>
<Prop Name='SequenceFileName' Type='String' Flags='0x0'>
<Value>1009450 AT ILR Final-test_app.seq</Value>
</Prop>
<Prop Name='ResultId' Type='Number' Flags='0x0'>
<Value>49</Value>
</Prop>
我想從<prop name = 'serial number'>
從<Report UUTResult = 'Failed'>
拉出序列號,測試結果和設備故障從來沒有使用XML工作過,但是這是我通過閱讀這個網站迄今爲止得到:
Dim xml As New MSXML.DOMDocument60
Dim xReport As IXMLDOMElement
Dim result As String
xml.Load (filePath)
Set xReport = xml.SelectSingleNode("//Reports/Report/")
result = xReport.getAttribute("UUTResult")
當我跑,我得到「運行時錯誤「2147467259(80004005):自動化設置xReport時出現錯誤未指定錯誤。
我也嘗試將xml作爲新的MSXML2.DOMDocument(而不是DOMDocument60)進行投射,然後在同一行中得到類型不匹配。
任何幫助非常感謝!
謝謝。
我似乎記得收到錯誤一樣,當沒有很好地形成的XML文檔。它在開始時是否有'xml'元素? – Mansfield
This [link](http://stackoverflow.com/questions/19729601/dynamically-search-for-data-in-an-xml-file-with-vba/19730346#19730346)可能會有所幫助。 – Santosh
我在第2行的原始文章中啓動了代碼。這是第一行:<?xml version =「1.0」encoding =「iso-8859-1」?><?xml-stylesheet type =「text/xsl」 HREF =? 「C:\數據\ horizontal.xsl」> – mkodikan