/** * Returns the AnyDataset XmlDocument representive object * @return \DOMDocument XmlDocument object */ public function getDomObject() { $anyDataSet = XmlUtil::createXmlDocumentFromStr("<anydataset/>"); $nodeRoot = $anyDataSet->getElementsByTagName("anydataset")->item(0); foreach ($this->_collection as $sr) { $row = $sr->getDomObject(); $nodeRow = $row->getElementsByTagName("row")->item(0); $newRow = XmlUtil::createChild($nodeRoot, "row"); XmlUtil::addNodeFromNode($newRow, $nodeRow); } return $anyDataSet; }
/** * Get the \DOMElement row objet * @return \DOMElement */ public function getDomObject() { if (is_null($this->_node)) { $this->_node = XmlUtil::createXmlDocumentFromStr("<row />"); $root = $this->_node->getElementsByTagName("row")->item(0); foreach ($this->_row as $key => $value) { if (!is_array($value)) { $field = XmlUtil::createChild($root, "field", $value); XmlUtil::addAttribute($field, "name", $key); } else { foreach ($value as $valueItem) { $field = XmlUtil::createChild($root, "field", $valueItem); XmlUtil::addAttribute($field, "name", $key); } } } } return $this->_node; }
$otherNode = \ByJG\Util\XmlUtil::createChild($myNode, 'othersubnode', 'other text'); \ByJG\Util\XmlUtil::addAttribute($otherNode, 'attr', 'value'); echo $xml->saveXML(); print_r(\ByJG\Util\XmlUtil::xml2Array($xml)); $node = \ByJG\Util\XmlUtil::selectSingleNode($xml, '//subnode'); echo $node->nodeValue . "\n"; $node = \ByJG\Util\XmlUtil::selectSingleNode($myNode, '//subnode'); echo $node->nodeValue . "\n"; $nodeList = \ByJG\Util\XmlUtil::selectNodes($xml, '//subnode'); foreach ($nodeList as $node) { echo $node->nodeName; } echo "\n"; $nodeList = \ByJG\Util\XmlUtil::selectNodes($myNode, '//subnode'); foreach ($nodeList as $node) { echo $node->nodeName; } echo "\n"; \ByJG\Util\XmlUtil::addNamespaceToDocument($xml, 'my', 'http://www.example.com/mytest/'); echo $xml->saveXML() . "\n"; \ByJG\Util\XmlUtil::createChild($xml->documentElement, 'nodens', 'teste', 'http://www.example.com/mytest/'); \ByJG\Util\XmlUtil::createChild($xml->documentElement, 'my:othernodens', 'teste'); echo $xml->saveXML() . "\n"; $nodeList = \ByJG\Util\XmlUtil::selectNodes($xml, '//my:othernodens', ['my' => 'http://www.example.com/mytest/']); foreach ($nodeList as $node) { echo 'A' . $node->nodeName; } //$str = '<?xml version="1.0" encoding="utf-8"' // . '<root xmlns:my="http://www.example.com/mytest/">' // . ' ' // . '</root>';