Question

Ok. Really hope someone can help me answer the following question. So I am using an XML datastore for persistence for a final year project. Here's the structure of the XML file.

<?xml version="1.0"?>
<!DOCTYPE datastore SYSTEM "datastore.dtd">
<datastore>
<dataset>
<name>Test1</name>
<dataobject>
  <userid>001</userid>
  <adl1/>
  <adl2/>
  <adl3/>
  <city>London</city>
  <county/>
  <postcode>SE1 7HS</postcode>
  <country>United Kingdom</country>
  <amount>300.0</amount>
  <date>01/01/2013</date>
    </dataobject>
   </dataset>
    <dataset>
    <name>Test2</name>
    <dataobject>
        <userid>001</userid>
        <adl1/>
        <adl2/>
        <adl3/>
        <city>Tunbridge Wells</city>
        <county>Kent</county>
        <postcode>TN1 2GE</postcode>
        <country>United Kingdom</country>
        <amount>20</amount>
        <date>01/07/2013</date>
    </dataobject>
</dataset></datastore>

One of the things I want the user to be able to do is to add a new dataset. Simple enough. So i've used the following small jQuery function and PHP script.

  function addDataSetToXML(dataset){
  $.ajax({
     type:'GET',
     url:'/phpScripts/addDataSet.php',
     data:{dataset : dataset},
     success:function(){
         window.alert("Added dataset " + dataset + " to gsdatastore.xml");
     },
    error:function() {window.alert("Did not work");}
    });
}

and here's addDataset.php:

<?php
$name = $_GET[$dataset];
$doc = new DOMDocument();
$xml = "../dataStore/gsdatastore.xml";
$doc->Load($xml);
$doc->formatOutput = true;
$newDataSetElement = $doc->createElement("dataset");
$newNameElement = $doc->createElement("name",$dataset);
$newDataSetElement->appendChild($newNameElement);
$root = $doc->documentElement;
$root->appendChild($newDataSetElement);
$doc->Save($xml);
?>

I cannot find any errors in the code and when the script is run i get the success message. I've used Firebug and finally tracked down the following in the response message (the HTTP GET returns a 200 OK message so its definitely finding the script and running it).

XML Parsing Error: no element found Location: moz-nullprincipal:{8b768c4c-ef3c-644a-ae97-dd38798b8ba1} Line Number 13, Column 3:

?> --^

Does anyone have any idea what this means? This has been doing my head in. Any help greatly appreciated.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top