public function xml() { $bool = false; $result = new \org\rhaco\Xml('summary'); $result->escape(true); foreach ($this->props() as $name => $value) { if (!empty($value)) { $bool = true; switch ($name) { case 'type': $result->attr($name, $value); break; case 'lang': $result->attr('xml:' . $name, $value); break; case 'value': $result->value($value); break; } } } if (!$bool) { throw new \org\rhaco\net\xml\atom\NotfoundException(); } return $result; }
public function xml() { $bool = false; $result = new \org\rhaco\Xml('entry'); foreach ($this->props() as $name => $value) { if (!empty($value)) { $bool = true; switch ($name) { case 'xmlns': $result->attr('xmlns', $value); break; case 'id': case 'title': $result->add(new \org\rhaco\Xml($name, $value)); break; case 'published': case 'updated': case 'issued': $result->add(new \org\rhaco\Xml($name, \org\rhaco\lang\Date::format_atom($value))); break; default: if (is_array($value)) { foreach ($value as $v) { try { $result->add($v instanceof \org\rhaco\net\xml\atom\Object ? $v->xml() : (string) $v); } catch (\org\rhaco\net\xml\atom\NotfoundException $e) { } } } else { if (is_object($value)) { try { $result->add($value instanceof \org\rhaco\net\xml\atom\Object ? $value->xml() : $value); } catch (\org\rhaco\net\xml\atom\NotfoundException $e) { } } else { $result->add(new \org\rhaco\Xml($name, $value)); break; } } } } } if (!$bool) { throw new \org\rhaco\net\xml\atom\NotfoundException(); } return $result; }
public function xml() { $bool = false; $result = new \org\rhaco\Xml('link'); foreach ($this->props() as $name => $value) { if (!empty($value)) { $bool = true; switch ($name) { case 'href': case 'rel': case 'type': $result->attr($name, $value); break; } } } if (!$bool) { throw new \org\rhaco\net\xml\atom\NotfoundException(); } return $result; }
eq(array("abc" => 123, "ghi" => 789), iterator_to_array($x)); $x->attr("def", 456); eq(array("abc" => 123, "ghi" => 789, "def" => 456), iterator_to_array($x)); $x->rm_attr("abc", "ghi"); eq(array("def" => 456), iterator_to_array($x)); $x = new \org\rhaco\Xml("test"); eq(false, $x->is_attr("abc")); $x->attr("abc", 123); eq(true, $x->is_attr("abc")); $x->attr("abc", null); eq(true, $x->is_attr("abc")); $x->rm_attr("abc"); eq(false, $x->is_attr("abc")); $x = new \org\rhaco\Xml("test"); $x->escape(true); $x->attr("abc", 123); eq(123, $x->in_attr("abc")); $x->attr("Abc", 456); eq(456, $x->in_attr("abc")); $x->attr("DEf", 555); eq(555, $x->in_attr("def")); eq(456, $x->in_attr("abc")); $x->attr("Abc", "<aaa>"); eq("<aaa>", $x->in_attr("abc")); $x->attr("Abc", true); eq("true", $x->in_attr("abc")); $x->attr("Abc", false); eq("false", $x->in_attr("abc")); $x->attr("Abc", null); eq(null, $x->in_attr("abc")); $x->attr("ghi", null);
protected function __str__() { $result = new \org\rhaco\Xml('feed'); $result->attr('xmlns', self::XMLNS); foreach ($this->ar_xmlns() as $ns => $url) { $result->attr('xmlns:' . $ns, $url); } foreach ($this->props() as $name => $value) { if (!empty($value)) { switch ($name) { case 'title': case 'subtitle': case 'id': case 'generator': $result->add(new \org\rhaco\Xml($name, $value)); break; case 'updated': $result->add(new \org\rhaco\Xml($name, \org\rhaco\lang\Date::format_atom($value))); break; default: if (is_array($value)) { foreach ($value as $v) { try { $result->add($v instanceof \org\rhaco\net\xml\atom\Object ? $v->xml() : $v); } catch (\org\rhaco\net\xml\atom\NotfoundException $e) { } } } } } } return $result->get(); }
<?php $x = new \org\rhaco\Xml("test", 123); eq("<test>123</test>", $x->get()); $x = new \org\rhaco\Xml("test", new \org\rhaco\Xml("hoge", "AAA")); eq("<test><hoge>AAA</hoge></test>", $x->get()); $x = new \org\rhaco\Xml("test"); eq("<test />", $x->get()); $x = new \org\rhaco\Xml("test"); $x->close_empty(false); eq("<test></test>", $x->get()); $x = new \org\rhaco\Xml("test"); $x->attr("abc", 123); $x->attr("def", 456); eq('<test abc="123" def="456" />', $x->get());