Heim  >  Artikel  >  Backend-Entwicklung  >  用PHP解析XML失误,尝试用XML做个数据源

用PHP解析XML失误,尝试用XML做个数据源

WBOY
WBOYOriginal
2016-06-13 13:26:16924Durchsuche

用PHP解析XML出错,尝试用XML做个数据源
利于XML词库,用PHP处理时出现
Notice: Trying to get property of non-object in C:\apache\htdocs\olword\wordprocess.php Fatal error: Call to a member function getElementsByTagName() on a non-object in C:\apache\htdocs\olword\wordprocess.php 

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->if($type=="update"){
     //接收新的单词

  $update_word_en=$_REQUEST['enword'];
  $update_word_ch=$_REQUEST['chword'];
 
  //查询
  $words=$xmldoc->getElementsByTagName("word");
  $isEnd=false;
  //遍历
 
  
  for($i=0;$ilength;$i++){
  //依次取出单词
  $word=$words->item($i);
  $word_en=getNodeVal($word,"en");
  if($update_word_en==$word_en){
      $isEnd=true;
   / /这里出现错误
      $parent_word=$word_en->parentNode;
      $word_ch=$parent_word->getElementsByTagName("ch")->item(0);
      $word_ch->nodeValue=$update_word_ch;
      //$word_en->nextSibling->nodeValue=$update_word_ch;这样修改也有问题
      //更新文件
   $isUpateOk=$xmldoc->save("word.xml");
if( $isUpateOk){

    echo "更新成功";
      }else echo "更新失败";
   }
}
if(!$isEnd){  
      echo "查无此词";

     }

}



------解决方案--------------------
没有看到 $xmldoc 在哪定义了?
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn