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("'", "'", $str));
}
?>
<html>
<script language="javascript1.2" src="codethatsdk.js"></script>
<script language="javascript" src="tree/codethattabpro.js"></script>
<body>
<input id="id1" type="hidden"
value='<php
print(wrap(ReadXML()));
?>'/>
<script language="javascript1.2">
<!--
var xmlTree = new CXMLTree (CodeThat.findElement("id1").value);
objDef = xmlTree.toObject();
var ts = new CTabSet("ts");
ts.create(objDef.tabDef);
//-->
</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 CodeThatTab >>
|