Skip to main content

XML Engine Tutorial

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>


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

Popular posts from this blog

CSS Tutorial step by step

CSS   Introduction Cascading Style Sheets   (CSS) is a   style sheet language   used for describing the   look and formatting   of a document written in a markup language . While most often used to style   web pages   and user interfaces written in   HTML   and   XHTML . CSS is a cornerstone specification of   the web   and almost all web pages use CSS style sheets to describe their presentation. CSS is designed primarily to enable   the separation of document content from document presentation , including elements such as the   layout ,   colors , and   fonts .   This separation can improve content   accessibility , provide more flexibility and control in the specification of presentation characteristics, enable multiple pages to share formatting, and reduce complexity and repetition in the structural content (such as by allowing for   table less web design ). It   obvia...

TypingPad

TypingPad is a simple  text editor  for  Microsoft Windows  and a basic text-editing program which enables computer users to create documents. It was first released  in 2018, and has been included in  versions of  Microsoft Windows .  Features TypingPad  is a common text-only ( plain text ) editor. The resulting files—typically saved with the  .txt  extension—have no format tags or styles, making the program suitable for editing system files to use in a  DOS  environment and, occasionally, source code for later  compilation or  execution , usually through a  command prompt . It is also useful for its negligible use of system resources; making for quick load time and processing time, especially on under-powered hardware. TypingPad supports both left-to-right and right-to-left based languages. Historically,  TypinfPad offers only the most basic text manipulation functions, such as finding text. ...

WIFI Hack in two step by image

1. Open cmd   type netsh wlan show profiles and choose a connected network. 2.  Again type netsh wlan show profiles Discovery key=clear.