Home |
Search |
Today's Posts |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
This worked for me:
'############################# Sub Tester() Dim xmlDoc As New MSXML2.DOMDocument40 Dim objNodeList As IXMLDOMNodeList Dim x As Object xmlDoc.async = False xmlDoc.loadXML Sheet1.Range("A1").Value If xmlDoc.parseError.errorCode < 0 Then Debug.Print "Error!" & vbCrLf & _ " Line: " & xmlDoc.parseError.Line & vbCrLf & _ " Text:" & xmlDoc.parseError.srcText & vbCrLf & _ " Reason: " & xmlDoc.parseError.reason Else Set objNodeList = xmlDoc.selectNodes("//Category") Debug.Print "Count: " & objNodeList.Length For Each x In objNodeList Debug.Print x.XML Next End If End Sub '#################################### Note I have a different xml version Tim. "Mike Archer" wrote in message ... Hello - I am pretty comfortable with vba in excel. However, I don't know anything about xml. I am trying to query an xml file. Here is a piece of the xml: <?xml version="1.0" encoding="UTF-8" ? - <GetCategoriesResponse xmlns="urn:ebay:apis:eBLBaseComponents" <Timestamp2006-04-28T14:27:28.172Z</Timestamp <AckSuccess</Ack <Version457</Version <Builde457_core_Bundled_2818483_R1</Build - <CategoryArray - <Category <BestOfferEnabledtrue</BestOfferEnabled <AutoPayEnabledtrue</AutoPayEnabled <CategoryID20081</CategoryID <CategoryLevel1</CategoryLevel <CategoryNameAntiques</CategoryName <CategoryParentID20081</CategoryParentID <Expiredfalse</Expired <IntlAutosFixedCatfalse</IntlAutosFixedCat <LeafCategoryfalse</LeafCategory <Virtualfalse</Virtual <ORPAfalse</ORPA <LSDfalse</LSD </Category - <Category <BestOfferEnabledtrue</BestOfferEnabled <AutoPayEnabledtrue</AutoPayEnabled <CategoryID37903</CategoryID <CategoryLevel2</CategoryLevel <CategoryNameAntiquities (Classical, Amer.)</CategoryName <CategoryParentID20081</CategoryParentID <Expiredfalse</Expired <IntlAutosFixedCatfalse</IntlAutosFixedCat <LeafCategoryfalse</LeafCategory <Virtualfalse</Virtual <ORPAfalse</ORPA <LSDfalse</LSD </Category - <Category <BestOfferEnabledtrue</BestOfferEnabled <AutoPayEnabledtrue</AutoPayEnabled <CategoryID37905</CategoryID <CategoryLevel3</CategoryLevel <CategoryNameEgyptian</CategoryName <CategoryParentID37903</CategoryParentID <Expiredfalse</Expired <IntlAutosFixedCatfalse</IntlAutosFixedCat <LeafCategorytrue</LeafCategory <Virtualfalse</Virtual <ORPAfalse</ORPA <LSDfalse</LSD </Category I need to be able to filter by CategoryParentID and return an array of CategoryNames. I know that I need to utilize XPath, but there is really no documentation in the excel help files. This is what I have tried so far: Dim xmlDoc As New Msxml2.DOMDocument40 Dim objNodeList As IXMLDOMNodeList xmlDoc.async = False xmlDoc.Load ("G:\CatTree.xml") xmlDoc.setProperty "SelectionLanguage", "XPath" Set objNodeList = xmlDoc.selectNodes("//Category") ' I get nothing returned for objNodeList MsgBox objNodeList.Length ' this is 0 For Each x In objNodeList ' skips this loop (because it is empty) MsgBox x.XML Next End Sub I think that I need to utilize selectionNameSpaces (but i'm not sure how - I'm not even completely sure I understand what a namespace is). If someone could point me towards some good examples of querying xml from vba in excel, that would be great. Specifically, the above example is the ebay category tree. So examples of using ebay's CatTree.xml would be even better. I can't find anything out there in vba (and I have really tested the limits of google's computing abilities). -- Thanks, Mike |