douxiegan6468 2013-08-19 10:31
浏览 36

尝试使用PHP脚本和jQuery更新XML文件时出现XML解析错误

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效
    • ¥15 悬赏!微信开发者工具报错,求帮改