BookmarkSubscribeRSS Feed
Wendi
Calcite | Level 5
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:
1 REPLY 1
Cynthia_sas
SAS Super FREQ
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

sas-innovate-2024.png

Today is the last day to save with the early bird rate! Register today for just $695 - $100 off the standard rate.

 

Plus, pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 540 views
  • 0 likes
  • 2 in conversation