TXmlElement represents an XML element node. You can obtain its tag-name, attributes, text between the opening and closing tags via the TagName, Attributes, and Value properties, respectively. You can also retrieve its parent and child elements by Parent and Elements properties, respectively. TBD: xpath
Since: 3.0
Author: Qiang Xue (qiang.xue@gmail.com)
Inheritance: extends Prado\TComponent
示例#1
0
 public function testToString()
 {
     $element = new TXmlElement('tag');
     self::assertEquals('<tag />', (string) $element);
     $element->setAttribute('key', 'value');
     self::assertEquals('<tag key="value" />', (string) $element);
     $element->setValue('value');
     self::assertEquals('<tag key="value">value</tag>', (string) $element);
 }
示例#2
0
 public function testSaveToFile()
 {
     $file = dirname(__FILE__) . '/data/tmp.xml';
     if (!is_writable(dirname($file))) {
         self::markTestSkipped(dirname($file) . ' must be writable for this test');
     }
     $xmldoc = new TXmlDocument('1.0', 'utf-8');
     $xmldoc->setTagName('root');
     $node = new TXmlElement('node');
     $node->setAttribute('param', 'attribute1');
     $xmldoc->getElements()->add($node);
     $xmldoc->saveToFile($file);
     self::assertTrue(is_file($file));
     if (is_file($file)) {
         unlink($file);
     }
 }
示例#3
0
 /**
  * Recursively converts DOM XML nodes into TXmlElement
  * @param DOMXmlNode the node to be converted
  * @return TXmlElement the converted TXmlElement
  */
 protected function buildElement($node)
 {
     $element = new TXmlElement($node->tagName);
     $element->setValue($node->nodeValue);
     foreach ($node->attributes as $name => $attr) {
         $element->getAttributes()->add(($attr->prefix === '' ? '' : $attr->prefix . ':') . $name, $attr->value);
     }
     foreach ($node->childNodes as $child) {
         if ($child instanceof \DOMElement) {
             $element->getElements()->add($this->buildElement($child));
         }
     }
     return $element;
 }
示例#4
0
 /**
  * Loads the service configuration
  * @param TXmlElement $xml configuration
  */
 public function loadConfig(TXmlElement $xml)
 {
     foreach ($xml->getElementsByTagName('rpcapi') as $_apiProviderXml) {
         $_properties = $_apiProviderXml->getAttributes();
         if (($_id = $_properties->remove('id')) === null || $_id == "") {
             throw new TConfigurationException('rpcservice_apiproviderid_required');
         }
         if (isset($this->apiProviders[$_id])) {
             throw new TConfigurationException('rpcservice_apiproviderid_duplicated');
         }
         $this->apiProviders[$_id] = $_properties;
     }
 }