I have two XML files (A
and B
) that I want to append to form XML file C
. Basically A
is just a "header" and B
is the "main" content.
A.xml
:
<?xml version="1.0" encoding="utf-8" ?>
<!--
SAS XML Libname Engine (SAS92XML)
SAS XMLMap Generated Output
Version 9.04.01M3P06242015
Created 2021-02-18T16:52:07
-->
<ns2:message xmlns:ns2="message">
<ns2:header xmlns:ns2="message">
<ns2:ID xmlns:ns2="message">11111</ns2:ID>
<ns2:survey xmlns:ns2="message">AABB</ns2:survey>
<ns2:partner xmlns:ns2="message">ABC</ns2:partner>
<ns2:initialDate xmlns:ns2="message">2020-01-01T00:00:00.000+00:00</ns2:initialDate>
<ns2:timeProduction xmlns:ns2="message">2021-02-18T16:41:35</ns2:timeProduction>
<ns2:type xmlns:ns2="message">TYPEOFMESSAGE</ns2:type>
</ns2:header>
</ns2:message>
B.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<ns2:message xmlns:ns2="message"
xmlns:ns3="send">
<ns2:content>
<ns2:dataSegment id="OBSERVATION">
<ns2:cube id="ABCD">
<ns3:obs>
<ns3:dim name="ID" value="1"/>
<ns3:dim name="FROM" value="2021-02-17"/>
<ns3:dim name="TO" value="2021-02-19"/>
<ns3:dim name="VALUE" value="A"/>
</ns3:obs>
</ns2:cube>
</ns2:dataSegment>
</ns2:content>
</ns2:message>
C.xml (want)
:
<?xml version="1.0" encoding="UTF-8"?>
<ns2:message xmlns:ns2="message"
xmlns:ns3="send">
<ns2:header>
<ns2:ID>11111</ns2:ID>
<ns2:survey>AABB</ns2:survey>
<ns2:partner>ABC</ns2:partner>
<ns2:initialDate>2020-01-01T00:00:00.000+00:00</ns2:initialDate>
<ns2:timeProduction>2021-02-18T16:41:35</ns2:timeProduction>
<ns2:type>TYPEOFMESSAGE</ns2:type>
</ns2:header>
<ns2:content>
<ns2:dataSegment id="OBSERVATION">
<ns2:cube id="ABCD">
<ns3:obs>
<ns3:dim name="ID" value="1"/>
<ns3:dim name="FROM" value="2021-02-17"/>
<ns3:dim name="TO" value="2021-02-19"/>
<ns3:dim name="VALUE" value="A"/>
</ns3:obs>
</ns2:cube>
</ns2:dataSegment>
</ns2:content>
</ns2:message>
For a long time, I have been using the PROC XSL
to append A
and B
using the following .xsl
script
script.xsl
:
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns2="message">
<xsl:output indent="yes" encoding="UTF-8"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/ns2:message">
<ns2:message xmlns:ns2="message" xmlns:ns3="send">
<!-- COPY CURRENT DATA -->
<xsl:copy-of select="*"/>
<!-- COMBINE ALL DATA FROM file.xml -->
<xsl:copy-of select="document('file:/path/to/file.xml')/ns2:message/*" />
</ns2:message>
</xsl:template>
</xsl:transform>
However, I found out that when B
is too large (~60MB), the PROC XSL
does not create C
(it does the job perfectly when B
is not that large).
SAS Code
:
proc xsl
in = 'path/to/file/A.xml'
xsl = 'path/to/file/script.xsl'
out = 'path/to/file/final.xml';
run;
No errors/warnings in the log.
SAS Log
:
MPRINT(GENERATE_XML): proc xsl
in = 'path/to/file/A.xml'
xsl = 'path/to/file/script.xsl'
out = 'path/to/file/final.xml';
MPRINT(GENERATE_XML): run;
NOTE: PROCEDURE XSL used (Total process time):
real time 19.61 seconds
cpu time 0.00 seconds
As it is such a small insert, literally appending 8 lines, I was wondering if it was just not possible to just read B.xml
through a data _null_
step and insert (using a put
statement for example) those 8 lines at the top of the xml file?