519daddxml.php<?
class myXML extends DomDocument
{
        private $root;
        public function __construct()
        {                parent::__construct();
                ///*
                if(!file_exists('date.xml'))
                {
                        $xmldata = '<?xml version="1.0" encoding="utf-8"?><table></table>';
                        $this->loadXML($xmldata);
                        $this->save('date.xml');
                }
                else
                {
                        $this->load('date.xml');
                }
                //*/
        }
        public function addData($areaid, $qq, $zone, $sex, $old, $face, $descript)
        {
                $this->root = $this->documentElement;
                $this->formatOutput = true;                //define child
                $uid                = $this->createAttribute ('uid');
                $text                = $this->createTextNode('q'.$qq);
                $uid                ->appendChild($text);                $areaidNode = $this->createElement('areaid');
                $text                = $this->createTextNode($areaid);
                $areaidNode -> appendChild($text);                $qqNode                = $this->createElement('qq');
                $text                = $this->createTextNode($qq);
                $qqNode                -> appendChild($text);                $zoneNode        = $this->createElement('zone');
                $text                = $this->createTextNode($zone);
                $zoneNode        -> appendChild($text);                $sexNode        = $this->createElement('sex');
                $text                = $this->createTextNode($sex);
                $sexNode        -> appendChild($text);                $oldNode        = $this->createElement('old');
                $text                = $this->createTextNode($old);
                $oldNode        -> appendChild($text);                $faceNode        = $this->createElement('face');
                $text                = $this->createTextNode($face);
                $faceNode        -> appendChild($text);                $descriptNode= $this->createElement('descript');
                $text                = $this->createTextNode($descript);
                $descriptNode-> appendChild($text);                $addtimeNode= $this->createElement('addtime');
                $text                = $this->createTextNode(date('Y-m-d'));
                $addtimeNode-> appendChild($text);
                //end define child                //append attribute or element
                $nodeUser = $this->createElement('user');
                $nodeUser->appendChild($uid);
                $nodeUser->appendChild($areaidNode);
                $nodeUser->appendChild($qqNode);
                $nodeUser->appendChild($zoneNode);
                $nodeUser->appendChild($sexNode);
                $nodeUser->appendChild($oldNode);
                $nodeUser->appendChild($faceNode);
                $nodeUser->appendChild($descriptNode);
                $nodeUser->appendChild($addtimeNode);
                //end append attribute or element                $this->root->appendChild($nodeUser);
                $this->save('date.xml');
               // header('location:index.php');
                die();
        }
}
//if(strtolower($_SERVER['REQUEST_METHOD'])=='post')
//{
       // extract($_POST, EXTR_OVERWRITE);
        $dom = new myXML;
        $dom->addData('32e', '49220977', 'fsdfdsf', '男', '23', 'bai', '1231232');//}
?>
出错提示:Warning: DOMDocument::load() [domdocument.load]: Input is not proper UTF-8, indicate encoding ! Bytes: 0xE5 0x8C 0x3F 0x32 in file:///D:/AppServ/www/soupiao/manages/date.xml, line: 13 in D:\AppServ\www\soupiao\manages\519daddxml.php on line 18Fatal error: Call to a member function appendChild() on a non-object in D:\AppServ\www\soupiao\manages\519daddxml.php on line 78请高手看看啊,到底是怎么回事?怎么一会可以一会就不可以,就出错?

解决方案 »

  1.   

    date.xml里
    <?xml version="1.0" encoding="utf-8"?>
    指定的与对应的中文编码不一致.如果你指定为utf-8,要将date.xml保存成utf-8格式的.
      

  2.   

    xml文件第18行,存在非utf-8编码的东西。把xml文件贴来看看
      

  3.   

    把你的XML文件贴出来看看..你XML文件13行有问题..不过也不一定,我今天解析XML的时候也是这个问题,而且我的是一直指向11行,估计是别的地方错误映射过来的...但愿有高人来具体解释下。