CURRENT XML:
<?xml version="1.0"?>
<form1>
<page1>
<first_name></first_name>
<last_name></last_name>
.
.
</page1>
<page2>
<address></address>
<phone_number></phone_number>
.
.
</page2>
<page3>
<company_name></company_name>
<job_title></job_title>
.
.
</page3>
</form1>
DESIRED XML –
i want to merge all child elements and rename the parent:
<?xml version="1.0"?>
<form>
<page>
<first_name></first_name>
<last_name></last_name>
.
.
<address></address>
<phone_number></phone_number>
.
.
<company_name></company_name>
<job_title></job_title>
.
.
</page>
</form>
then, since i have thousands of XML files with some unknown elements, i want to find all of them before bulk importing the XML into Access database, because any new elements in subsequent files will be dropped if they are not defined in the schema.
not all child elements are known.
not all file names are known.
so, how can i check all files for all elements, fill the Access table with them all, then bulk import all the XML records to fit into the desired schema as shown above?
EDIT:
ok, i see – there are no attributes.
what i meant was all child elements.
thanks for pointing that out Oded, I updated the question with corrections.
this is the VBA code I am using in Access for bulk importing the files:
Private Sub cmdImport_Click()
Dim strFile As String 'Filename
Dim strFileList() As String 'File Array
Dim intFile As Integer 'File Number
Dim strPath As String ' Path to file folder
strPath = "C:\Users\Main\Desktop\XML-files"
strFile = Dir(strPath & "*.XML")
While strFile <> ""
'add files to the list
intFile = intFile + 1
ReDim Preserve strFileList(1 To intFile)
strFileList(intFile) = strFile
strFile = Dir()
Wend
'see if any files were found
If intFile = 0 Then
MsgBox "No files found"
Exit Sub
End If
'cycle through the list of files
For intFile = 1 To UBound(strFileList)
Application.ImportXML strPath & strFileList(intFile), acAppendData
Next intFile
MsgBox "Import Completed"
End Sub
i can use the stylesheet to transform the XML as such:
For intFile = 1 To UBound(strFileList)
Application.TransformXML strPath & strFileList(intFile), _
"C:\Users\Main\Desktop\stylesheet2.xslt", _
"C:\Users\Main\Desktop\temp.xml", True
Application.ImportXML "C:\Users\Main\Desktop\temp.xml", acAppendData
Next intFile
MsgBox "Import Completed"
End Sub
however, it does not merge all the file elements into one table. am i missing something?
do i need to save a variable list? or create some attribute ids?
EDIT: From comments
my file names are 1.xml, 2.xml, 3.xml,
4.xml, etc. But like i said have thousands
Suppose this input documents:
1.xml
2.xml
This stylesheet:
Output:
Note: If this blows up your memory, then you need to split this in two stylesheets: first, output the names; second, merge. If you can’t pass param with
Application.TransformXML, then the max number of files is fixed. Also, there must not be any hole: if max number of files is 3,2.xmlcan’t be missed (this is becausefn:documentthrows an error)EDIT: For a two pass transformation.
This stylesheet with any input (not used):
Output:
And this stylesheet:
With previus output as input, result: