選單
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

XML 教程

XML HOME XML Introduction XML How to use XML Tree XML Syntax XML Elements XML Attributes XML Namespaces XML Display XML HttpRequest XML Parser XML DOM XML XPath XML XSLT XML XQuery XML XLink XML Validator XML DTD XML Schema XML Server XML Examples XML Quiz XML Certificate

XML AJAX

AJAX Introduction AJAX XMLHttp AJAX Request AJAX Response AJAX XML File AJAX PHP AJAX ASP AJAX Database AJAX Applications AJAX Examples

XML DOM

DOM Introduction DOM Nodes DOM Accessing DOM Node Info DOM Node List DOM Traversing DOM Navigating DOM Get Values DOM Change Nodes DOM Remove Nodes DOM Replace Nodes DOM Create Nodes DOM Add Nodes DOM Clone Nodes DOM Examples

XPath 教程

XPath Introduction XPath Nodes XPath Syntax XPath Axes XPath Operators XPath Examples

XSLT 教程

XSLT Introduction XSL Languages XSLT Transform XSLT <template> XSLT <value-of> XSLT <for-each> XSLT <sort> XSLT <if> XSLT <choose> XSLT Apply XSLT on the Client XSLT on the Server XSLT Edit XML XSLT Examples

XQuery 教程

XQuery Introduction XQuery Example XQuery FLWOR XQuery HTML XQuery Terms XQuery Syntax XQuery Add XQuery Select XQuery Functions

XML DTD

DTD Introduction DTD Building Blocks DTD Elements DTD Attributes DTD Elements vs Attr DTD Entities DTD Examples

XSD Schema

XSD Introduction XSD How To XSD <schema> XSD Elements XSD Attributes XSD Restrictions XSD Complex Elements XSD Empty XSD Elements-only XSD Text-only XSD Mixed XSD Indicators XSD <any> XSD <anyAttribute> XSD Substitution XSD Example

XSD Data Types

XSD String XSD Date/Time XSD Numeric XSD Misc XSD Reference

Web Services

XML Services XML WSDL XML SOAP XML RDF XML RSS

參考手冊

DOM Node Types DOM Node DOM NodeList DOM NamedNodeMap DOM Document DOM Element DOM Attribute DOM Text DOM CDATA DOM Comment DOM XMLHttpRequest DOM Parser XSLT Elements XSLT/XPath Functions

XML DOM - 文件物件


Document 物件代表整個 XML 文件。


XML 文件物件

Document 物件是 XML 文件樹的根,它提供了對文件資料的主要訪問。

由於元素節點、文字節點、註釋、處理指令等不能存在於文件之外,Document 物件還包含建立這些物件的方法。Node 物件有一個 ownerDocument 屬性,該屬性將它們與建立它們的 Document 相關聯。

Document 物件屬性

屬性 描述
childNodes 返回文件的子節點的 NodeList
doctype 返回與文件關聯的文件型別宣告
documentElement 返回文件的根節點
documentURI 設定或返回文件的位置
domConfig 返回呼叫 normalizeDocument() 時使用的配置
firstChild 返回文件的第一個子節點
implementation 返回處理此文件的 DOMImplementation 物件
inputEncoding 返回文件的編碼(解析時)
lastChild 返回文件的最後一個子節點
nodeName 返回節點名稱(取決於其型別)
nodeType 返回節點的節點型別
nodeValue 設定或返回節點的值(取決於其型別)
xmlEncoding 返回文件的 XML 編碼
xmlStandalone 設定或返回文件是否是獨立的
xmlVersion 設定或返回文件的 XML 版本

Document 物件方法

方法 描述
adoptNode(sourcenode) 將一個節點從另一個文件移植到此文件,並返回移植後的節點
createAttribute(name) 建立具有指定名稱的屬性節點,並返回新的 Attr 物件
createAttributeNS(uri,name) 使用指定的名稱和名稱空間建立屬性節點,並返回新的 Attr 物件
createCDATASection() 建立 CDATA 部分節點
createComment() 建立註釋節點
createDocumentFragment() 建立一個空的 DocumentFragment 物件,並返回它
createElement() 建立元素節點
createElementNS() 使用指定的名稱空間建立元素節點
createEntityReference(name) 建立一個實體引用物件,並返回它
createProcessingInstruction(target,data) 建立一個處理指令物件,並返回它
createTextNode() 建立文字節點
getElementById(id) 返回具有給定值的 ID 屬性的元素。如果不存在這樣的元素,則返回 null
getElementsByTagName() 返回所有具有指定名稱的元素的 NodeList
getElementsByTagNameNS() 返回所有具有指定名稱和名稱空間的元素的 NodeList
importNode(nodetoimport,deep) 將一個節點從另一個文件匯入到此文件。此方法會建立源節點的副本。如果 deep 引數設定為 true,則匯入指定節點的所有子節點。如果設定為 false,則僅匯入節點本身。此方法返回匯入的節點
normalizeDocument()  
renameNode() 重新命名元素或屬性節點


DocumentType 物件屬性

每個文件都有一個 DOCTYPE 屬性,其值要麼是 null,要麼是 DocumentType 物件。

DocumentType 物件提供了對 XML 文件定義的實體的介面。

屬性 描述
name 返回 DTD 的名稱
publicId 返回 DTD 的公共識別符號
systemId 返回外部 DTD 的系統識別符號

DocumentImplementation 物件方法

DOMImplementation 物件執行獨立於任何特定文件物件模型例項的操作。

方法 描述
createDocument(nsURI, name, doctype) 建立具有指定 doctype 的新 DOM Document 物件
createDocumentType(name, pubId, systemId) 建立一個空的 DocumentType 節點
getFeature(feature, version) 返回一個實現指定功能和版本的 API 的物件(如果存在)
hasFeature(feature, version) 檢查 DOM 實現是否實現了特定的功能和版本

ProcessingInstruction 物件屬性

ProcessingInstruction 物件表示一個處理指令。

處理指令用於在 XML 文件文字中保留特定於處理器的資訊。

屬性 描述
data 設定或返回此處理指令的內容
target 返回此處理指令的目標

×

聯絡銷售

如果您想將 W3Schools 服務用於教育機構、團隊或企業,請傳送電子郵件給我們
sales@w3schools.com

報告錯誤

如果您想報告錯誤,或想提出建議,請傳送電子郵件給我們
help@w3schools.com

W3Schools 經過最佳化,旨在方便學習和培訓。示例可能經過簡化,以提高閱讀和學習體驗。教程、參考資料和示例會不斷審查,以避免錯誤,但我們無法保證所有內容的完全正確性。使用 W3Schools 即表示您已閱讀並接受我們的使用條款Cookie 和隱私政策

版權所有 1999-2024 Refsnes Data。保留所有權利。W3Schools 由 W3.CSS 提供支援