
| home | AJAX (8) || C#.NET (7) || Coldfusion Development (16) || DHTML (15) || Flash Development (19) || jQuery (8) || MSSQL (2) || UNIX (10) |
| 2.21.08 | Convert ADODB XML To JSON Through XSLT |
Hot on the heels of my ADOtoWDDX XSLT1.0 script, here’s a way to take the ADODB XML recordSet and parse the data into a JSON array of objects (again, this will work with XSLT 1.0):
Here’s the XSLT:
Download this code: ADOtoJSON.xls
The example above contains a “escape-single-quote” function (aka template) to use to escape all single quotes which need to be escaped for the JSON document to be valid. This is based off several widely published concepts on using simple recursion similar to a C++ String Tokenizer concept. Of course, this is only for the 1999 XSL Transformations (XSLT) Version 1.0 specification - for maximum compatibility. XSLT2.0 has a nice replace() function which enables regular expressions, so nice.
Here’s an example ADODB XML string:
...
removed AttributeType information here
...
</s:ElementType>
</s:Schema>
<rs:data>
<z:row guest_no='1808354000000' first_name='JIMBOB' last_name='PALMERSKI'
birth_date='1980-06-01T00:00:00' address_id='927000000000'
area_code='(555)' phone='121-2121' area_cod2=' ' phone2=' '
address='2443 unit 15''"' city='mammoth lakes''2'
state='AK ' zip='12345'/>
<z:row guest_no='1750384000000' first_name='WEBOPS' last_name='RULEZ;'
birth_date='1981-01-01T00:00:00'/>
</rs:data>
</xml>
Download this code: ADO.xml
And here’s the XSLT actual transformation output:
[
{
guest_no:'1808354000000',
first_name:'JIMBOB',
last_name:'PALMERSKI',
birth_date:'1980-06-01T00:00:00',
address_id:'927000000000',
area_code:'(555)',
phone:'121-2121',
area_cod2:' ',
phone2:' ',
address:'2443 unit 15\'\'"',
city:'mammoth lakes\'\'2',
state:'AK ',
zip:'12345'
},
{
guest_no:'1750384000000',
first_name:'WEBOPS',
last_name:'RULEZ;',
birth_date:'1981-01-01T00:00:00'
}
]
This is glorious for output conversion from the bloated ADODB default XML recordSet - especially when you’re not using the ADODB assemblies or are not in the windows environment.
| Nikolaj on 2.22.08 at 10am |
|
This makes my tummy ache. |
1 Comment