steve_bezrad


Hi,

I need to select "PortfolioBreakdown" node and everything inside this node based on <_SalePosition="L"> attribute. Any suggestions

XML part of the file:

- <PortfolioBreakdown _SalePosition="L">
- <AssetAllocation>
<BreakdownValue Type="1">92.60</BreakdownValue>
<BreakdownValue Type="2">5.89</BreakdownValue>
<BreakdownValue Type="3">0.00</BreakdownValue>
<BreakdownValue Type="4">0.00</BreakdownValue>
<BreakdownValue Type="5">0.00</BreakdownValue>
<BreakdownValue Type="6">0.00</BreakdownValue>
<BreakdownValue Type="7">3.23</BreakdownValue>
<BreakdownValue Type="8">0.00</BreakdownValue>
</AssetAllocation>
- <MarketCapitalBreakdown>
<BreakdownValue Type="1">26.46</BreakdownValue>
<BreakdownValue Type="2">29.53</BreakdownValue>
<BreakdownValue Type="3">31.63</BreakdownValue>
<BreakdownValue Type="4">10.54</BreakdownValue>
<BreakdownValue Type="5">0.33</BreakdownValue>
</MarketCapitalBreakdown>
My code sample:
Option Explicit
Public Sub FilesAccess(path)
Dim fso, xmlfile, Starttime, Endtime
Starttime = Time
Set fso = CreateObject("Scripting.FileSystemObject")
Sheet1.Cells(1).Value = "Start:" & Time
For Each xmlfile In fso.GetFolder(path).Files
CheckBreakdown CStr(xmlfile)
Next
Set xmlfile = Nothing
Set fso = Nothing
Endtime = Time
Sheet1.Cells(2).Value = "End:" & Time
MsgBox ("The test is completed")
End Sub
Private Sub CheckBreakdown(xmlfile)
Dim doc, nodes, node, sum As Double, break, breakdownvaluetype, nodes_0, num_of_breakdown_values, max_num, min_of_breakdown_values, min_num, Count, nodes_1, saleposition, x
Set doc = CreateObject("MSXML2.DOMDocument.4.0")
doc.async = False
doc.Load xmlfile
doc.setProperty "SelectionLanguage", "XPath"
### Once again I'm interested in accessing this node and everything inside based on specific attribute <_SalePosition='L'>###
Set nodes = doc.SelectNodes("//Package/PackageBody/FundShareClass/Fund/PortfolioList/Portfolio/PortfolioBreakdown[_SalePosition='L']")
.... Other code .......



Re: How to select a specific set of nodes from xml file by using VBA

Jonathan Allen


I hate to say it, but you most likely won't get an answer here. This is a VB.NET forum, and VBA is more like VB 6.

Jonathan






Re: How to select a specific set of nodes from xml file by using VBA

Bruno Yu - MSFT

Move the thread from Visual Basic General. There are more exports on Visual Basic for Applications in this forum. I believe you are able to get the satisfying answers.

If you have any questions in VB6, please post the thread in the following links:

  • Visual Basic 6 Newgroups
  • Visual Basic 6.0 on MSDN Library
  • MSDN Visual Basic 6.0 Resource Center
  • VB City
  • VB-Helper
  • VB Forums
  • CodeGuru
  • Code Project
  • Planet Source Code

    Thanks again for your question.