Spry with HTML codes/CDATA in XML

I was assigned with a mini project to do a team notice board that read XML files using Spry.
While reading plain text in the XML is straightforward,  reading of HTML codes like <br> tag, <b> tag are not.

<?xml version="1.0" encoding="utf-8"?>
		<msg>This is a <strong>message</strong></msg>
<msg>This is a <strong>message</strong></msg>

When you type these tags(e.g. strong tag as above) in the XML, it simply ‘breaks’ the XML formatting and would thus caused an error when it is loaded with Spry

So… to input HTML data in XML…

1. Use CDATA wrapper in your XML

			This is a <strong>message</strong>

2. Set setColumnType(“msg”, “html”) to your Spry dataset for that field

var ds1 = new Spry.Data.XMLDataSet("data.xml", "posts/post");
ds1.setColumnType("msg", "html");

Spry with HTML Data Source Code

Spry with HTML Data Online Demo

Similar Posts:

VN:F [1.9.22_1171]
Rating: 8.6/10 (5 votes cast)
Spry with HTML codes/CDATA in XML, 8.6 out of 10 based on 5 ratings