I'm having issues with referring to the schema file that is used in the XML files that are loaded. Schema file is located in folder="C:\Users\zander\Desktop\20211112094529\Recipe\RECIPEs\Data\Sequences\"
and because the XML files are in multiple subfolders, I don't want to copy the schema file to each subfolder.
All the examples that I find are with http...
locations, can anyone help me with referring to a local folder?
<?xml version="1.0"?>
<SEQUENCE Format="2.0" Name="hardware\bbx" xmlns="x-schema:sequence_schema.xml">
<PASSPORT Frozen="No" Type="Production" AccessModifyGroups="All" AccessDisplayGroups="All"
Version="1.0" ReviseTime="28/11/2018 11:36:13.384" Revisor="Wesley" CreateTime="11/01/2012
17:38:14.765" Creator="Wes" Description="">
<CUSTOM>
<CUSTOM_PARAM Name="SendLotEndSignal" Value="0"/>
</CUSTOM>
</PASSPORT>
<STEPS>
<STEP SeqEndCleanRecipe="NO_RECIPE" Recipe="STANDARD\205C" Chambers="B2B35" SectionName="Steps">
<CUSTOM>
<CUSTOM_PARAM Name="Type" Value="PAAP"/>
<CUSTOM_PARAM Name="Block" Value="B2"/>
</CUSTOM>
</STEP>
<STEP SeqEndCleanRecipe="NO_RECIPE" Recipe="STANDARD\110C" Chambers="B2B14" SectionName="Steps">
<CUSTOM>
<CUSTOM_PARAM Name="Type" Value="PAHP"/>
<CUSTOM_PARAM Name="Block" Value="B2"/>
</CUSTOM>
</STEP>
</STEPS>
</SEQUENCE>
This is the code that I'm using (updated to full new code). The code works perfectly when I copy the schema file to the same folder as the XML, it works but I prefer not to do this because I have a lot of subfolders:
Option Explicit
'Sub ReadAllXML(Ffolder As String)
Sub ReadAllXML()
Dim Ffolder As String
Dim FilePath, XMLFileName, RecipeID As String
Dim main_folder As String
Dim oXMLFile, Recipe As Object
Dim Col, NumberOfElements, LastRow As Long
Dim n As Object
Dim RecipeName, ChamberName, UnitKind, BlockName As String
Dim strtxt, Fromtxt, FromPos, PathWithoutSequences, FirstFolder As String
Dim wks As Worksheet
'main folder is the folder where the schema file is stored
main_folder = "C:\Users\zander\Desktop\20211112094529\Recipe\RECIPEs\Data\Sequences\"
'Ffolder are different folders where all the XML files are stored
Ffolder = "C:\Users\zander\Desktop\20211112094529\Recipe\RECIPEs\Data\Sequences\Subfolder1\subfolder2\"
Set oXMLFile = CreateObject("Microsoft.XMLDOM")
Set wks = ThisWorkbook.Worksheets("Sheet1")
XMLFileName = Dir(Ffolder & "*.xml")
If XMLFileName <> "" Then
FilePath = Ffolder & XMLFileName
' Namespace = "xmlns=x-schema:sequence_schema.xml" "xsi:schemaLocation=""file:///C:\Users\zander\Desktop\20211112094529\Recipe\RECIPEs\Data\Sequences\sequence_schema.xml""
oXMLFile.Load FilePath
'oXMLFile.SetProperty "SelectionLanguage", "XPath"
'oXMLFile.SetProperty "SelectionNamespaces", "xmlns=x-schema:sequence_schema.xml"
'oXMLFile.resolveExternals = False
'oXMLFile.validateOnParse = False
Debug.Print oXMLFile.parseError.ErrorCode & " " & oXMLFile.parseError.reason & " " & oXMLFile.parseError.Line
'Set elements = oXMLFile.getElementsByTagName("STEP")
'RecipeName = oXMLFile.SelectSingleNode("//STEP").Attributes.getNamedItem("Recipe").Text
'BlockName = oXMLFile.SelectSingleNode("//STEP/CUSTOM").Attributes.getNamedItem("CUSTOM_PARAM").Text
Col = 10
NumberOfElements = oXMLFile.getElementsByTagName("STEP").Length
With wks
LastRow = wks.Cells(wks.Rows.Count, "C").End(xlUp).Row + 1
strtxt = FilePath
Fromtxt = "Sequences"
'Totxt = "test"
FromPos = InStr(strtxt, Fromtxt)
'ToPos = InStr(strtxt, Totxt)
'extract the text string between the two words
'ExtractStr = Mid(strtxt, FromPos + Len(Fromtxt), ToPos - FromPos - Len(Fromtxt))
PathWithoutSequences = Right(strtxt, Len(strtxt) - FromPos - 9)
FirstFolder = Left(PathWithoutSequences, Len(PathWithoutSequences) - Len(XMLFileName) - 1)
.Cells(LastRow, 3) = FirstFolder
.Cells(LastRow, 8) = XMLFileName
For Each n In oXMLFile.SelectNodes("//STEP")
RecipeName = n.Attributes.getNamedItem("Recipe").Text
ChamberName = n.Attributes.getNamedItem("Chambers").Text
UnitKind = n.ChildNodes(0).ChildNodes(0).Attributes.getNamedItem("Value").Text
BlockName = n.ChildNodes(0).ChildNodes(1).Attributes.getNamedItem("Value").Text
.Cells(LastRow, Col) = RecipeName
.Cells(LastRow, Col + 1) = ChamberName
.Cells(LastRow, Col + 2) = UnitKind
.Cells(LastRow, Col + 3) = BlockName
Col = Col + 4
Next
End With
End If
End Sub