예제 #1
0
 public function addChild($name, $value = null)
 {
     if ($name instanceof XmlElementInterface) {
         $value = $name;
         $name = $value->getName();
     }
     $coreElement = $this->elem->addChild($name);
     $element = new XmlElement($coreElement);
     if ($value instanceof XmlElementInterface) {
         foreach ($value->attributes() as $k => $v) {
             $element->attributes()->set($k, $v);
         }
         foreach ($value->children() as $child) {
             $element->addChild($child);
         }
         if ($value->text()) {
             $element->setText($value->text());
         }
         $value->_swapoutInternal($coreElement);
     } else {
         $element->setText($value);
     }
     return $element;
 }
예제 #2
0
 public function add($name, $value = null)
 {
     $parentElements = $this->elem->xpath('..');
     $element = new XmlElement($parentElements[0]);
     return $element->addChild($name, $value);
 }
예제 #3
0
 public function testAddXmlElementName()
 {
     $el1 = new XmlElement(new SimpleXMLElement('<data p="d" va="re"><piece n="0">a</piece><piece n="1">b</piece></data>'));
     $el1Str = $el1->__toString();
     $collection = $this->getXmlCollection();
     $el = $collection->add('xx', $el1);
     $this->assertSame(str_replace('data', 'xx', $el1Str), $el->__toString());
     $added = $collection->find(array('p' => 'd', 'va' => 're'));
     $this->assertEqual(1, count($added));
 }
 public function testNestedServicesXml()
 {
     $serviceFile = new XmlElement(new \SimpleXMLElement('<container><services></services></container>'));
     $serviceFile->child('services')->addChild($this->getNestedServices());
     $this->assertEquals('<?xml version="1.0"?>' . "\n" . '<container><services>' . '<service id="service.one" class="stdClass">' . '<argument type="service">' . '<argument type="service" id="arg.one"/>' . '<argument type="service" id="arg.two" on-invalid="ignore"/>' . '<argument type="service" id="arg.three" on-invalid="null"/>' . '<argument type="string">arg.four</argument>' . '</argument>' . '</service>' . '</services></container>' . "\n", $serviceFile->__toString());
 }
 private function wrap($element)
 {
     $rootElement = new XmlElement(new \SimpleXMLElement('<routes />'));
     $rootElement->addChild($element);
     return $rootElement;
 }
예제 #6
0
    <link rel="self" href="/files/30" type="api"/>
    <link rel="self" href="http://bay.dev/file/Algebra/Exercise/Screenshot-from-2013-10-21-19:31:42.png" type="www"/>
    <link rel="author" href="/users/vierbergenlars"/>
  </entry>
  <entry id="40">
    <filename><![CDATA[Screen Shot 2013-11-17 at 13.34.30.xcf]]></filename>
    <course id="1"><![CDATA[Analyse]]></course>
    <type id="1"><![CDATA[Slides]]></type>
    <link rel="self" href="/files/40" type="api"/>
    <link rel="self" href="http://bay.dev/file/Algebra/Slides/Screen-Shot-2013-11-17-at-13.34.30.xcf" type="www"/>
    <link rel="author" href="/users/vierbergenlars"/>
  </entry>
</result>
XML;
$simpleXml = new \SimpleXMLElement($xml);
$xmlElement = new XmlElement($simpleXml);
$totalPages = ceil($xmlElement->attr('total') / $xmlElement->attr('items_per_page'));
echo $xmlElement->attr('page') . '/' . $totalPages . "\n";
$files = $xmlElement->children();
/* @var $files XmlCollectionInterface */
foreach ($files as $file) {
    /* @var $file XmlElementInterface */
    echo 'File ' . $file->attr('id') . ":\n";
    // echo '  Filename: ' . $file->child('filename')->text() . "\n";
    foreach ($file->children() as $fileProperty) {
        /* @var $fileProperty XmlElementInterface */
        if ($fileProperty->getName() != 'link') {
            echo '  ' . ucfirst($fileProperty->getName()) . ': ' . $fileProperty->text() . "\n";
        }
    }
    echo "  Links:\n";
예제 #7
0
 public function testAddXmlElementName()
 {
     $el1 = new XmlElement(new SimpleXMLElement('<data p="d" va="re"><piece n="0">a</piece><piece n="1">b</piece></data>'));
     $el1Str = $el1->__toString();
     $element = $this->getXmlElement();
     $el = $element->addChild('xx', $el1);
     $this->assertSame(str_replace('data', 'xx', $el1Str), $el->__toString());
     $added = $element->child('xx');
     $this->assertEqual($added->__toString(), $el->__toString());
 }