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
ファイル: TXmlElementTest.php プロジェクト: pradosoft/prado
 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
ファイル: TXmlDocumentTest.php プロジェクト: pradosoft/prado
 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
ファイル: TXmlDocument.php プロジェクト: pradosoft/prado
 /**
  * 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
ファイル: TRpcService.php プロジェクト: pradosoft/prado
 /**
  * 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;
     }
 }