I'm an expert when it comes to anything regarding ASP, but I'm currently using a web host that only supports php (:cough:yahoo:cough, and lucky me I've never used the language.
I'm sending variables to a php page in this form:
Map.php?map=****&id=****&path=****&x=****&y=****
I assume thats the correct way to do it,
now in the actual php page I'd like to grab those variables and put them in an XML file but I'm not confident enough in the syntax of this language and its XML parsers to do it:
PHP Code:
<?php
//Get variables passed to this page?
icon=$_GET['id'];
map=$_GET['id'];
path=$_GET['id'];
x=$_GET['id'];
y=$_GET['id'];
//open the xml database
$doc = new DomDocument;
$doc->Load('blah/guilds.xml')
?>
From this point I'm a little stuck, how do I update XML nodes from this point? And if they don't exist, create them?
//Get variables passed to this page?
icon=$_GET['id'];
map=$_GET['id'];
path=$_GET['id'];
x=$_GET['id'];
y=$_GET['id'];
But just in case, it should be something like:
PHP Code:
//Get variables passed to this page?
icon=$_GET['id'];
map=$_GET['map'];
path=$_GET['path'];
x=$_GET['x'];
y=$_GET['y'];
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
PS: You might want to look at the SimpleXML functions.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Thanks for the advice, but my server is stuck on PHP 4.3.0, so SimpleXML isn't an option according to the webhost's guide on the topic.
Heres how I would generally do it in javascript:
PHP Code:
// Load XML
var mapxml = new ActiveXObject("MSXML2.DOMDocument.3.0");
mapxml.load("map.xml");
//Get and Test if the specific icon node exists
var test = mapxml.selectSingleNode("\guilds\icon[@id="+id+"]");
//If it does exist
if (test != null){
//update the properties
test.childNodes.item(0).text=map;
test.childNodes.item(1).text=path;
test.childNodes.item(2).text=x;
test.childNodes.item(3).text=y;
//save the file
mapxml.save("map.xml");
}
//If it does not exist, create it
else{
//define the document base tag
var guilds = mapxml.documentElement;
//create <icon> element
var icon1 = mapxml.createNode(xmlNodeType.Element, "icon", "");
//create the id for the element
var iconid = mapxml.createAttribute("id")
//set the value for the attribute
iconid.value = id;
//add the attribute to the tag
icon1.attributes.setNamedItem(iconid)
//append <icon id="blah"> to <guilds>
guilds.appendChild(icon1)
//create <map> element
var map1 = mapxml.createNode(xmlNodeType.Element, "map", "");
//create the text node
var map1value=mapxml.createTextNode(map)
//append the text to the element
map1.appendChild(map1value)
//append <map>blah</map> to <icon>
icon1.appendChild(map1)
//create <path> element
var path1 = mapxml.createNode(xmlNodeType.Element, "path", "");
//create the text node
var pathtext = =mapxml.createTextNode(path)
//append the text to the element
path1.appendChild(pathtext)
//append <path>blah</path> to <icon>
icon1.appendChild(path1)
//create <x> element
var x1 = mapxml.createNode(xmlNodeType.Element, "x", "");
//create the text node
var xtext = mapxml.createTextNode(x)
//append the text to the element
x1.appendChild(xtext)
//append <x>blah</x> to <icon>
icon1.appendChild(x1)
//create <y> element
var y1 = mapxml.createNode(xmlNodeType.Element, "y", "");
//create the text node
var ytext = mapxml.createTextNode(y)
//append the text to the element
y1.appendChild(ytext)
//append <x>blah</x> to <icon>
icon1.appendChild(y1)
//save the file
mapxml.save("map.xml");
}
Can anyone assist with the translation? Or tell me the equivalent functions in XML DOM for PHP?
Bookmarks