--- 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).