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
Afficher le fichier Open project: pradosoft/prado Class Usage Examples

Méthodes publiques

Méthode 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 )

Méthodes protégées

Méthode Description
buildElement ( $node ) : TXmlElement Recursively converts DOM XML nodes into TXmlElement

Method Details

__construct() public méthode

Constructor.
public __construct ( $version = '1.0', $encoding = '' )

__toString() public méthode

$document = new TXmlDocument(); $document->TagName = 'root'; echo $document; or $document = new TXmlDocument(); $document->TagName = 'root'; $xml = (string)$document;
public __toString ( ) : string
Résultat string string representation of this document

buildElement() protected méthode

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

getEncoding() public méthode

public getEncoding ( ) : string
Résultat string encoding of this XML document

getVersion() public méthode

public getVersion ( ) : string
Résultat string version of this XML document

loadFromFile() public méthode

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

loadFromString() public méthode

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

saveToFile() public méthode

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

saveToString() public méthode

Saves this XML document as an XML string
public saveToString ( ) : string
Résultat string the XML string of this XML document

setEncoding() public méthode

public setEncoding ( $encoding )

setVersion() public méthode

public setVersion ( $version )