ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
这是XMLWriter扩展。它封装了libxml xmlWriter API 此扩展需要[libxml](https://www.php.net/manual/zh/book.libxml.php)PHP 扩展(默认开启) * [XMLWriter :: endAttribute](https://www.php.net/manual/en/function.xmlwriter-end-attribute.php)—结束属性 * [XMLWriter :: endCdata](https://www.php.net/manual/en/function.xmlwriter-end-cdata.php)—结束当前的CDATA * [XMLWriter :: endComment](https://www.php.net/manual/en/function.xmlwriter-end-comment.php)—创建结束注释 * [XMLWriter :: endDocument](https://www.php.net/manual/en/function.xmlwriter-end-document.php)—结束当前文档 * [XMLWriter :: endDtdAttlist](https://www.php.net/manual/en/function.xmlwriter-end-dtd-attlist.php)—结束当前DTD AttList * [XMLWriter :: endDtdElement](https://www.php.net/manual/en/function.xmlwriter-end-dtd-element.php)—结束当前DTD元素 * [XMLWriter :: endDtdEntity](https://www.php.net/manual/en/function.xmlwriter-end-dtd-entity.php)—结束当前DTD实体 * [XMLWriter :: endDtd](https://www.php.net/manual/en/function.xmlwriter-end-dtd.php)—结束当前DTD * [XMLWriter :: endElement](https://www.php.net/manual/en/function.xmlwriter-end-element.php)—结束当前元素 * [XMLWriter :: endPi](https://www.php.net/manual/en/function.xmlwriter-end-pi.php)—结束当前PI * [XMLWriter :: flush](https://www.php.net/manual/en/function.xmlwriter-flush.php)—刷新当前缓冲区 * [XMLWriter :: fullEndElement](https://www.php.net/manual/en/function.xmlwriter-full-end-element.php)—结束当前元素 * [XMLWriter :: openMemory](https://www.php.net/manual/en/function.xmlwriter-open-memory.php)—使用内存用于字符串输出创建新的xmlwriter * [XMLWriter :: openUri](https://www.php.net/manual/en/function.xmlwriter-open-uri.php)—使用源uri创建新的xmlwriter以进行输出 * [XMLWriter :: outputMemory](https://www.php.net/manual/en/function.xmlwriter-output-memory.php)—返回当前缓冲区 * [XMLWriter :: setIndentString](https://www.php.net/manual/en/function.xmlwriter-set-indent-string.php)—设置用于缩进的字符串 * [XMLWriter :: setIndent](https://www.php.net/manual/en/function.xmlwriter-set-indent.php)—启用/禁用缩进 * [XMLWriter :: startAttributeNs](https://www.php.net/manual/en/function.xmlwriter-start-attribute-ns.php)—创建开始命名空间的属性 * [XMLWriter :: startAttribute](https://www.php.net/manual/en/function.xmlwriter-start-attribute.php)—创建开始属性 * [XMLWriter :: startCdata](https://www.php.net/manual/en/function.xmlwriter-start-cdata.php)—创建开始CDATA标记 * [XMLWriter :: startComment](https://www.php.net/manual/en/function.xmlwriter-start-comment.php)—创建开始注释 * [XMLWriter :: startDocument](https://www.php.net/manual/en/function.xmlwriter-start-document.php)—创建文档标签 * [XMLWriter :: startDtdAttlist](https://www.php.net/manual/en/function.xmlwriter-start-dtd-attlist.php)—创建开始DTD AttList * [XMLWriter :: startDtdElement](https://www.php.net/manual/en/function.xmlwriter-start-dtd-element.php)—创建开始DTD元素 * [XMLWriter :: startDtdEntity](https://www.php.net/manual/en/function.xmlwriter-start-dtd-entity.php)—创建开始DTD实体 * [XMLWriter :: startDtd](https://www.php.net/manual/en/function.xmlwriter-start-dtd.php)—创建开始DTD标记 * [XMLWriter :: startElementNs](https://www.php.net/manual/en/function.xmlwriter-start-element-ns.php)—创建开始命名空间的元素标签 * [XMLWriter :: startElement](https://www.php.net/manual/en/function.xmlwriter-start-element.php)—创建开始元素标签 * [XMLWriter :: startPi](https://www.php.net/manual/en/function.xmlwriter-start-pi.php)—创建开始PI标签 * [XMLWriter :: text](https://www.php.net/manual/en/function.xmlwriter-text.php)—编写文本 * [XMLWriter :: writeAttributeNs](https://www.php.net/manual/en/function.xmlwriter-write-attribute-ns.php)—写入完整的命名空间属性 * [XMLWriter :: writeAttribute](https://www.php.net/manual/en/function.xmlwriter-write-attribute.php)—写完整属性 * [XMLWriter :: writeCdata](https://www.php.net/manual/en/function.xmlwriter-write-cdata.php)—写入完整的CDATA标记 * [XMLWriter :: writeComment](https://www.php.net/manual/en/function.xmlwriter-write-comment.php)—写完整的注释标签 * [XMLWriter :: writeDtdAttlist](https://www.php.net/manual/en/function.xmlwriter-write-dtd-attlist.php)—编写完整的DTD AttList标记 * [XMLWriter :: writeDtdElement](https://www.php.net/manual/en/function.xmlwriter-write-dtd-element.php)—编写完整的DTD元素标签 * [XMLWriter :: writeDtdEntity](https://www.php.net/manual/en/function.xmlwriter-write-dtd-entity.php)—编写完整的DTD实体标签 * [XMLWriter :: writeDtd](https://www.php.net/manual/en/function.xmlwriter-write-dtd.php)—写入完整的DTD标记 * [XMLWriter :: writeElementNs](https://www.php.net/manual/en/function.xmlwriter-write-element-ns.php)—编写完整的命名空间元素标签 * [XMLWriter :: writeElement](https://www.php.net/manual/en/function.xmlwriter-write-element.php)—写完整元素标签 * [XMLWriter :: writePi](https://www.php.net/manual/en/function.xmlwriter-write-pi.php)—[编写](https://www.php.net/manual/en/function.xmlwriter-write-pi.php)一个PI * [XMLWriter :: writeRaw](https://www.php.net/manual/en/function.xmlwriter-write-raw.php)—编写原始XML文本 例子: ``` class XmlConstruct extends XMLWriter { /** * Constructor. * @param string $prm_rootElementName A root element's name of a current xml document * @param string $prm_xsltFilePath Path of a XSLT file. * @access public * @param null */ public function __construct($prm_rootElementName, $prm_xsltFilePath=''){ $this->openMemory(); $this->setIndent(true); $this->setIndentString(' '); $this->startDocument('1.0', 'UTF-8'); if($prm_xsltFilePath){ $this->writePi('xml-stylesheet', 'type="text/xsl" href="'.$prm_xsltFilePath.'"'); } $this->startElement($prm_rootElementName); } /** * Set an element with a text to a current xml document. * @access public * @param string $prm_elementName An element's name * @param string $prm_ElementText An element's text * @return null */ public function setElement($prm_elementName, $prm_ElementText){ $this->startElement($prm_elementName); $this->text($prm_ElementText); $this->endElement(); } /** * Construct elements and texts from an array. * The array should contain an attribute's name in index part * and a attribute's text in value part. * @access public * @param array $prm_array Contains attributes and texts * @return null */ public function fromArray($prm_array){ if(is_array($prm_array)){ foreach ($prm_array as $index => $element){ if(is_array($element)){ $this->startElement($index); $this->fromArray($element); $this->endElement(); } else $this->setElement($index, $element); } } } /** * Return the content of a current xml document. * @access public * @param null * @return string Xml document */ public function getDocument(){ $this->endElement(); $this->endDocument(); return $this->outputMemory(); } /** * Output the content of a current xml document. * @access public * @param null */ public function output(){ header('Content-type: text/xml'); echo $this->getDocument(); } } Example: $contents = array( 'page_title' => 'Generate a XHTML page from XML+XSLT files', 'welcome_msg' => 'Simple XHTML document from XML+XSLT files!', 'prova' => array( "gino" => array( "innergino" => "gino inner value" ), "filo" => "filodata" ), ); $XmlConstruct = new XmlConstruct('root'); $XmlConstruct->fromArray($contents); $XmlConstruct->output(); ```