Exporting an XML Document with Separate Metadata

This example exports an XML document from a SAS data set and specifies a separate file to contain metadata-related information. The example illustrates using the XMLMETA= option and XMLSCHEMA= option and uses a SAS data set that was created from a Microsoft Access database.
First, here is the CONTENTS procedure output for the SAS data set INPUT.SUPPLIERS:
CONTENTS Procedure Output for INPUT.SUPPLIERS
CONTENTS Procedure Output for INPUT.SUPPLIERS
The following SAS program exports an XML document from the SAS data set INPUT.SUPPLIERS:
libname input 'c:\My Documents\myfiles'; 1

filename xsd 'c:\My Documents\XML\suppliers.xsd'; 2

libname output xml 'c:\My Documents\XML\suppliers.xml' xmltype=msaccess
   xmlmeta=schemadata xmlschema=xsd; 3

data output.suppliers; 4
   set input.suppliers;
run;     
1 The first LIBNAME statement assigns the libref INPUT to the physical location of the SAS library that stores the SAS data set SUPPLIERS.
2 The FILENAME statement assigns the fileref XSD to the physical location of the separate external file that will contain the metadata-related information.
3 The second LIBNAME statement assigns the libref OUTPUT to the physical location of the file (complete pathname, filename, and file extension) that will store the exported XML document and specifies the XML engine. The engine options
  • XMLTYPE=MSACCESS supports the markup standards for a Microsoft Access database.
  • XMLMETA=SCHEMADATA specifies to include both data content and metadata-related information in the exported markup.
  • XMLSCHEMA= specifies the fileref that is assigned, in the previous FILENAME statement, to the separate external file that will contain the metadata-related information.
4 The DATA step reads the SAS data set INPUT.SUPPLIERS and writes its data content in Microsoft Access database XML markup to the XML document Suppliers.XML, and then writes the metadata information to the separate external file Suppliers.XSD.
Part of the resulting XML document is shown in XML Document Suppliers.XML. The separate metadata information is shown in Separate Metadata Information Suppliers.XSD.
XML Document Suppliers.XML
<?xml version="1.0" encoding="windows-1252" ?>
   <dataroot  xmlns:xs="http://www.w3.org/2001/XMLSchema"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xmlns:od="urn:schemas-microsoft-com:officedata"
              xsi:noNamespaceSchemaLocation="suppliers.xsd">
      <SUPPLIERS>
         <HOMEPAGE/>
         <FAX/>
         <PHONE>(272) 444-2222</PHONE>
         <COUNTRY>UK</COUNTRY>
         <POSTALCODE>EC1 4SD</POSTALCODE>
         <REGION/>
         <CITY>London</CITY>
         <ADDRESS>49 Franklin St.</ADDRESS>
         <CONTACTTITLE>Purchasing Manager</CONTACTTITLE>
         <CONTACTNAME>Charlotte Smith</CONTACTNAME>
         <COMPANYNAME>Exotic Flowers</COMPANYNAME>
         <SUPPLIERID>1</SUPPLIERID>
      </SUPPLIERS>
      <SUPPLIERS>
         <HOMEPAGE>#MYCAJUN.HTM#</HOMEPAGE>
         <FAX/>
         <PHONE>(512) 284-3677</PHONE>
         <COUNTRY>USA</COUNTRY>
         <POSTALCODE>70117</POSTALCODE>
         <REGION>LA</REGION>
         <CITY>New Orleans</CITY>
         <ADDRESS>P.O. Box 78934</ADDRESS>
         <CONTACTTITLE>Order Administrator</CONTACTTITLE>
         <CONTACTNAME>Shelley Martin</CONTACTNAME>
         <COMPANYNAME>New Orleans Cajun Foods</COMPANYNAME>
         <SUPPLIERID>2</SUPPLIERID>
      </SUPPLIERS>
         .
         .
         .
   </dataroot>
Separate Metadata Information Suppliers.XSD
<?xml version="1.0" encoding="windows-1252" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:od="urn:schemas-microsoft-com:officedata">
   <xs:element name="dataroot">
      <xs:complexType>
         <xs:sequence>
            <xs:element ref="SUPPLIERS"  minOccurs="0" maxOccurs="unbounded" />
         </xs:sequence>
      </xs:complexType>
   </xs:element>
   <xs:element name="SUPPLIERS">
      <xs:complexType>
         <xs:sequence>
            <xs:element name="HOMEPAGE" minOccurs="0"
                        od:jetType="text" od:sqlSType="nvarchar">
               <xs:simpleType>
                  <xs:restriction base="xs:string">
                     <xs:maxLength value="94" />
                  </xs:restriction>
               </xs:simpleType>
            </xs:element>
            <xs:element name="FAX" minOccurs="0"
                        od:jetType="text" od:sqlSType="nvarchar">
               <xs:simpleType>
                  <xs:restriction base="xs:string">
                     <xs:maxLength value="15" />
                  </xs:restriction>
               </xs:simpleType>
            </xs:element>
            <xs:element name="PHONE" minOccurs="0"
                        od:jetType="text" od:sqlSType="nvarchar">
               <xs:simpleType>
                  <xs:restriction base="xs:string">
                     <xs:maxLength value="15" />
                  </xs:restriction>
               </xs:simpleType>
            </xs:element>
            <xs:element name="COUNTRY" minOccurs="0"
                        od:jetType="text" od:sqlSType="nvarchar">
               <xs:simpleType>
                  <xs:restriction base="xs:string">
                     <xs:maxLength value="11" />
                  </xs:restriction>
               </xs:simpleType>
            </xs:element>
            <xs:element name="POSTALCODE" minOccurs="0"
                        od:jetType="text" od:sqlSType="nvarchar">
               <xs:simpleType>
                  <xs:restriction base="xs:string">
                     <xs:maxLength value="8" />
                  </xs:restriction>
               </xs:simpleType>
            </xs:element>
            <xs:element name="REGION" minOccurs="0"
                        od:jetType="text" od:sqlSType="nvarchar">
               <xs:simpleType>
                  <xs:restriction base="xs:string">
                     <xs:maxLength value="8" />
                  </xs:restriction>
               </xs:simpleType>
            </xs:element>
            
<xs:element name="CITY" minOccurs="0"
                        od:jetType="text" od:sqlSType="nvarchar">
               <xs:simpleType>
                  <xs:restriction base="xs:string">
                     <xs:maxLength value="13" />
                  </xs:restriction>
               </xs:simpleType>
            </xs:element>
            <xs:element name="ADDRESS" minOccurs="0"
                        od:jetType="text" od:sqlSType="nvarchar">
               <xs:simpleType>
                  <xs:restriction base="xs:string">
                     <xs:maxLength value="45" />
                  </xs:restriction>
               </xs:simpleType>
            </xs:element>
            <xs:element name="CONTACTTITLE" minOccurs="0"
                        od:jetType="text" od:sqlSType="nvarchar">
               <xs:simpleType>
                  <xs:restriction base="xs:string">
                     <xs:maxLength value="28" />
                  </xs:restriction>
               </xs:simpleType>
            </xs:element>
            <xs:element name="CONTACTNAME" minOccurs="0"
                        od:jetType="text" od:sqlSType="nvarchar">
               <xs:simpleType>
                  <xs:restriction base="xs:string">
                     <xs:maxLength value="26" />
                  </xs:restriction>
               </xs:simpleType>
            </xs:element>
            <xs:element name="COMPANYNAME" minOccurs="0"
                        od:jetType="text" od:sqlSType="nvarchar">
               <xs:simpleType>
                  <xs:restriction base="xs:string">
                     <xs:maxLength value="38" />
                  </xs:restriction>
               </xs:simpleType>
            </xs:element>
            <xs:element name="SUPPLIERID" minOccurs="0"
                        od:jetType="double" od:sqlSType="double" type="xs:double" />
         </xs:sequence>
      </xs:complexType>
   </xs:element>
</xs:schema>