I have the code below that maps an XML schema to Excel spreadsheets (as in ListObjects).
Sub MapXMLFieldsToExcelCells(wb As Workbook, sLOB As String)
'*******************************************************************
'** Name: xmlFieldMap
'** Purpose: Maps fields of existing xlmMap (named "xmlData") to file
'** Dependents: TieXMLToExcel (remapping of xml file)
'** Notes:
'*******************************************************************
sProcName = "MapXMLFieldsToExcelCells"
With wb
Dim xMap As XmlMap
Set xMap = .XmlMaps(sLOB)
Dim wsXMLMain As Worksheet
Set wsXMLMain = .Worksheets("xml" & IIf(Left(.Name, 2) = "SA", "SA", "") & sLOB)
Dim wsConfig As Worksheet
Set wsConfig = .Worksheets("rConfig")
With wsConfig
Dim rNode As Range
For Each rNode In .Range("xmlNodeMapping").Columns(1).Cells
Dim sNodePath As String
sNodePath = rNode & rNode.Offset(, 1)
Dim sTable As String
sTable = rNode.Offset(, 2)
'only have this here in case node does not exist
'caveat is that it will fail also if node is just written out wrong
Application.DisplayAlerts = False
'On Error Resume Next
wsXMLMain.ListObjects(sTable).ListColumns(rNode.Offset(, 3).Value2).XPath.SetValue xMap, sNodePath
'On Error GoTo ErrorReport
Application.DisplayAlerts = True
Next
End With
.XmlMaps(sLOB).DataBinding.Refresh
End With
End Sub
(please ignore the specific lines of the project here - there are not many of them)
The code works fine. I can map the nodes and node attributes if I pass the configuration sheet as shown below:
Xpath Node Table Field
/root/d/p/t/ ar tForms AR
/root/d/p/t/ @n tFormsa name
What I would like to do, if possible, is to apply a filter on the node to display only some elements from the node.
For example, based on the correct syntax:
Xpath Node Table Field
/root/d/p/t[item='ar']/ type tForms type
Will only pull elements in node t, which is = ar.
I can’t make it work and I can’t find anything on the Internet, I can agree that this is not an option, but he wants to publish it before abandoning the approach.