3.2.0

Trying to use xml.php to edit mypets.xml file !!!! HELP !!!!

The files below are supposed to edit mypets.xsl file through my FTP server, but I cant figure out what comes next in the process!! Im using the 'Save XML Data' button in the 'THIRD FORM TABLE' to complete the action.
Any help would be greatly appecitated!!!!!!!
Many Thanks.


<?php

$the_file = "mypets.xml";
$root_tag = "persons"; // Name of the root tag without < or >
$allowed = array( // Fields of the xml document
Pet_name',
'Agility',
'Species',
'Att_strength',
'Def_strength',
'Amount'

);

$this_tag = "person"; // Name of the parent tag of our data without < or >

$data = "\t<$this_tag>\n";
for ( $i = 0 ; $i < count($allowed) ; $i++ ) { // Loop through the fields
$the_field = $allowed[$i];
$data .= "\t\t<$the_field>" .
htmlentities($_POST[$the_field]) // Grab from the post data, and clean it up
. "</$the_field>\n";
}
$data .= "\t</$this_tag>\n";

$j = 0 ;
if ( ( $fp = @fopen($the_file,'r') ) != false ) {
while ( !feof($fp) ) {
$line = (fgets($fp,4096));
$string = NULL;
$file .= $line;
for ( $i = 0 ; $i < strlen($line) ; $i++ ) {
$chr = ord(substr($line,$i,1));
if ( ( $chr < 123 ) && ($chr > 48) ) {
$string .= substr($line,$i,1);
}
}
if ( ($string == "<$root_tag>") && ($j == 0) ) {
$file .= $data;
$j++;
}
}
fclose($fp);
}

if ( ( $fp = @fopen($the_file,'w') ) != false ) { // Write the new file
fwrite($fp,$file);
fclose($fp);
}

header("Location: mypets.htm");<!----- DONT KNOW IF THIS IS CORRECT!! --->

?>



<html>
<head>
<title>My Neopets</title>
<SCRIPT TYPE="text/javascript">
<!--
// copyright 1999 Idocs, Inc. http://www.idocs.com
// Distribute this script freely but keep this notice in place
function numbersonly(myfield, e, dec)
{
var key;
var keychar;

if (window.event)
key = window.event.keyCode;
else if (e)
key = e.which;
else
return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) ||
(key==9) || (key==13) || (key==27) )
return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1))
return true;

// decimal point jump
else if (dec && (keychar == "."))
{
myfield.form.elements[dec].focus();
return false;
}
else
return false;
}

//-->
</SCRIPT>

<script language="JavaScript">
var PID = ["MSXML4.DOMDocument", "MSXML3.DOMDocument",
"MSXML2.DOMDocument", "MSXMLDOMDocument",
"Microsoft.XmlDom"];
var PID2 = ["MSXML4.FreeThreadedDOMDocument",
"MSXML3.FreeThreadedDOMDocument",
"MSXML2.FreeThreadedDOMDocument",
"MSXML.FreeThreadedDOMDocument"];
var PID3 = ["MSXML4.XSLTemplate", "MSXML3.XSLTemplate",
"MSXML2.XSLTemplate", "MSXML.XSLTemplate"];

var XMLFile="mypets.xml";
var XSLTFile="mypets.xsl";
var XMLDoc=new ActiveXObject(getPID(PID));
var XSLTDoc=new ActiveXObject(getPID(PID2));
var XSLTemp=new ActiveXObject(getPID(PID3));

function getPID(pArray){
var PIDStr ="";
var PIDFound = false;
for (i=0; i<pArray.length && !PIDFound; i++) {
try {
var objectXML=new ActiveXObject(pArray);
PIDStr=pArray[i];
PIDFound=true;
} catch (objException) {
}
}
return PIDStr;
}
function loadXML(document, file) {
document.async=false;
document.load(file);
}
function init(){
loadXML(XMLDoc, XMLFile);
loadXML(XSLTDoc, XSLTFile);
XSLTemp.stylesheet=XSLTDoc;
doTransform();
}
function doTransform(){
var XMLProcessor=XSLTemp.createProcessor();
XMLProcessor.input=XMLDoc;
fstring=document.webform.filter.value;
if (fstring=="") filter="//Pet"
else filter="//Pet["+fstring+"]";
XMLProcessor.addParameter("group", XMLDoc.selectNodes(filter));
XMLProcessor.transform();
ctable.innerHTML=XMLProcessor.output;
}
function addRecord() {
var old=XMLDoc.getElementsByTagName("Pet")[0];
var clone=old.cloneNode(true);
clone.childNodes[0].firstChild.nodeValue=document.webform.pet.value;
clone.childNodes[1].firstChild.nodeValue=document.webform.species.value;
clone.childNodes[2].firstChild.nodeValue=document.webform.agility.value;
clone.childNodes[3].firstChild.nodeValue=document.webform.att.value;
clone.childNodes[4].firstChild.nodeValue=document.webform.def.value;
clone.childNodes[5].firstChild.nodeValue=document.webform.amount.value;
XMLDoc.documentElement.appendChild(clone);
doTransform();
reset();
}
function reset() {

document.webform.pet.value="";
document.webform.species.value="";
document.webform.agility.value="";
document.webform.att.value="";
document.webform.def.value="";
document.webform.amount.value="";
}
function changeStyle(){
var XSLTDoc=new ActiveXObject(getPID(PID2));
loadXML(XSLTDoc,"mypets.xsl");
var sortNode=XSLTDoc.getElementsByTagName("xsl:sort")[0];
if (document.webform.sort[0].checked) {
select="Pet_name";
datatype="text";
}
else if (document.webform.sort[1].checked){
select="Species";
datatype="text";
}
else if (document.webform.sort[2].checked){
select="Amount";
datatype="number";
}
else if (document.webform.sort[3].checked){
select="Agility";
datatype="number";
}
if (document.webform.order[0].checked) order="ascending";
else order="descending";
sortNode.setAttribute("select", select);
sortNode.setAttribute("data-type", datatype);
sortNode.setAttribute("order", order);
XSLTemp.stylesheet=XSLTDoc;
doTransform();
}
function saveRemote()
{
document.FileSender.webform.value = XMLDoc.xml;
document.FileSender.submit();
}

</script>
<link href="mypets.css" rel="stylesheet" type="text/css" />
</head>
<body onload="document.forms.webform.pet.focus(); init()" style="background-color: #000000; background-image: url('bars3.jpg'); " link="#000000" vlink="#000000" alink="#000000">
<br /><br />
<table id="home" width="850" border="2" align="center" cellpadding="5" cellspacing="5" bgcolor=#99CCFF>
<tr>
<td align="center" >
<div id="title">
<br />
<a href="http://www.neopets.com/refer.phtml?username=derek1020"><img src="banner.gif" width="468" height="60" border="1" align="left" ></a>
<br />
<br />
&nbsp;&nbsp;<br/>
</div>
<div id="data_entry" style="width: 241px; height: 453px;">
<!-- FORM -->
<form name="webfor" id="webform" method="post" action="xml.php">
<!-- FIRST FORM TABLE -->
<h4 >Add a New NeoPet</h4>
<table height="199" width="251">
<tr>
<td>&nbsp; Pet Name</td><td><input name="pet" id="pet" size="15" /></td>
</tr>
<tr>
<td>&nbsp; Species</td><td><input name="species" id="species" size="15" /></td>
</tr>
<tr>
<td>&nbsp; Agility</td><td><input name="agility" id="agility" SIZE=3 MAXLENGTH=3
onKeyPress="return numbersonly(this, event)" /></td>
</tr>
<tr>
<td>&nbsp; Attack</td><td><input name="att" id="att" SIZE=3 MAXLENGTH=3
onKeyPress="return numbersonly(this, event)" /></td>
</tr>
<tr>
<td>&nbsp; Defense</td><td><input name="def" id="def" SIZE=3 MAXLENGTH=3
onKeyPress="return numbersonly(this, event)" /></td>
</tr>
<tr>
<td>&nbsp; Amount</td><td><input name="amount" id="amount" SIZE=6 MAXLENGTH=6
onKeyPress="return numbersonly(this, event)" /></td>
</tr>
<tr>
<td colspan="2" align="center"><hr />
<input type="button" value=" Add Pet " onclick="addRecord()" />
<input type="button" value=" Delete Pet "/>
[i]<input type="submit" value="Save XML Data"/> <!--HERES THE BUTTON-->

&nbsp;&nbsp;
<input type="hidden" value="xmltext" id="xmltext" />
</td>
</tr>
</table>
<!-- SECOND FORM TABLE -->
<h4>Sort My Pets</h4>
<table>
<tr>
<td><input type="radio" name="sort" onClick="changeStyle()" /></td>
<td>Name</td>
<td><input type="radio" name="sort" onClick="changeStyle()" /></td>
<td>Species</td>
</tr>
<tr>
<td><input type="radio" name="sort" onClick="changeStyle()" /></td>
<td>Amount</td>
<td><input type="radio" name="sort" onClick="changeStyle()" /></td>
<td>Agility</td>
</tr>
<tr>
<td colspan="4" align="center" >
<hr />
Ascending: <input type="radio" name="order" onClick="changeStyle()" />
Descending: <input type="radio" name="order" checked="checked" onClick="changeStyle()" />
</td>
</tr>
</table>
<br />
<!-- THIRD FORM TABLE -->
<h4>Filter the Contributor List</h4>
<table>
<tr>
<td>&nbsp;Text strings should&nbsp; be placed in single quotes.
Leave the input box blank to show all contributions.
</td>
<td width="133"><textarea name="filter" id="filter" rows="4" cols="14"></textarea>&nbsp;
</td>
</tr>
</table>
&nbsp;&nbsp;
<input type="button" value="Filter" onClick="changeStyle()"/><br />
</form>
</div>
<div id="ctable">
</div>
</td>
</tr>
</table>
<br /><br />
</body>
</html>
XML/PHP Newbie
August 12,

This topic is archived.

See also:


Back to support forum