Changeset 82

Show
Ignore:
Timestamp:
01/17/07 15:10:13 (2 years ago)
Author:
schst
Message:

Added writeElement() method

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/xml/stubXMLDomStreamWriter.php

    r65 r82  
    130130 
    131131    /** 
     132     * Write a full element 
     133     * 
     134     * @param string $elementName 
     135     * @param array $attributes 
     136     * @param string $cdata 
     137     */ 
     138    public function writeElement($elementName, array $attributes = array(), $cdata = null) { 
     139        $element = $this->doc->createElement($elementName); 
     140        foreach ($attributes as $attName => $attValue) { 
     141            $element->setAttribute($attName, $attValue); 
     142        } 
     143        if (null !== $cdata) { 
     144            $element->appendChild($this->doc->createTextNode($cdata)); 
     145        } 
     146        if (count($this->elementStack) == 0) { 
     147            $this->doc->appendChild($element); 
     148        } else { 
     149            $parent = end($this->elementStack); 
     150            $parent->appendChild($element); 
     151        } 
     152         
     153    } 
     154     
     155    /** 
    132156     * Import another stream 
    133157     * 
  • trunk/src/main/php/xml/stubXMLStreamWriter.php

    r31 r82  
    8181 
    8282    /** 
     83     * Write a full element 
     84     * 
     85     * @param string $elementName 
     86     * @param array $attributes 
     87     * @param string $cdata 
     88     */ 
     89    public function writeElement($elementName, array $attributes = array(), $cdata = null); 
     90     
     91    /** 
    8392     * Import another stream 
    8493     * 
  • trunk/src/test/php/xml/stubXMLDomStreamWriterTestCase.php

    r31 r82  
    4141    } 
    4242 
     43    /** 
     44     * Test creating a document with several tags 
     45     */ 
     46    public function testFullElement() { 
     47        $writer = new stubXMLDomStreamWriter(); 
     48        $writer->writeElement('foo', array('att' => 'value'), 'content'); 
     49 
     50        $this->assertEqual('<?xml version="1.0" encoding="ISO-8859-1"?>' . "\n" . '<foo att="value">content</foo>' . "\n" , $writer->asXML()); 
     51    } 
     52     
    4353    /** 
    4454     * Test creating a document with attributes