| Getting Started with the XML Engine |
| Assigning a Libref to an XML Document |
The XML engine works much like other SAS engines. That is, you execute a LIBNAME statement in order to assign a libref and specify an engine. You then use that libref throughout the SAS session where a libref is valid.
However, instead of the libref being associated with the physical location of a SAS library, the libref for the XML engine is associated with a physical location of an XML document. When you use the libref that is associated with an XML document, SAS either translates the data in a SAS data set into XML markup or translates the XML markup into SAS format.
| Importing an XML Document |
To import an XML document as a SAS data set, the following LIBNAME statement assigns a libref to a specific XML document and specifies the XML engine:
libname myxml xml 'C:\My Files\XML\Students.xml';
Executing the DATASETS procedure shows that SAS interprets the XML document as a SAS data set:
proc datasets library=myxml;
PROC DATASETS Output for MYXML Library
Directory
Libref MYXML
Engine XML
Physical Name C:\My Files\XML\Students.xml
XMLType GENERIC
XMLMap NO XMLMAP IN EFFECT
Member
# Name Type
1 STUDENTS DATA
The PRINT procedure results in the following output:
proc print data=myxml.students; run;
PROC PRINT Output of SAS Data Set MYXML.STUDENTS
The SAS System
Obs STATE CITY ADDRESS NAME ID
1 Texas Huntsville 1611 Glengreen Brad Martin 755
2 Texas Houston 11900 Glenda Zac Harvell 1522
| Exporting an XML Document |
To export an XML document from a SAS data set, the LIBNAME statement for the XML engine assigns a libref to an XML document to be created from a SAS data set.
In the following code, the first LIBNAME statement assigns the libref MYFILES to the SAS library that contains the SAS data set Singers. The second LIBNAME statement assigns the libref MYXML to the physical location of the XML document that is to be exported from Myfiles.Singers:
libname myfiles 'C:\My Files\'; libname myxml xml 'C:\My Files\XML\Singers.xml';
Executing these statements creates the XML document named Singers.XML:
data myxml.Singers; set myfiles.Singers; run;
<?xml version="1.0" encoding="windows-1252" ?>
<TABLE>
<SINGERS>
<FirstName> Tom </FirstName>
<Age> 62 </Age>
</SINGERS>
<SINGERS>
<FirstName> Willie </FirstName>
<Age> 70 </Age>
</SINGERS>
<SINGERS>
<FirstName> Randy </FirstName>
<Age> 43 </Age>
</SINGERS>
</TABLE>
Copyright © 2007 by SAS Institute Inc., Cary, NC, USA. All rights reserved.