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" ?> 
      <NAME>Linda Kay</NAME>
      <NAME>Chas Wofford</NAME>
      <SCHOOL>Sam Houston</SCHOOL>
      <NAME>Jerry Kolar</NAME>

<?xml version="1.0" ?> 
      <NAME>Brad Martin</NAME>
      <NAME>Zac Harvell</NAME>
      <NAME>Walter Smith</NAME>

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


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

                                       #  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;


                               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