Overview
• XML basics and Libname engine introduction
• Effectively reading XML files
• Introduction to the XML Mapper
•Writing XML files using SAS
• Common problems processing XML files
What is XML?
• XML is a set of rules used for defining &modeling structures
• XML is extensible & customizable
Its greatest strength
Its greatest weakness
XML Basics- Well Formed Files
Document has a single root element
• Elements nest properly
• No tag omission (close what you
open)
• Attributes must be quoted
• Special characters < > and & must
always be escaped
XML Basics- Well Formed Files
• XML is case sensitive
Anatomy of an XML file
<?xml version="1.0"?>
<workorder priority="high"datedue="09/30/2001">
<submitter>
<name first="Jennifer" last="Kyrnin" />
<email>html.guide@about.com</email>
<account number="11001100" />
Container or root XML Declaraton
Anatomy of an XML file
Copyr i g ht © 2012 , SAS Ins t i tut e Inc . Al l r ights reser ve d .
</submitter>
<project title="update aa051198.htm article">
<url>http://webdesign.com/aa051198.htm</url>
<description> new article</description>
</project>
</workorder>
Libname Engine Introduction
Release Engine Description
SAS 8.1 XML Export production
SAS 8.2 XML A bility to read added
with hot fix
SAS 9.1 XML
SAS 9.2 XML|XML92 Enhanced features
Libname Engine
Introduction
SAS 9.3|9.4 XML|XMLV2 XMLV2 is an alias
of XML92
Libname Engine Introduction-Processing XML
• Provides the ability to read and write XML files
• Requires that XML files be well formed for reading
• Reads and writes generic XML files by default
• Wildcards can be used to read all files in a directory
• Allows hierarchical files to be read by dynamically
generating Map files
• Namespaces are supported beginning with SAS 9.3
• Provides the ability to use XMLMap files for export as well
Libname Engine Introduction-Extended Functionality
of the XMLV2 Engine as import.
Effectively Reading XML Files
<?xml version="1.0" ?>
<TABLE>
<STUDENTS>
<ID> 0755 </ID>
<NAME> Brad Martin </NAME>
<ADDRESS> 1611 Glengreen </ADDRESS>
<CITY> Huntsville </CITY>
<STATE> Texas </STATE>
</STUDENTS>
<STUDENTS>
<ID> 1522 </ID>
<NAME> Zac Harvell </NAME>
<ADDRESS> 11900 Glenda </ADDRESS>
<CITY> Houston </CITY>
<STATE> Texas </STATE>
</STUDENTS>
</TABLE>
proc print data=test.students;
run;
ID NAME ADDRESS CITY STATE
0755 Brad Martin 1611 Glengreen Huntsville Texas
1522 Zac Harvell 11900 Glenda Houston Texas
<TABLE>
<STUDENTS Dept="Math">
<ID> 0755 </ID>
<NAME> Brad Martin </NAME>
<ADDRESS> 1611 Glengreen </ADDRESS>
<CITY> Huntsville </CITY>
<STATE> Texas </STATE>
</STUDENTS>
<STUDENTS Dept="CSC">
<ID> 1522 </ID>
<NAME> Zac Harvell </NAME>
<ADDRESS> 11900 Glenda </ADDRESS>
<CITY> Houston </CITY>
<STATE> Texas </STATE>
</STUDENTS>
</TABLE>
• XML basics and Libname engine introduction
• Effectively reading XML files
• Introduction to the XML Mapper
•Writing XML files using SAS
• Common problems processing XML files
What is XML?
• XML is a set of rules used for defining &modeling structures
• XML is extensible & customizable
Its greatest strength
Its greatest weakness
XML Basics- Well Formed Files
Document has a single root element
• Elements nest properly
• No tag omission (close what you
open)
• Attributes must be quoted
• Special characters < > and & must
always be escaped
XML Basics- Well Formed Files
• XML is case sensitive
Anatomy of an XML file
<?xml version="1.0"?>
<workorder priority="high"datedue="09/30/2001">
<submitter>
<name first="Jennifer" last="Kyrnin" />
<email>html.guide@about.com</email>
<account number="11001100" />
Container or root XML Declaraton
Anatomy of an XML file
Copyr i g ht © 2012 , SAS Ins t i tut e Inc . Al l r ights reser ve d .
</submitter>
<project title="update aa051198.htm article">
<url>http://webdesign.com/aa051198.htm</url>
<description> new article</description>
</project>
</workorder>
Libname Engine Introduction
Release Engine Description
SAS 8.1 XML Export production
SAS 8.2 XML A bility to read added
with hot fix
SAS 9.1 XML
SAS 9.2 XML|XML92 Enhanced features
Libname Engine
Introduction
SAS 9.3|9.4 XML|XMLV2 XMLV2 is an alias
of XML92
Libname Engine Introduction-Processing XML
• Provides the ability to read and write XML files
• Requires that XML files be well formed for reading
• Reads and writes generic XML files by default
• Wildcards can be used to read all files in a directory
• Allows hierarchical files to be read by dynamically
generating Map files
• Namespaces are supported beginning with SAS 9.3
• Provides the ability to use XMLMap files for export as well
Libname Engine Introduction-Extended Functionality
of the XMLV2 Engine as import.
Effectively Reading XML Files
<?xml version="1.0" ?>
<TABLE>
<STUDENTS>
<ID> 0755 </ID>
<NAME> Brad Martin </NAME>
<ADDRESS> 1611 Glengreen </ADDRESS>
<CITY> Huntsville </CITY>
<STATE> Texas </STATE>
</STUDENTS>
<STUDENTS>
<ID> 1522 </ID>
<NAME> Zac Harvell </NAME>
<ADDRESS> 11900 Glenda </ADDRESS>
<CITY> Houston </CITY>
<STATE> Texas </STATE>
</STUDENTS>
</TABLE>
Effectively Reading XML Files
Libname test xmlv2 'C:\students.xml';proc print data=test.students;
run;
ID NAME ADDRESS CITY STATE
0755 Brad Martin 1611 Glengreen Huntsville Texas
1522 Zac Harvell 11900 Glenda Houston Texas
Effectively Reading XML Files- Attributes Require an XMLMap
<?xml version="1.0" ?><TABLE>
<STUDENTS Dept="Math">
<ID> 0755 </ID>
<NAME> Brad Martin </NAME>
<ADDRESS> 1611 Glengreen </ADDRESS>
<CITY> Huntsville </CITY>
<STATE> Texas </STATE>
</STUDENTS>
<STUDENTS Dept="CSC">
<ID> 1522 </ID>
<NAME> Zac Harvell </NAME>
<ADDRESS> 11900 Glenda </ADDRESS>
<CITY> Houston </CITY>
<STATE> Texas </STATE>
</STUDENTS>
</TABLE>
Effectively Reading XML Files-Required Structure
Problem.XML
__________________________________________
<xml version=“1.0” ?> Declaration statement
__________________________________________
<Table> SAS recognizes the first instance tag as
the root enclosing element, which is the
document container.
_________________________________________________
<Students> Starting with the second-level instance tag, SAS begins to scan for columns.
________________________________________________
<Student> SAS expects to start reading data here and
because there is no data an error occurs
__________________________________________________
<ID> 0755 </ID>
<NAME> Brad Martin</NAME>
<ADDRESS> 1611 Glengreen
</ADDRESS>
<CITY> Huntsville </CITY>
<STATE> Texas </STATE>
</Student>
</Students>
</Table>
_______________________________________________
Comments
Post a Comment