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
Показать файл
Открыть проект
Примеры использования класса
Открытые методы
Защищенные методы
Метод |
Описание |
|
buildElement ( $node ) : TXmlElement |
Recursively converts DOM XML nodes into TXmlElement |
|
Описание методов
__construct()
публичный Метод
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;
buildElement()
защищенный Метод
Recursively converts DOM XML nodes into TXmlElement
protected buildElement ( $node ) : TXmlElement |
Результат |
TXmlElement |
the converted TXmlElement |
getEncoding()
публичный Метод
getVersion()
публичный Метод
loadFromFile()
публичный Метод
Loads and parses an XML document.
loadFromString()
публичный Метод
The version and encoding will be determined based on the parsing result.
saveToFile()
публичный Метод
Saves this XML document as an XML file.
saveToString()
публичный Метод
Saves this XML document as an XML string
setEncoding()
публичный Метод
setVersion()
публичный Метод