Archive for the 'Spry' Category

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.

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;posts&gt;
	&lt;post&gt;
		&lt;msg&gt;This is a &lt;strong&gt;message&lt;/strong&gt;&lt;/msg&gt;
	&lt;/post&gt;
&lt;/posts&gt;
&lt;msg&gt;This is a &lt;strong&gt;message&lt;/strong&gt;&lt;/msg&gt;

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

		&lt;msg&gt;
			&lt;![CDATA[
			This is a &lt;strong&gt;message&lt;/strong&gt;
			]]&gt;
		&lt;/msg&gt;

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

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

Spry with HTML Data Source Code

Spry with HTML Data Online Demo

VN:F [1.9.7_1111]
Rating: 7.0/10 (1 vote cast)
VN:F [1.9.7_1111]
Rating: 0 (from 0 votes)



Search Website

www.lingeriesg.com

www.lingeriesg.com

Sponsored Ads

Sponsored Links

www.asiadolly.com

www.asiadolly.com

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