Tag Archive for 'html-data-in-xml'

24
Oct

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"?>
<posts>
	<post>
		<msg>This is a <strong>message</strong></msg>
	</post>
</posts>
<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

		<msg>
			<![CDATA[
			This is a <strong>message</strong>
			]]>
		</msg>

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

VN:F [1.9.3_1094]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)



Search Website

Sponsored Ads

Sponsored Links

Sponsors

Sponsors

About Me

Me

Hello, Im Benny Chong. This blog is a proof that I have too much spare time to burn. 

I will be writing topics mainly on web design, application development, photography and other rubbish. Cheers