SIF Message Parsing made easy … with Siffer

Forgive the formatting of this post. But I wanted to share the XML parsing I added to Siffer with an example.

require 'rubygems'
require 'siffer'
xml = "<SIF_Message Version=\"2.3\" xmlns=\"http://www.sifinfo.org/infrastructure/2.x\">
<SIF_Ack>
<SIF_Header>
<SIF_MsgId>AB1058CD3261545A31905937B265CE01</SIF_MsgId>
<SIF_Timestamp>2006-02-18T08:39:40-08:00</SIF_Timestamp>
<SIF_SourceId>SifInfo_TestZIS</SIF_SourceId></SIF_Header>
<SIF_OriginalSourceId>RamseyLib</SIF_OriginalSourceId>
<SIF_OriginalMsgId>1298ACEF3261545A31905937B265CE01</SIF_OriginalMsgId>
<SIF_Status><SIF_Code>0</SIF_Code>
<SIF_Data><SIF_Message Version=\"2.3\"><SIF_Request>
<SIF_Header><SIF_MsgId>A3E90785EFDA330DACB00785EFDA330D</SIF_MsgId>
<SIF_Timestamp>2006-02-18T08:39:02-08:00</SIF_Timestamp><
SIF_SourceId>RamseySIS</SIF_SourceId></SIF_Header>
<SIF_Version>2.*</SIF_Version><SIF_MaxBufferSize>1048576</SIF_MaxBufferSize><
SIF_Query><SIF_QueryObject ObjectName=\"LibraryPatronStatus\" />
<SIF_ConditionGroup Type=\"None\"><SIF_Conditions Type=\"None\"><SIF_Condition>
<SIF_Element>@SIF_RefObject</SIF_Element><SIF_Operator>EQ</SIF_Operator>
<SIF_Value>StaffPersonal</SIF_Value></SIF_Condition></SIF_Conditions></SIF_ConditionGroup></SIF_Query>
</SIF_Request></SIF_Message></SIF_Data></SIF_Status></SIF_Ack></SIF_Message>"

msg = Message.parse(xml)
puts msg.is_a?(Ack)
puts msg.status.code == "0"

Notice that the msg object returned from parse is actually the Ack object and can return the attributes accordingly.

The way to do this yourself is the following:

gem install siffer -v 0.0.7

Then create a file with the proper require statements you see above. Grab an example SIF Message XML and call Message.parse. The parse method will return the proper object of the parsed messgae (i.e. Request message will return a Request object back).

There are edge cases yet to be debugged – but 90% of all SIF messages are now parsing and Siffer includes all SIF Message objects.

Stay tuned for PUSH/PULL Agents!

Category: Code Comment »


Leave a Reply



Back to top