php and xml DomDocument

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ibidrin@googlemail.com

    php and xml DomDocument

    Hi Ng,
    a error occurs in my class Articles in which i try to add an element
    to an existing xml-file.
    $var_dump($chan nels) >>>object(DOMNO deList)+6 (0) {}
    $var_dump($chan nels->length) >>>int(0)
    $var_dump($chan nels->item(0)) >>>NULL

    The tag article exists in the xml-file but it were not found by method
    getElementsByTa gName.
    Following error were occur:

    Fatal error: Call to a member function appendChild() on a non-object
    in ...


    Any suggestions?


    class Article extends DomDocument
    {
    public function __contruct()
    {
    parent::__contr uct('1.0','utf-8');
    }
    public function addArticle($tit le, $text)
    {
    $newItem = $this->createElement( 'item');
    $newTitle = $this->createElement( 'title');
    $newTitle->appendChild($t his->createTextNode ($title));
    $newItem->appendChild($n ewTitle);
    $newText = $this->createCDATASec tion($text);
    $newItem->appendChilde($ newText);
    $channels = $this->getElementsByT agName('article s');
    //hier bekomme ich den Fehler, obwohl es den Tag "arcticles" gibt
    $channels->item(0)->appendChild($n ewItem);
    //andere Ideen wie ich einen neuen Text in einer bestehender xml-
    Datei
    anhängen kann?
    }
    }

  • Simon Stienen

    #2
    Re: php and xml DomDocument

    On 2007-04-03 17-39-53, ibidrin@googlem ail.com wrote:
    Any suggestions?
    //hier bekomme ich den Fehler, obwohl es den Tag "arcticles" gibt
    //andere Ideen wie ich einen neuen Text in einer bestehender xml-Datei anhängen kann?
    Yup. Tanslate your comments as well next time. ;)

    For people unable to understand Germen:
    // here I'm getting the error, although "articles" exists.
    // any other ideas on how to append new text to an existing xml file?

    Grüsse

    Comment

    • Jerry Stuckle

      #3
      Re: php and xml DomDocument

      ibidrin@googlem ail.com wrote:
      Hi Ng,
      a error occurs in my class Articles in which i try to add an element
      to an existing xml-file.
      $var_dump($chan nels) >>>object(DOMNO deList)+6 (0) {}
      $var_dump($chan nels->length) >>>int(0)
      $var_dump($chan nels->item(0)) >>>NULL
      >
      The tag article exists in the xml-file but it were not found by method
      getElementsByTa gName.
      Following error were occur:
      >
      Fatal error: Call to a member function appendChild() on a non-object
      in ...
      >
      >
      Any suggestions?
      >
      >
      class Article extends DomDocument
      {
      public function __contruct()
      {
      parent::__contr uct('1.0','utf-8');
      }
      public function addArticle($tit le, $text)
      {
      $newItem = $this->createElement( 'item');
      $newTitle = $this->createElement( 'title');
      $newTitle->appendChild($t his->createTextNode ($title));
      $newItem->appendChild($n ewTitle);
      $newText = $this->createCDATASec tion($text);
      $newItem->appendChilde($ newText);
      $channels = $this->getElementsByT agName('article s');
      //hier bekomme ich den Fehler, obwohl es den Tag "arcticles" gibt
      $channels->item(0)->appendChild($n ewItem);
      //andere Ideen wie ich einen neuen Text in einer bestehender xml-
      Datei
      anhängen kann?
      }
      }
      >
      Where are you loading your XML file, and what does it look like?

      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      • Andy Hassall

        #4
        Re: php and xml DomDocument

        On 3 Apr 2007 08:39:53 -0700, ibidrin@googlem ail.com wrote:
        >Hi Ng,
        >a error occurs in my class Articles in which i try to add an element
        >to an existing xml-file.
        $var_dump($chan nels) >>>object(DOMNO deList)+6 (0) {}
        >$var_dump($cha nnels->length) >>>int(0)
        >$var_dump($cha nnels->item(0)) >>>NULL
        >
        >The tag article exists in the xml-file but it were not found by method
        >getElementsByT agName.
        >Following error were occur:
        >
        >Fatal error: Call to a member function appendChild() on a non-object
        >in ...
        >
        >
        >Any suggestions?
        >
        >
        >class Article extends DomDocument
        >{
        > public function __contruct()
        What's your actual code, or is this typo in your real code as well?
        > {
        > parent::__contr uct('1.0','utf-8');
        > }
        > public function addArticle($tit le, $text)
        > {
        > $newItem = $this->createElement( 'item');
        > $newTitle = $this->createElement( 'title');
        > $newTitle->appendChild($t his->createTextNode ($title));
        > $newItem->appendChild($n ewTitle);
        > $newText = $this->createCDATASec tion($text);
        > $newItem->appendChilde($ newText);
        > $channels = $this->getElementsByT agName('article s');
        > //hier bekomme ich den Fehler, obwohl es den Tag "arcticles" gibt
        "arcticles" or "articles" ?
        > $channels->item(0)->appendChild($n ewItem);
        > //andere Ideen wie ich einen neuen Text in einer bestehender xml-
        >Datei
        >anhängen kann?
        > }
        >}
        --
        Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
        http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

        Comment

        Working...