---
id: php-xml-dom
title: "PHP XML DOM"
category: "Programming_Language"
status: "draft"
verification_status: "conceptual"
canonical_id: ""
aliases: ["DOMDocument", "PHP DOM νμ"]
duplicate_of: ""
source_trust_level: "B"
confidence_score: 0.89
created_at: 2026-07-04
updated_at: 2026-07-04
review_reason: ""
merge_history: []
tags: ["php", "programming", "w3schools", "xml", "dom"]
raw_sources: ["https://www.w3schools.com/php/php_xml_dom.asp"]
applied_in: []
github_commit: ""
---
# [[PHP XML DOM]]
## π― ν μ€ ν΅μ°° (One-line insight)
Looping through DOM child nodes surfaces INVISIBLE `#text` nodes between every real element β the whitespace between XML tags (indentation, line breaks) becomes its own empty text node in the DOM tree, which the source explicitly warns "sometimes cause problems" if you're not aware they're there. [S1]
## π§ ν΅μ¬ κ°λ
(Core concepts)
- **DOM Parser** β tree-based; loads the whole document into memory; memory-intensive for large files; part of PHP core. [S1]
- **`DOMDocument`** β the class used to parse XML into a DOM tree structure. [S1]
- **`->load($filename)`** β loads an XML file into the DOMDocument object. [S1]
- **`->saveXML()`** β serializes the DOM back into an XML string. [S1]
- **`->documentElement`** β the root element of the loaded document. [S1]
- **`->childNodes`** β iterable collection of a node's direct children, INCLUDING whitespace-only `#text` nodes. [S1]
- **`->nodeName` / `->nodeValue`** β the name and value of each node encountered while looping. [S1]
## π μΈλΆ λ΄μ© (Details)
- Load and output: `$xmlDoc = new DOMDocument(); $xmlDoc->load("note.xml"); print $xmlDoc->saveXML();`. [S1]
- Loop through child nodes (revealing whitespace text nodes): `$x = $xmlDoc->documentElement; foreach ($x->childNodes AS $item) { print $item->nodeName . " = " . $item->nodeValue . "
"; }` β output alternates between real elements (`to = Tove`) and empty `#text =` entries from whitespace. [S1]
## βοΈ λͺ¨μ λ° μ
λ°μ΄νΈ (Contradictions & updates)
- **곡백 ν
μ€νΈ λ
Έλμ μ‘΄μ¬**: XML μμ± μ νκ·Έ μ¬μ΄μ κ³΅λ°±μ΄ λ³λμ λΉ ν
μ€νΈ λ
Έλλ‘ μ·¨κΈλλ©°, μ΄λ₯Ό μΈμ§νμ§ λͺ»νλ©΄ λ¬Έμ κ° λ μ μλ€λ μ μ΄ νμΌλ‘ κ²½κ³ λ¨. [S1]
## π οΈ μ μ© μ¬λ‘ (Applied in summary)
νμ¬ λ°κ²¬λ μ€μ μ μ© μ¬λ‘κ° μμ΅λλ€ β note.xmlμ DOM νΈλ¦¬λ‘ λ‘λν΄ μμ λ
Έλλ₯Ό μννλ κ²μ΄ νΈλ¦¬ κΈ°λ° νμ±μ λν μ€μ μ¬λ‘λ€. [S1]
## π» μ½λ ν¨ν΄ (Code patterns)
Looping through DOM child nodes, revealing whitespace text nodes (PHP):
```php
$xmlDoc = new DOMDocument();
$xmlDoc->load("note.xml");
$x = $xmlDoc->documentElement;
foreach ($x->childNodes AS $item) {
print $item->nodeName . " = " . $item->nodeValue . "
";
// includes empty "#text = " entries from whitespace between tags
}
```
## β
κ²μ¦ μν λ° μ λ’°λ
- **μν:** draft
- **κ²μ¦ λ¨κ³:** conceptual
- **μΆμ² μ λ’°λ:** B (W3Schools β widely used educational reference, not a primary standards body)
- **μ λ’° μ μ:** 0.89
- **μ€λ³΅ κ²μ¬ κ²°κ³Ό:** μ κ· μμ± (New discovery)
## π μ§μ κ·Έλν (Knowledge Graph)
- **μμ/루νΈ:** [[PHP Tutorial]]
- **κ΄λ ¨ κ°λ
:** [[PHP XML Parser Expat]], [[PHP AJAX Intro]]
- **μ°Έμ‘° λ§₯λ½:** XML μΉμ
μ λ§μ§λ§ β AJAX μΉμ
μΌλ‘ μ΄μ΄μ§(AJAX XML μ±ν°μμ DOM νμ± μ¬νμ©).
## π μΆμ² (Sources)
- [S1] W3Schools β PHP DOM Parser β https://www.w3schools.com/php/php_xml_dom.asp
## π λ³κ²½ μ΄λ ₯ (Change history)
- 2026-07-04: Initial draft synthesized from the W3Schools "PHP DOM Parser" page (Astra wiki-curation, P-Reinforce v3.1 format).