User Manual
Samples

Introduction    Configure table look    Table decoration properties

Table general features    Table keys    User types    Data from the DB / CSV / XML / form

Using XML    Table reference    What's new?    Standard vs PRO

123Guide   

Order PRO Now   

How to Create XML Definition

To create XML definition from Object definition you should uses these simple rules:

Let Object definition is

def = {
	simpleprop : value,
	complexprop : {
		simpleprop : value
	},
	arrayprop : [
	{
		simpleprop : value, complexprop : {
			simpleprop : value
		}
	}, ...
	]
}

then XML definition will be

<?xml version="1.0"?>
<defObj>
<simpleprop>value</simpleprop>
<complexprop>
<simpleprop>value</simpleprop>
</complexprop>
<arrayprop>
<simpleprop>value</simpleprop>
<complexprop>
<simpleprop>value</simpleprop>
</complexprop>
</arrayprop>
<arrayprop>
<simpleprop>value</simpleprop>
<complexprop>
<simpleprop>value</simpleprop>
</complexprop>
</arrayprop>
</defObj>

How to Read XML from Server

Retrieving XML from server into client script can be done in two easy steps. First step is to decide what will be the source of your XML data. Second step is to write a simple server code embedding XML data into your web page.

Examples in php are listed below.

XML data may be taken

from a file located on server

from existing server script (may be from the other, not yours server)

from script function (for example, from a function retrieving data from database)

1. Let a file named data.xml is located on server along with your working web-page. Than your web-page may look like this:

<php
Function ReadXML() {
	$resXml = fopen("data.xml", "r+");
	flock($resXml, LOCK_EX);
	$xmlData = fread($resXml, filesize("data.xml"));
	flock($resXml, LOCK_UN);
	fclose($resXml);
	return($xmlData);
}

Function wrap($str) {
	return(str_replace("'", "&#39", $str));
}
?>	
	<html>

	<script language="javascript1.2" src="../Scripts/codethatsdk.js"></script>
	<script language="javascript" src="../Scripts/codethattype.js"></script>
	<script language="javascript" src="../Scripts/codethattablepro.js"></script>

	<body>

	<form><input id="id1" type="hidden" 
			value='<php
print(wrap(ReadXML())); 
?>'/></form>
	<script language="javascript1.2">
<!--
var xmlTree = new CXMLTree (document.forms[0].id1.value);
var def = xmlTree.toObject();
var t = new CCodeThatTable("t");
t.loadData(def.tableDef);
t.doAction(); 
//-->
</script>
	</body>
	</html>

2. Let there is an existing script which returns xml by url http://servername.com/cgi-bin/script. The difference from previous case is slightly changed ReadXML function (no locking and different file name). The function (see 1.) may look like this:

Function ReadXML()
{
	$resXml = fopen("http://servername.com/cgi-bin/script ", "r+");
	$xmlData = fread($resXml, filesize("data.xml"));
	fclose($resXml);
	return($xmlData);
}

Other code remains as in 1.

3. You have a script function which returns xml as a string. You just have to substitute ReadXML function from 1. with your function.

Please don't consider these examples as a complete solution. They are expected to give you an idea how this can be done. You may find other solutions. You also may need improvements to the sample code (for example to support security features).

Example - Using XML

You can see an example here - Using XML Example [popup]

Read more about CodeThatTable >>

© CodeThat.com, 2003-2005
Design by XTLabs, Inc.