PHP Class Prado\Xml\TXmlDocument
TXmlDocument represents a DOM representation of an XML file.
Besides all properties and methods inherited from {@link TXmlElement},
you can load an XML file or string by {@link loadFromFile} or {@link 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:
1
1
Exibir arquivo
Open project: pradosoft/prado
Class Usage Examples
Public Methods
Protected Methods
Method |
Description |
|
buildElement ( $node ) : TXmlElement |
Recursively converts DOM XML nodes into TXmlElement |
|
Method Details
__construct()
public method
public __construct ( $version = '1.0', $encoding = '' ) |
__toString()
public method
$document = new TXmlDocument();
$document->TagName = 'root';
echo $document;
or
$document = new TXmlDocument();
$document->TagName = 'root';
$xml = (string)$document;
buildElement()
protected method
Recursively converts DOM XML nodes into TXmlElement
protected buildElement ( $node ) : TXmlElement |
return |
TXmlElement |
the converted TXmlElement |
getEncoding()
public method
getVersion()
public method
loadFromFile()
public method
Loads and parses an XML document.
loadFromString()
public method
The version and encoding will be determined based on the parsing result.
saveToFile()
public method
Saves this XML document as an XML file.
saveToString()
public method
Saves this XML document as an XML string
setEncoding()
public method
setVersion()
public method