Extracting Data From XML with VBA

ShaineB1981

New Member
As a bit of a background, im a fairly new person to coding. its been pretty much 10 years since i last 'coded' so please go easy ;).Im currently trying to exctract data from an XML file below:\[code\]- <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>\[/code\]At the moment im wanting the user to chose which IPnumber, Channel and Band they want.. then i want to extract the CMPWRE & CMPWIM data for each in a list like below:\[code\]IPNumber 'X'Band 'X'Channel 'X'CMPWRE 'XXX'CMPWIM 'XXX' \[/code\]Here is a short snippet of code that im trying to use to extract the data, but im just getting no luck getting it to work.Code:\[code\]Set oXML = CreateObject("MSXML.DOMDocument")oXML.async = FalseoXML.Load ("H:\14-13-21.xml")Dim LgChan As StringDim LgChan1 As StringDim LgChan2 As String**Dim LgChan3 As StringDim LgChan4 As String**Dim Test As Integer Dim Test2 As IntegerDim Test3 As IntegerTest = mobelenum0.Value ' User Box on GUI where a value is inputted E.G. the number 5Test2 = 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 1LgChan = "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 = http://stackoverflow.com/questions/13804343/oXML.DocumentElement.SelectSingleNode(LgChan).NodeTypedValue Worksheets("sheet1").Range("B102").Value = http://stackoverflow.com/questions/13804343/oXML.DocumentElement.SelectSingleNode(LgChan1).nodeTypedValue Worksheets("sheet1").Range("B103").Value = http://stackoverflow.com/questions/13804343/oXML.DocumentElement.SelectSingleNode(LgChan2).nodeTypedValue**Worksheets("sheet1").Range("B104").Value = http://stackoverflow.com/questions/13804343/oXML.DocumentElement.SelectSingleNode(LgChan3).nodeTypedValueWorksheets("sheet1").Range("B105").Value = http://stackoverflow.com/questions/13804343/oXML.DocumentElement.SelectSingleNode(LgChan4).nodeTypedValue**\[/code\]im struggling to get the code so that if a differend band is selected then obviously the channel value will change... same again with the IPNumber change filtering down through. Any help would be great!Smerf
 
Back
Top