DATA Step, Macro, Functions and more

XML file

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:
Posts: 9,371

Re: XML file

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:

For more information on well-formed and valid XML, refer to these descriptions:

For more information on the XML Libname Engine:

For more information on using the XML Mapper to build an XML Map to aid in reading a file:

Some other papers/information:

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:

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.

Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation