Home > Uncategorized > Parsing WDDX with a Regular Expression

Parsing WDDX with a Regular Expression

WDDX is an XML Serialization format native to ColdFusion, and can be parsed in .NET using WDDX.NET (http://wddxnet.codeplex.com/)  – However, it is an extra assembly in your deployment, and sometimes, something more simple (but less correct) may be handy.

Take these two WDDX packets for example;

<wddxPacket version=’1.0′><header/><data><struct>
<var name=’NOMARP’><string>Madrid</string></var>
<var name=’TYPCLA’><string>TOUTES</string></var>
<var name=’DIRECT’><number>1.0</number></var>
<var name=’NOMCIE’><string>Iberia</string></var>
<var name=’DATDEP’><string>070912</string></var>
<var name=’TAXES’><number>53.0</number></var>
<var name=’CDEARP’><string>MAD</string></var>
<var name=’REDUC’><number>0.0</number></var>
<var name=’TOTALD’><number>109.0</number></var>
<var name=’IDPROP’><string>MDcwMTExMjM0OTJBUlVNQURBTENJQiBXMDMwOTMwMzE5UkVTQVhNTCAgIDEyMzQ5Mg==</string></var>
<var name=’REMMTE’><string>0</string></var>
<var name=’DATRET’><string>140912</string></var>
<var name=’CODCIE’><string>IB</string></var>
<var name=’REMMTA’><string>0</string></var>
<var name=’REMMTB’><string>0</string></var>
<var name=’TAXADT’><string>53.63</string></var>
<var name=’QBDOSS’><number>56.0</number></var>
<var name=’RECODE’><string></string></var>
<var name=’TAXBEB’><string>0</string></var>
<var name=’RELIBL’><string>-</string></var>
<var name=’TAXENF’><string>0</string></var>
<var name=’PRIXE’><number>0.0</number></var>
<var name=’REMSSE’><string></string></var>
<var name=’PRIXB’><number>0.0</number></var>
<var name=’NUMSEG’><number>2.0</number></var>
<var name=’REMSSB’><string></string></var>
<var name=’SEQPRO’><number>1.0</number></var>
<var name=’PRIXA’><number>56.0</number></var>
<var name=’REMSSA’><string></string></var>
<var name=’TYPRO’><string></string></var>
<var name=’MSGREM’><string>Nant</string></var>
<var name=’FLGCIE’><string>IB_small.gif</string></var></struct></data></wddxPacket>

<wddxPacket version=’1.0′><header/><data><recordset rowCount=’2′ fieldNames=’SEQPRO,IDSEG,SEQSEG,CODSEG,SEQVOL,DATDEP,HEUDEP,DATARR,HEUARR,VILDEP,VILARR,CIESEG,CIENOM,NUMVOL,DEPNOM,ARRNOM,TYPEQU,OPRCIE,NESCAL’ type=’coldfusion.sql.QueryTable’>
<field name=’SEQPRO’><string>1</string><string>1</string></field>
<field name=’IDSEG’><string>NahjbcJUNFNIRaadfeLZw</string><string>CbejbcJNIRUNFaadgbLZw</string></field>
<field name=’SEQSEG’><number>1.0</number><number>2.0</number></field>
<field name=’CODSEG’><string>A</string><string>R</string></field>
<field name=’SEQVOL’><number>1.0</number><number>2.0</number></field>
<field name=’DATDEP’><string>070912</string><string>140912</string></field>
<field name=’HEUDEP’><string>2255</string><string>2140</string></field>
<field name=’DATARR’><string>070912</string><string>140912</string></field>
<field name=’HEUARR’><string>2355</string><string>2240</string></field>
<field name=’VILDEP’><string>MAD</string><string>ALC</string></field>
<field name=’VILARR’><string>ALC</string><string>MAD</string></field>
<field name=’CIESEG’><string>IB</string><string>IB</string></field>
<field name=’CIENOM’><string>Iberia</string><string>Iberia</string></field>
<field name=’NUMVOL’><string>354</string><string>361</string></field>
<field name=’DEPNOM’><string>Madrid</string><string>Alicante</string></field>
<field name=’ARRNOM’><string>Alicante</string><string>Madrid</string></field>
<field name=’TYPEQU’><string>320</string><string>320</string></field>
<field name=’OPRCIE’><string>—</string><string>—</string></field>
<field name=’NESCAL’><string>0</string><string>0</string></field></recordset></data></wddxPacket>

So, for this format, I used the Regular expression:

const string strWddxRegex = @”name..(?<Name>\w+)..(.(string|number).(?<Value>[\w.=]*)..(string|number).)+”;

Which served the purpose!

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: