示例#1
0
 private function buildNodeTree(SdlTag $node)
 {
     $tag = strtolower($node->getName());
     $attr = "";
     foreach ($node->getAttributes() as $name => $value) {
         $attr .= " {$name}=\"{$value}\"";
     }
     $out = "";
     if ($node->hasChildren()) {
         if ($tag) {
             $out .= "<{$tag}{$attr}>";
         }
         foreach ($node->getChildren() as $child) {
             $out .= $this->buildNodeTree($child);
         }
         if ($tag) {
             $out .= "</{$tag}>";
         }
     } else {
         if (count($node) > 0) {
             if (!$tag) {
                 $out .= $node[0];
             } else {
                 $out .= "<{$tag}{$attr}>" . $node[0] . "</{$tag}>";
             }
         } else {
             $out .= "<{$tag}{$attr}>";
         }
     }
     return $out;
 }
示例#2
0
 public function testCreateTree()
 {
     $node1 = new SdlTag("root");
     $node2 = new SdlTag("subnode", "foo");
     $node1->addChild($node2);
     $this->assertTrue($node1->hasChildren());
     $this->assertInstanceOf('\\Cherry\\Data\\Ddl\\SdlTag', $node1->getChild("subnode"));
     $cl = $node1->getChildren("subnode");
     $this->assertEquals(1, count($cl));
     $this->assertInstanceOf('\\Cherry\\Data\\Ddl\\SdlTag', $cl[0]);
 }