作爲一個背景位,我是一個相當新的編程人員。自從我上次'編碼'以來,這已經差不多10年了,所以請放輕鬆;)。使用VBA從XML中提取數據
林目前正試圖從下面的XML文件exctract數據:
- <IPNumber IPNumber="5">
- <Band Band="1">
- <Channel Channel="1">
<CMPWRE>0.123456</CMPWRE>
<CMPWIM>0.234567</CMPWIM>
</Channel>
- <Channel Channel="2">
<CMPWRE>-0.123456</CMPWRE>
<CMPWIM>0.234567</CMPWIM>
</Channel>
</Band>
- <Band Band="2">
- <Channel Channel="1">
<CMPWRE>0.123456</CMPWRE>
<CMPWIM>0.234567</CMPWIM>
</Channel>
</Band>
</IPNumber5>
- <IPNumber IPNumber="6">
- <Band Band="1">
- <Channel Channel="1">
<CMPWRE>0.123456</CMPWRE>
<CMPWIM>0.234567</CMPWIM>
</Channel>
- <Channel Channel="2">
<CMPWRE>-0.123456</CMPWRE>
<CMPWIM>0.234567</CMPWIM>
</Channel>
</Band>
- <Band Band="2">
- <Channel Channel="1">
<CMPWRE>0.123456</CMPWRE>
<CMPWIM>0.234567</CMPWIM>
</Channel>
</Band>
</IPNumber6>
目前IM希望用戶選擇IPnumber,信道和頻帶他們想要的..然後我想提取的CMPWRE &每個列表中像下面CMPWIM數據:
IPNumber 'X'
Band 'X'
Channel 'X'
CMPWRE 'XXX'
CMPWIM 'XXX'
下面是一小段程式碼,即時通訊試圖用提取的數據,但我只是沒有得到任何運氣得到它的工作。
代碼:
Set oXML = CreateObject("MSXML.DOMDocument")
oXML.async = False
oXML.Load ("H:\14-13-21.xml")
Dim LgChan As String
Dim LgChan1 As String
Dim LgChan2 As String
**Dim LgChan3 As String
Dim LgChan4 As String**
Dim Test As Integer
Dim Test2 As Integer
Dim Test3 As Integer
Test = mobelenum0.Value ' User Box on GUI where a value is inputted E.G. the number 5
Test2 = FeedSubBand.Value ' User Box on GUI where a value is inputted E.G. the number 1
Test3 = LogicChannel.Value ' User Box on GUI where a value is inputted E.G. the number 1
LgChan = "TableContents/IPModuleNumber[@IPModuleNumber='1']"
LgChan1 = "//TableContents/IPModuleNumber/FeederSubBand[@FeederSubBand=" & Test2 & "]"
LgChan2 = "//TableContents/IPModuleNumber/FeederSubBand/LogicalChannel[@LogicalChannel=" & Test3 & "]"
**LgChan3 = "//TableContents/IPModuleNumber/FeederSubBand/LogicalChannel[@LogicalChannel=" & Test3 & "]/CMPWRE"
LgChan4 = "//TableContents/IPModuleNumber/FeederSubBand/LogicalChannel[@LogicalChannel=" & Test3 & "]/CMPWIM"**
Worksheets("sheet1").Range("B101").Value = oXML.DocumentElement.SelectSingleNode(LgChan).NodeTypedValue
Worksheets("sheet1").Range("B102").Value = oXML.DocumentElement.SelectSingleNode(LgChan1).nodeTypedValue
Worksheets("sheet1").Range("B103").Value = oXML.DocumentElement.SelectSingleNode(LgChan2).nodeTypedValue
**Worksheets("sheet1").Range("B104").Value = oXML.DocumentElement.SelectSingleNode(LgChan3).nodeTypedValue
Worksheets("sheet1").Range("B105").Value = oXML.DocumentElement.SelectSingleNode(LgChan4).nodeTypedValue**
IM努力獲得的代碼,這樣,如果選擇了differend帶那麼很明顯的渠道價值將隨着IPNumber變化通過過濾下來改變......一樣了。
任何幫助將是偉大的!
Smerf
您是否擁有對xml佈局的控制權?通過我的思維方式,是無效的XML。這不會幫助任何類型的解析器 –
Chris