DATA Step, Macro, Functions and more

XML file

Reply
New Contributor
Posts: 2

XML file

I need to read in an XML file that comes all in one string. Here is an example with three records. The current string I am using is currently at length 968,273 and could easily be longer. We will be receiving these strings from an MQ server on our mainframe - we are fetching them to the PC and this is how they appear. The example below is only length 3830. I am wondering what would be the best way to read this in. I want to use only a single data step (at most) and have one record per item (there may be multiple items per ResolvedRequest - see that repeats.

Just imagine the following all on one line:
SAS Super FREQ
Posts: 8,743

Re: XML file

Hi:
White space in an XML file is generally ignored, so the fact that the file comes as one long string should not be horrible to deal with using the SAS XML Libname Engine (SXLE) -- as long as the file is well-formed. You would have to try with the WHOLE file -- not just a snippet of the XML -- because copying a snippet might make the XML be ill-formed -- but I'd recommend trying the XML Mapper application and/or the SAS XML Libname Engine.
Assuming that
1) the XML is well-formed and
2) the XML is valid (or follows some "rules" set forth in a DTD or Schema)

You should be able to read it with the SAS XML Libname Engine. Actually, SAS doesn't -really- care whether there is a DTD or Schema definition for the XML file -- but YOU should know or be able to find out whether the XML elements follow the rules set forth in a DTD or Schema. An XML file that conforms to a DTD or Schema will be easier to deal with in the long run because when/if you encounter a tag or element that you have not seen previously, you will be able to find out information from the DTD or Schema -- such as the proper nesting, the proper number of possible occurences, whether the element contains character data or other types of data (depending on whether the definition is coming from a DTD or a Schema).

If you cannot read your file directly with the XML Libname Engine (because it has too many nested levels), you may be able to "map" the nested levels to SAS variables using the XML Mapper to build an XML Map file. The difference between a "generic" XML file and a non-hierarchical file is described here:
http://support.sas.com/onlinedoc/913/getDoc/en/engxml.hlp/a002592089.htm

For more information on well-formed and valid XML, refer to these descriptions:
http://en.wikipedia.org/wiki/Well-formed_XML

For more information on the XML Libname Engine:
http://support.sas.com/rnd/base/xmlengine/sxle913/usersguide913.htm

For more information on using the XML Mapper to build an XML Map to aid in reading a file:
http://support.sas.com/onlinedoc/913/getDoc/en/engxml.hlp/a002484804.htm

Some other papers/information:
http://www2.sas.com/proceedings/forum2008/099-2008.pdf
http://www2.sas.com/proceedings/sugi30/099-30.pdf
http://www2.sas.com/proceedings/sugi29/119-29.pdf
http://www2.sas.com/proceedings/forum2007/100-2007.pdf

And, here is some specific application messaging information for WebSphereMQ and MSMQ in the context of the SAS Enterprise Intelligence Platform and SAS Integration Technologies:
http://support.sas.com/rnd/itech/doc9/dev_guide/messageq/index.html

If you run into issues or are still uncertain after reading all the material, you may want to work with Tech Support on the appropriate way to read this XML data.

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