<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ``` DOMElement extends DOMNode { /* 屬性 */ //尚未實現,始終返回NULL public readonly bool $schemaTypeInfo ; //元素名稱 public readonly string $tagName ; /* 方法 */ //創建一個新的DOMElement對象 public __construct ( string $name [, string $value [, string $namespaceURI ]] ) //返回屬性值 public getAttribute ( string $name ) : string //返回屬性節點 public getAttributeNode ( string $name ) : DOMAttr //回屬性節點 public getAttributeNodeNS ( string $namespaceURI , string $localName ) : DOMAttr //返回屬性值 public getAttributeNS ( string $namespaceURI , string $localName ) : string //通過標記名獲取元素 public getElementsByTagName ( string $name ) : DOMNodeList //通過namespaceURI和localName獲取元素 public getElementsByTagNameNS ( string $namespaceURI , string $localName ) : DOMNodeList //檢查屬性是否存在 public hasAttribute ( string $name ) : bool //檢查屬性是否存在 public hasAttributeNS ( string $namespaceURI , string $localName ) : bool //Removes attribute public removeAttribute ( string $name ) : bool //移除屬性 public removeAttributeNode ( DOMAttr $oldnode ) : bool //移除屬性 public removeAttributeNS ( string $namespaceURI , string $localName ) : bool //添加新屬性 public setAttribute ( string $name , string $value ) : DOMAttr //向元素添加新的屬性節點 public setAttributeNode ( DOMAttr $attr ) : DOMAttr //向元素添加新的屬性節點 public setAttributeNodeNS ( DOMAttr $attr ) : DOMAttr //添加新屬性 public setAttributeNS ( string $namespaceURI , string $qualifiedName , string $value ) : void //聲明名稱指定的屬性為ID類型 public setIdAttribute ( string $name , bool $isId ) : void //聲明節點指定的屬性為ID類型 public setIdAttributeNode ( DOMAttr $attr , bool $isId ) : void //聲明由本地名稱和名稱空間URI指定的屬性為ID類型 public setIdAttributeNS ( string $namespaceURI , string $localName , bool $isId ) : void } ``` 要獲取DOMElement的值,只需獲取nodeValue公共參數(它是從DOMNode繼承的) ``` echo $domElement->nodeValue; ``` 結合所有注釋,獲取節點內部HTML的最簡單方法是使用此函數 ``` function get_inner_html( $node ) { $innerHTML= ''; $children = $node->childNodes; foreach ($children as $child) { $innerHTML .= $child->ownerDocument->saveXML( $child ); } return $innerHTML; } ``` 擁有將文檔/節點/元素轉換為字符串的函數會很好。 無論如何,我使用下面的代碼片段來獲取DOMNode的innerHTML值: ``` function getInnerHTML($Node) { $Body = $Node->ownerDocument->documentElement->firstChild->firstChild; $Document = new DOMDocument(); $Document->appendChild($Document->importNode($Body,true)); return $Document->saveHTML(); } ``` 重命名元素并保留屬性: ``` // 將元素$element的名稱更改為$ newName function renameElement($element, $newName) { $newElement = $element->ownerDocument->createElement($newName); $parentElement = $element->parentNode; $parentElement->insertBefore($newElement, $element); $childNodes = $element->childNodes; while ($childNodes->length > 0) { $newElement->appendChild($childNodes->item(0)); } $attributes = $element->attributes; while ($attributes->length > 0) { $attribute = $attributes->item(0); if (!is_null($attribute->namespaceURI)) { $newElement->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:'.$attribute->prefix, $attribute->namespaceURI); } $newElement->setAttributeNode($attribute); } $parentElement->removeChild($element); } function prettyPrint($d) { $d->formatOutput = true; echo '<pre>'.htmlspecialchars($d->saveXML()).'</pre>'; } $d = new DOMDocument( '1.0' ); $d->loadXML('<?xml version="1.0"?> <library> <data a:foo="1" x="bar" xmlns:a="http://example.com/a"> <invite> <username>jmansa</username> <userid>1</userid> </invite> <update>1</update> </data> </library>'); $xpath = new DOMXPath($d); $elements = $xpath->query('/library/data'); if ($elements->length == 1) { $element = $elements->item(0); renameElement($element, 'invites'); } prettyPrint($d); ``` 盡管使用dom操作元素可能更可取,但有時從文檔元素實際獲取innerHTML很有用(例如,加載到客戶端編輯器中)。 要獲取特定html文件($filepath)中特定元素($elem\_id)的innerHTML: ``` $innerHTML = ''; $doc = new DOMDocument(); $doc->loadHTMLFile($filepath); $elem = $doc->getElementById($elem_id); // loop through all childNodes, getting html $children = $elem->childNodes; foreach ($children as $child) { $tmp_doc = new DOMDocument(); $tmp_doc->appendChild($tmp_doc->importNode($child,true)); $innerHTML .= $tmp_doc->saveHTML(); } ``` 以下代碼顯示可以從文檔中提取純文本內容 ``` function getTextFromNode($Node, $Text = "") { if ($Node->tagName == null) return $Text.$Node->textContent; $Node = $Node->firstChild; if ($Node != null) $Text = getTextFromNode($Node, $Text); while($Node->nextSibling != null) { $Text = getTextFromNode($Node->nextSibling, $Text); $Node = $Node->nextSibling; } return $Text; } function getTextFromDocument($DOMDoc) { return getTextFromNode($DOMDoc->documentElement); } $Doc = new DOMDocument(); $Doc->loadHTMLFile("Test.html"); echo getTextFromDocument($Doc)."\n"; ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看