:: CodeThat. Do IT this way! :: Free javascript menu, javascript tree, dhtml menu, dhtml tree, popup menu, outlook bar menu, free scripts, free javascript, calendar

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    Menu types    Style customize    Menu position    Items' actions

Dynamic menu    Using XML    HTML code as items' text    Menu from the database

Build menu in the frame    Menu borders    Addition features    Standard vs PRO

On-line
Builder

PRO

STD

123Guide    Examples    Download

Themes    FAQ

CODETHATMENU 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="javascript1.2" src="menu/codethatmenupro.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 and complete code here - Using XML Example

Read more about CodeThatMenu >>

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

[ Go Top ]

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