JavaScript Tree java script tree menu dhtml tree navigation javascript tree view control node expand collapse javaswcript tree example free tree menu

PRODUCTS

JavaScript Projects

PHP Projects

Javascript Tools

SUPPORT

Standard vs PRO

FAQ

Contacts

Site Map

CODETHAT

Downloads

Users Testimonials

Our Customers

STUDIO   GRID   TABLE   MENU   TREE   XPBAR   HINT   EDITOR   TAB   FORM   CALENDAR   SCROLLER   SHOPPINGCART   TREEPHP   PACKER

User
Manual

Introduction    Item's look    Item's positioning    Items' actions    Using XML    IE-like style

Run-time item manipulation    HTML code as nodes text    Tree from the database

Mouse-over behaviour    Performance tips    What's new?    Tree reference    STD vs PRO

On-line
Builder

PRO

STD

123Guide    Examples    Download

Themes

CODETHATTREE USER MANUAL

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="codethatsdk.js"></script>
<script language="javascript" src="tree/codethattreepro.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);
treeDef = xmlTree.toObject();
var treeView = new CTree(treeDef.Menu, "sample");
treeView.create(); 

//-->
</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 CodeThatTree >>

[ Home ]  [ Contacts ]  [ Site Map ]  [ News ]  [ Links ]  [ Downloads ]

[ Go Top ]

© CodeThat.com, 2003-2010
Design by XTLabs, Inc
Sponsored by Rocket Division Software, LTD.