Class TXmlDocument
TXmlDocument class.
TXmlDocument represents a DOM representation of an XML file. Besides all properties and methods inherited from TXmlElement, you can load an XML file or string by loadFromFile or 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: The above code represents the following XML string: - <?xml version="1.0" encoding="utf-8"?>
- <Root>
- <Proc Name="xxxx">
- <Query ID="xxxx">
- <Attr Name="aaa">1</Attr>
- <Attr Name="bbb">1</Attr>
- </Query>
- </Proc>
- </Root>
| Constructor Summary |
| public |
Constructor.
|
| Method Summary |
|
string
|
|
|
string
|
|
|
boolean
|
Loads and parses an XML document.
|
|
boolean
|
Loads and parses an XML string.
|
|
void
|
Saves this XML document as an XML file.
|
|
string
|
Saves this XML document as an XML string
|
|
void
|
|
|
void
|
|
|
string
|
Magic-method override. Called whenever this document is used as a string.
|
| Methods Inherited From TXmlElement |
|
TXmlElement::getAttribute(), TXmlElement::getAttributes(), TXmlElement::getElementByTagName(), TXmlElement::getElements(), TXmlElement::getElementsByTagName(), TXmlElement::getHasAttribute(), TXmlElement::getHasElement(), TXmlElement::getParent(), TXmlElement::getTagName(), TXmlElement::getValue(), TXmlElement::setAttribute(), TXmlElement::setParent(), TXmlElement::setTagName(), TXmlElement::setValue(), TXmlElement::toString(), TXmlElement::__toString()
|
| Methods Inherited From TComponent |
|
TComponent::addParsedObject(), TComponent::attachEventHandler(), TComponent::canGetProperty(), TComponent::canSetProperty(), TComponent::createdOnTemplate(), TComponent::detachEventHandler(), TComponent::evaluateExpression(), TComponent::evaluateStatements(), TComponent::getEventHandlers(), TComponent::getSubProperty(), TComponent::hasEvent(), TComponent::hasEventHandler(), TComponent::hasProperty(), TComponent::raiseEvent(), TComponent::setSubProperty(), TComponent::__get(), TComponent::__set()
|
| Constructor Details |
__construct
Constructor.
|
| Method Details |
getEncoding
| public string getEncoding |
() |
| Output |
|
string
| encoding of this XML document |
| Exception |
|
getVersion
| public string getVersion |
() |
| Output |
|
string
| version of this XML document |
| Exception |
|
loadFromFile
| public boolean loadFromFile |
(string $file ) |
Loads and parses an XML document.
| Input |
| string | $file | the XML file path |
| Output |
|
boolean
| whether the XML file is parsed successfully |
| Exception |
| throws | TIOException if the file fails to be opened. |
|
loadFromString
| public boolean loadFromString |
(string $string ) |
Loads and parses an XML string.
The version and encoding will be determined based on the parsing result.
| Input |
| string | $string | the XML string |
| Output |
|
boolean
| whether the XML string is parsed successfully |
| Exception |
|
saveToFile
| public void saveToFile |
(string $file ) |
Saves this XML document as an XML file.
| Input |
| string | $file | the name of the file to be stored with XML output |
| Output |
| Exception |
| throws | TIOException if the file cannot be written |
|
saveToString
| public string saveToString |
() |
Saves this XML document as an XML string
| Output |
|
string
| the XML string of this XML document |
| Exception |
|
setEncoding
| public void setEncoding |
(string $encoding ) |
| Input |
| string | $encoding | encoding of this XML document |
| Output |
| Exception |
|
setVersion
| public void setVersion |
(string $version ) |
| Input |
| string | $version | version of this XML document |
| Output |
| Exception |
|
__toString
| public string __toString |
() |
Magic-method override. Called whenever this document is used as a string.
- $document = new TXmlDocument();
- $document->TagName = 'root';
- echo $document;
or - $document = new TXmlDocument();
- $document->TagName = 'root';
- $xml = (string)$document;
| Output |
|
string
| string representation of this document |
| Exception |
|
|