LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (October 2009, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 28 Oct 2009 16:48:17 -0500
Reply-To:     matt.pettis@THOMSONREUTERS.COM
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Matthew Pettis <matt.pettis@THOMSONREUTERS.COM>
Subject:      Re: reading in XML data
Comments: To: eli@ACERCORNER.COM
In-Reply-To:  <51307900-c9d7-4642-9c40-a957370c86bc@m38g2000yqd.googlegroups.com>
Content-Type: text/plain; charset="us-ascii"

OK:

Your XML example is not well-formed. 3 problems: - Your line '<?xml version="1."?>' should probably be: '<?xml version="1.0"?>' -- otherwise, things don't parse. - You don't close the '<test>' tag. - You don't close the '<frame>' tag.

Fig. 1 has what I think should be your proper XML. I saved it in: c:\temp\sasl.xml

Fig.2 has the contents of the .map file I created. For this example, I saved it in: c:\temp\sasl.map

Fig. 3 has some sample SAS code that reads the XML. I saved it in: c:\temp\sasl.sas

As long as your input xml is well-formed, you should be able to tinker with the .sas example to make it read in your files.

HTH, Matt

=== Fig. 1 : XML that is fixed (c:\temp\sasl.xml)=== <?xml version="1.0"?> <test> <frame value="1"> <node name="node1"> <attribute name="a1" value="1"></attribute> <attribute name="a2" value="0"></attribute> <attribute name="a3" value="0"></attribute> <attribute name="a4" value="0"></attribute> <attribute name="a5" value="4.681483335"></attribute> <attribute name="a6" value="1.870251177"></attribute> <attribute name="a7" value="7.635592512"></attribute> <attribute name="a8" value="1"></attribute> <attribute name="a9" value="1"></attribute> <attribute name="a10" value="1"></attribute> </node> <node name="node2"> <attribute name="a1" value="1"></attribute> <attribute name="a2" value="-0.009869254665"></attribute> <attribute name="a20" value="0.03694603221"></attribute> <attribute name="a21" value="0.1336173431"></attribute> <attribute name="a6" value="0"></attribute> <attribute name="a10" value="0"></attribute> <attribute name="a17" value="0"></attribute> <attribute name="a50" value="1"></attribute> <attribute name="a55" value="1"></attribute> <attribute name="a56" value="1"></attribute> </node> </frame> </test> === End Fig. 1 ===================

=== Fig. 2: The map file that you will need. (c:\temp\sasl.map)=== <?xml version="1.0" encoding="windows-1252"?>

<!-- ############################################################ --> <!-- 2009-10-28T15:39:41 --> <!-- SAS XML Libname Engine Map --> <!-- Generated by XML Mapper, 9.1.0300.20040709.2028 --> <!-- ############################################################ --> <!-- ### Validation report ### --> <!-- ############################################################ --> <!-- Map validation completed successfully. --> <!-- ############################################################ --> <SXLEMAP xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="SASLMAP" version="1.2" xsi:noNamespaceSchemaLocation="http://www.sas.com/xml/schema/sxle12.xsd" >

<!-- ############################################################ --> <TABLE name="test"> <TABLE-PATH syntax="XPath">/test/frame/node/attribute</TABLE-PATH>

<COLUMN name="attr_name"> <PATH syntax="XPath">/test/frame/node/attribute/@name</PATH> <TYPE>character</TYPE> <DATATYPE>string</DATATYPE> <LENGTH>3</LENGTH> </COLUMN>

<COLUMN name="frame_value" retain="YES"> <PATH syntax="XPath">/test/frame/@value</PATH> <TYPE>numeric</TYPE> <DATATYPE>integer</DATATYPE> </COLUMN>

<COLUMN name="node_name" retain="YES"> <PATH syntax="XPath">/test/frame/node/@name</PATH> <TYPE>character</TYPE> <DATATYPE>string</DATATYPE> <LENGTH>5</LENGTH> </COLUMN>

<COLUMN name="attr_value"> <PATH syntax="XPath">/test/frame/node/attribute/@value</PATH> <TYPE>numeric</TYPE> <DATATYPE>double</DATATYPE> </COLUMN>

</TABLE>

</SXLEMAP> === End Fig. 2 =================================

=== Fig. 3: Using the .map file to read the .xml file into a SAS dataset. === /*********************************************************************** ********* * Generated by XML Mapper, 9.1.0300.20040709.2028

************************************************************************ ********/

/* * ENVIRONMENT */ filename sasl 'C:\temp\sasl.xml'; filename SXLEMAP 'C:\temp\sasl.map'; libname sasl xml xmlmap=SXLEMAP access=READONLY;

/* * CATALOG */

proc datasets lib=sasl; run;

/* * SAMPLE USAGE */

title 'Table test'; proc contents data=sasl.test varnum; run; proc print data=sasl.test; run; === End Fig. 3 ==============================================================

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Eli Kling Sent: Wednesday, October 28, 2009 5:40 AM To: SAS-L@LISTSERV.UGA.EDU Subject: reading in XML data

I am having trouble reading an xml file I got from a client (well I have 50 of them). Before I go to the good old data step and parse it myself, I wonder if there is an elegant way of doing this. The structure is a follows:

<?xml version="1."?> <test> <frame value="1"> <node name="node1"> <attribute name="a1" value="1"></attribute> <attribute name="a2" value="0"></attribute> <attribute name="a3" value="0"></attribute> <attribute name="a4" value="0"></attribute> <attribute name="a5" value="4.681483335"></attribute> <attribute name="a6" value="1.870251177"></attribute> <attribute name="a7" value="7.635592512"></attribute> <attribute name="a8" value="1"></attribute> <attribute name="a9" value="1"></attribute> <attribute name="a10" value="1"></attribute> </node> <node name="node2"> <attribute name="a1" value="1"></attribute> <attribute name="a2" value="-0.009869254665"></attribute> <attribute name="a20" value="0.03694603221"></attribute> <attribute name="a21" value="0.1336173431"></attribute> <attribute name="a6" value="0"></attribute> <attribute name="a10" value="0"></attribute> <attribute name="a17" value="0"></attribute> <attribute name="a50" value="1"></attribute> <attribute name="a55" value="1"></attribute> <attribute name="a56" value="1"></attribute> </node>

Yes, each node has its own attributes where some are shared - but this is probably a read hering.


Back to: Top of message | Previous page | Main SAS-L page