作为一个背景,我对编码来说是一个相当新的人。自从我上次“编码”以来已经快 10 年了,所以请放轻松;)。
我目前正在尝试从下面的 XML 文件中提取数据:
- <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>
目前我希望用户选择他们想要的 IP 号码、频道和频段。然后我想在如下列表中为每个提取 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**
我正在努力获取代码,以便如果选择了不同的频段,那么显然通道值将会改变......再次过滤IPNumber更改。
任何帮助都会很棒!
小精灵