Class TXmlDocument
TXmlDocument class.
TXmlDocument represents a DOM representation of an XML file. Besides all
properties and methods inherited from TXmlElement
, you can load an XML
file or string by TXmlDocument::loadFromFile()
or TXmlDocument::loadFromString()
. You can also
get the version and encoding of the XML document by the Version and Encoding
properties.
To construct an XML string, you may do the following:
$doc=new TXmlDocument('1.0','utf-8'); $doc->TagName='Root'; $proc=new TXmlElement('Proc'); $proc->setAttribute('Name','xxxx'); $doc->Elements[]=$proc; $query=new TXmlElement('Query'); $query->setAttribute('ID','xxxx'); $proc->Elements[]=$query; $attr=new TXmlElement('Attr'); $attr->setAttribute('Name','aaa'); $attr->Value='1'; $query->Elements[]=$attr; $attr=new TXmlElement('Attr'); $attr->setAttribute('Name','bbb'); $attr->Value='1'; $query->Elements[]=$attr;
The above code represents the following XML string:
<?xml version="1.0" encoding="utf-8"?> <Root> <Proc Name="xxxx"> <Query ID="xxxx"> <Attr Name="aaa">1</Attr> <Attr Name="bbb">1</Attr> </Query> </Proc> </Root>
- TComponent
-
TXmlElement
-
TXmlDocument
Package: System\Xml
Copyright: Copyright © 2005-2014 PradoSoft
License: http://www.pradosoft.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 3.0
Located at Xml/TXmlDocument.php
Copyright: Copyright © 2005-2014 PradoSoft
License: http://www.pradosoft.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 3.0
Located at Xml/TXmlDocument.php
public
|
|
public
string
|
|
public
|
|
public
string
|
|
public
|
|
public
boolean
|
|
public
boolean
|
#
loadFromString( string $string )
Loads and parses an XML string. The version and encoding will be determined based on the parsing result. |
public
|
|
public
string
|
|
public
string
|
#
__toString( )
Magic-method override. Called whenever this document is used as a string. $document = new TXmlDocument(); $document->TagName = 'root'; echo $document; or $document = new TXmlDocument(); $document->TagName = 'root'; $xml = (string)$document; |
protected
|
GLOBAL_RAISE_EVENT_LISTENER
|