Previous Page | Next Page

Importing XML Documents

Importing Concatenated XML Documents

For a file that is a concatenation of multiple XML documents, you can use the XML engine to import the file. To import concatenated XML documents, simply specify the LIBNAME statement option XMLCONCATENATE=YES.

Note:   Use XMLCONCATENATE=YES cautiously. If an XML document consists of concatenated XML documents, the content is not standard XML construction. The option is provided for convenience, not to encourage invalid XML markup.  [cautionend]

This example imports the following file named ConcatStudents.XML, which consists of two XML documents:

<?xml version="1.0" ?> 
<LIBRARY>   
   <STUDENTS>  
      <ID>1345</ID>
      <NAME>Linda Kay</NAME>
      <SCHOOL>Bellaire</SCHOOL>
      <CITY>Houston</CITY>
   </STUDENTS>
   <STUDENTS>   
      <ID>2456</ID>
      <NAME>Chas Wofford</NAME>
      <SCHOOL>Sam Houston</SCHOOL>
      <CITY>Houston</CITY>
   </STUDENTS>
   <STUDENTS>   
      <ID>3567</ID>
      <NAME>Jerry Kolar</NAME>
      <SCHOOL>Sharpstown</SCHOOL>
      <CITY>Houston</CITY>
   </STUDENTS>    
</LIBRARY>

<?xml version="1.0" ?> 
<LIBRARY>   
   <STUDENTS>  
      <ID>1234</ID>
      <NAME>Brad Martin</NAME>
      <SCHOOL>Reagan</SCHOOL>
      <CITY>Austin</CITY>
   </STUDENTS>
   <STUDENTS>   
      <ID>2345</ID>
      <NAME>Zac Harvell</NAME>
      <SCHOOL>Westwood</SCHOOL>
      <CITY>Austin</CITY>
   </STUDENTS>
   <STUDENTS>   
      <ID>3456</ID>
      <NAME>Walter Smith</NAME>
      <SCHOOL>Bowie</SCHOOL>
      <CITY>Austin</CITY>
   </STUDENTS>
</LIBRARY>

First, using the default XML engine behavior, which does not support concatenated XML documents (XMLCONCATENATE=NO), the following SAS program imports the first XML document, which consists of three observations, and produces an error for the second XML document:

libname concat xml '/u/My Documents/XML/ConcatStudents.xml';                                              

proc datasets library=concat;

SAS Log Output

NOTE: Libref CONCAT was successfully assigned as follows:
      Engine:        XML
      Physical Name: /u/My Documents/XML/ConcatStudents.xml
20   proc datasets library=concat;
ERROR: "xml" is illegal as a processing-instruction target name.
       encountered during XMLMap parsing
       occurred at or near line 23, column 7

                                            Directory

       Libref         CONCAT
       Engine         XML
       Physical Name  /u/My Documents/XML/ConcatStudents.xml
       XMLType        GENERIC
       XMLMap         NO XMLMAP IN EFFECT


                                                    Member
                                       #  Name      Type

                                       1  STUDENTS  DATA

Specifying the LIBNAME statement option XMLCONCATENATE=YES enables the XML engine to import the concatenated XML documents as one SAS data set:

libname concat xml '/u/My Documents/XML/ConcatStudents.xml' xmlconcatenate=yes;                                              

proc print data=concat.students;
run;

PROC PRINT Output

                               The SAS System                                     1

            Obs    CITY       SCHOOL         NAME                  ID

              1    Houston    Bellaire       Linda Kay           1345
              2    Houston    Sam Houston    Chas Wofford        2456
              3    Houston    Sharpstown     Jerry Kolar         3567
              4    Austin     Reagan         Brad Martin         1234
              5    Austin     Westwood       Zac Harvell         2345
              6    Austin     Bowie          Walter Smith        3456

Previous Page | Next Page | Top of Page