www.webdeveloper.com
Results 1 to 3 of 3

Thread: <script> tags: removing CDATA created by loadHTML

  1. #1
    Join Date
    Jan 2011
    Location
    Munich, Germany
    Posts
    237

    <script> tags: removing CDATA created by loadHTML

    I'm trying to impement the "userland workaround" described here:

    https://bugs.php.net/bug.php?id=54429

    with the following PHP code variation:

    Code:
    public function __xCDATA($i) {
     $list = $i->getElementsByTagName('script');
     foreach ($list as $script) {
      if ($script->childNodes->length && $script->firstChild->nodeType == 4) {
       $text = $this->ownerDocument->createTextNode( $script->firstChild->nodeValue);
       //$script->replaceChild($text, $script->firstChild);
      }
     } 
    }
    see: http://4nf.org/php/JSLikeHTMLElement.txt

    If I enable the last line:

    Code:
    //$script->replaceChild($text, $script->firstChild);
    ...the function crashes

    What am I doing wrong?


    Thanks in advance and kind regards

  2. #2
    Join Date
    Jan 2011
    Location
    Munich, Germany
    Posts
    237
    I also tried this, just for debugging:

    Code:
    public function __xCDATA($i) {
     $list = $i->getElementsByTagName('script');
     foreach ($list as $script) {
      if ($script->childNodes->length && $script->firstChild->nodeType == 4) {
       $text = $this->ownerDocument->createTextNode(";");
       $script->replaceChild($text, $script->firstChild);
      }
     } 
    }
    Doesn't work either (crashes).

    Any ideas?

  3. #3
    Join Date
    Jan 2011
    Location
    Munich, Germany
    Posts
    237

    SaveXML inserts extra CDATA

    After lots of fiddling around, this code, after the returning of SaveXML, wiped out the extra CDATA:

    $string = str_replace("<![CDATA[","",$string);
    $string = str_replace("]]>","",$string);

    However, the "XML" code returned was distorted.

    Has anyone else observed the same?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles