DATA Step, Macro, Functions and more

Complex XML and XMLMap

Reply
Contributor
Posts: 32

Complex XML and XMLMap

Running SAS 9.2, Phase 2 (TS2M0)
Can XMLMap assist with creating a SAS dataset such as the following XML describes:


Value
etc...


Value
etc

Value
etc




I don't have a schema file (XSD) yet.
- There can be 1 to many Reports in the file
- The subrecord section can occur 0 to unbounded

When we tried to read a file with one record, we ended up with Header, Info and Subrecord datasets, and many of the fields were set to missing. XML engine, tried several XMLTYPES (did not use XMLMAP).

I need the following from the 1 report record:
Header, Info and unique subrecord(s), 1 obs. per subrecord, header and info repeating. So if there were 3 subrecords within the one record, I'd have 3 records with the other fields carrying thru.

Can this be done within SAS using the mapper, XML or XML92 engines? We are under a tight deadline. Any ideas appreciated.
SAS Super FREQ
Posts: 8,740

Re: Complex XML and XMLMap

Hi:
I'm confused....this XML describes one or more REPORTS and you want to convert the report information into a -single- SAS dataset??? I believe this is the kind of thing you will definitely need to do with an XMLMAP to read the ????? data/report.

Is there data in the XML that is all that needs to be extracted????? Do you have an example of a "real" file. Using the XMLMapper (which is a Java application that allows you to map your XML to a SAS dataset), you can map how you want your SAS dataset to be built. Or, you could try writing the map syntax on your own.

By default, the SAS XML Libname engine expects very regular, non-hierarchical (flat) XML to read. Your XML file needs to be flat (one root tag, one observation boundary tag, one tag for every field), like this in order to read it without an XML Map:
[pre]
<?xml version="1.0"?>
<gifttable>
<giftidea>
<Name>Alan</Name>
<Idea>Books</Idea>
<Limit>$60</Limit>
</giftidea>
<giftidea>
<Name>Barb</Name>
<Idea>Jewelry</Idea>
<Limit>$25</Limit>
</giftidea>
<giftidea>
<Name>Carl</Name>
<Idea>Bike Gear</Idea>
<Limit>$75</Limit>
</giftidea>
. . . more tags . . .
</gifttable>

[/pre]

In the above XML, I have the required XML processing instruction; one root tag GIFTABLE, one observation boundary that contains my variables GIFTIDEA, and 3 tags for 3 fields, NAME, IDEA and LIMIT. So, my SAS variables would become NAME, IDEA and LIMIT and every observation would be composed of the tags that were contained within one <GIFTIDEA>/</GIFTIDEA> pair of tags.

...If your XML file is not "flat" like this, then the only way to deal with the file is 1) transform the XML to be flatter (using 3rd party tools or an XSL transform) so you can read it with the "vanilla" SAS XML Libname Engine or 2) read the file with an XML Map.

Here is a resource page:
http://support.sas.com/rnd/base/xmlengine/index.html

cynthia
Ask a Question
Discussion stats
  • 1 reply
  • 134 views
  • 0 likes
  • 2 in conversation