Document 對象代表整個 XML 文檔。
Document 對象是一棵文檔樹的根,可為我們提供對文檔數據的最初(或最頂層)的訪問入口。
用於元素節點、文本節點、注釋、處理指令等均無法存在於 document 之外,document 對象同樣提供了創建這些對象的方法。Node 對象提供了一個 ownerDocument 屬性,此屬性可把它們與在其中創建它們的 Document 關聯起來。
Document 對象的屬性
| 屬性 | 描述 | IE | F | O | W3C |
| async | 規定 XML 檔案的下載是否應當被同步處理。 | 5 | 1.5 | 9 | No |
| childNodes | 返回屬於文檔的子節點的節點列表。 | 5 | 1 | 9 | Yes |
| doctype | 返回與文檔相關的文檔類型聲明 (DTD)。 | 6 | 1 | 9 | Yes |
| documentElement | 返回文檔的根節點 | 5 | 1 | 9 | Yes |
| documentURI | 設定或返回文檔的位置 | No | 1 | 9 | Yes |
| domConfig | 返回normalizeDocument()被調用時所使用的配置 | ​ | ​ | No | Yes |
| firstChild | 返回文檔的首個子節點 | 5 | 1 | 9 | Yes |
| implementation | 返回處理該文檔的 DOMImplementation 對象。 | No | 1 | 9 | Yes |
| inputEncoding | 返回用於文檔的編碼方式(在解析時)。 | No | 1 | No | Yes |
| lastChild | 返回文檔的最後一個子節點。 | 5 | 1 | 9 | Yes |
| nodeName | 依據節點的類型返回其名稱。 | 5 | 1 | 9 | Yes |
| nodeType | 返回節點的節點類型。 | 5 | 1 | 9 | Yes |
| nodeValue | 根據節點的類型來設定或返回節點的值。 | 5 | 1 | 9 | Yes |
| strictErrorChecking | 設定或返回是否強制進行錯誤檢查。 | No | 1 | No | Yes |
| text | 返回節點及其後代的文本(僅用於 IE)。 | 5 | No | No | No |
| xml | 返回節點及其後代的 XML(僅用於 IE)。 | 5 | No | No | No |
| xmlEncoding | 返回文檔的編碼方法。 | No | 1 | No | Yes |
| xmlStandalone | 設定或返回文檔是否為 standalone。 | No | 1 | No | Yes |
| xmlVersion | 設定或返回文檔的 XML 版本。 | No | 1 | No | Yes |
Document 對象的方法
| 屬性 | 描述 | IE | F | O | W3C |
| adoptNode(sourcenode) | 從另一個文檔向本文檔選定一個節點,然後返回被選節點。 | ​ | ​ | No | Yes |
| createAttribute(name) | 創建擁有指定名稱的屬性節點,並返回新的 Attr 對象。 | 6 | 1 | 9 | Yes |
| createAttributeNS(uri,name) | 創建擁有指定名稱和命名空間的屬性節點,並返回新的 Attr 對象。 | ​ | ​ | 9 | Yes |
| createCDATASection() | 創建 CDATA 區段節點。 | 5 | 1 | 9 | Yes |
| createComment() | 創建注釋節點。 | 6 | 1 | 9 | Yes |
| createDocumentFragment() | 創建空的 DocumentFragment 對象,並返回此對象。 | 5 | 1 | 9 | Yes |
| createElement() | 創建元素節點。 | 5 | 1 | 9 | Yes |
| createElementNS() | 創建帶有指定命名空間的元素節點。 | No | 1 | 9 | Yes |
| createEvent() | 創建新的 Event 對象。 | ​ | ​ | ​ | Yes |
| createEntityReference(name) | 創建 EntityReference 對象,並返回此對象。 | 5 | ​ | No | Yes |
| createExpression() | 創建一個XPath表達式以供稍後計算。 | ​ | ​ | ​ | Yes |
| createProcessingInstruction() | 創建 ProcessingInstruction 對象,並返回此對象。 | 5 | ​ | 9 | Yes |
| createRange() | 創建 Range 對象,並返回此對象。 | No | ​ | ​ | Yes |
| evaluate() | 計算一個 XPath 表達式。 | No | 1 | 9 | Yes |
| createTextNode() | 創建文本節點。 | 5 | 1 | 9 | Yes |
| getElementById() | 查找具有指定的唯一 ID 的元素。 | 5 | 1 | 9 | Yes |
| getElementsByTagName() | 返回所有具有指定名稱的元素節點。 | 5 | 1 | 9 | Yes |
| getElementsByTagNameNS() | 返回所有具有指定名稱和命名空間的元素節點。 | No | 1 | 9 | Yes |
| importNode() | 把一個節點從另一個文檔複製到該文檔以便套用。 | ​ | ​ | 9 | Yes |
| loadXML() | 通過解析XML標籤字元串來組成文檔。 | ​ | ​ | ​ | ​ |
| normalizeDocument() | ​ | ​ | ​ | No | Yes |
| renameNode() | 重命名元素或者屬性節點。 | ​ | ​ | No | Yes |