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
Since: 3.0
Author: Qiang Xue ([email protected])
Inheritance: extends TXmlElement
Datei anzeigen Open project: pradosoft/prado Class Usage Examples

Public Methods

Method Description
__construct ( $version = '1.0', $encoding = '' ) Constructor.
__toString ( ) : string Magic-method override. Called whenever this document is used as a string.
getEncoding ( ) : string
getVersion ( ) : string
loadFromFile ( $file ) : boolean Loads and parses an XML document.
loadFromString ( $string ) : boolean Loads and parses an XML string.
saveToFile ( $file ) Saves this XML document as an XML file.
saveToString ( ) : string Saves this XML document as an XML string
setEncoding ( $encoding )
setVersion ( $version )

Protected Methods

Method Description
buildElement ( $node ) : TXmlElement Recursively converts DOM XML nodes into TXmlElement

Method Details

__construct() public method

Constructor.
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;
public __toString ( ) : string
return string string representation of this document

buildElement() protected method

Recursively converts DOM XML nodes into TXmlElement
protected buildElement ( $node ) : TXmlElement
return TXmlElement the converted TXmlElement

getEncoding() public method

public getEncoding ( ) : string
return string encoding of this XML document

getVersion() public method

public getVersion ( ) : string
return string version of this XML document

loadFromFile() public method

Loads and parses an XML document.
public loadFromFile ( $file ) : boolean
return boolean whether the XML file is parsed successfully

loadFromString() public method

The version and encoding will be determined based on the parsing result.
public loadFromString ( $string ) : boolean
return boolean whether the XML string is parsed successfully

saveToFile() public method

Saves this XML document as an XML file.
public saveToFile ( $file )

saveToString() public method

Saves this XML document as an XML string
public saveToString ( ) : string
return string the XML string of this XML document

setEncoding() public method

public setEncoding ( $encoding )

setVersion() public method

public setVersion ( $version )