PHP Класс 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
С версии: 3.0
Автор: Qiang Xue ([email protected])
Наследование: extends TXmlElement
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__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 )

Защищенные методы

Метод Описание
buildElement ( $node ) : TXmlElement Recursively converts DOM XML nodes into TXmlElement

Описание методов

__construct() публичный Метод

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

__toString() публичный Метод

$document = new TXmlDocument(); $document->TagName = 'root'; echo $document; or $document = new TXmlDocument(); $document->TagName = 'root'; $xml = (string)$document;
public __toString ( ) : string
Результат string string representation of this document

buildElement() защищенный Метод

Recursively converts DOM XML nodes into TXmlElement
protected buildElement ( $node ) : TXmlElement
Результат TXmlElement the converted TXmlElement

getEncoding() публичный Метод

public getEncoding ( ) : string
Результат string encoding of this XML document

getVersion() публичный Метод

public getVersion ( ) : string
Результат string version of this XML document

loadFromFile() публичный Метод

Loads and parses an XML document.
public loadFromFile ( $file ) : boolean
Результат boolean whether the XML file is parsed successfully

loadFromString() публичный Метод

The version and encoding will be determined based on the parsing result.
public loadFromString ( $string ) : boolean
Результат boolean whether the XML string is parsed successfully

saveToFile() публичный Метод

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

saveToString() публичный Метод

Saves this XML document as an XML string
public saveToString ( ) : string
Результат string the XML string of this XML document

setEncoding() публичный Метод

public setEncoding ( $encoding )

setVersion() публичный Метод

public setVersion ( $version )