--- id: php-xml-simplexml-get title: "PHP XML SimpleXML Get" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["SimpleXML node values", "SimpleXML attributes", "PHP SimpleXML κ°’ 쑰회"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.9 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["php", "programming", "w3schools", "xml", "simplexml"] raw_sources: ["https://www.w3schools.com/php/php_xml_simplexml_get.asp"] applied_in: [] github_commit: "" --- # [[PHP XML SimpleXML Get]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) SimpleXML lets you access node VALUES with `->propertyName` syntax and ATTRIBUTES with `['attrName']` array-bracket syntax on the SAME object β€” `$xml->book[0]->title` reads a nested element, while `$xml->book[0]['category']` reads that same book's attribute, meaning the choice of `->` vs `[]` distinguishes elements from attributes throughout SimpleXML. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **`->propertyName`** β€” reads a child element's value (e.g., `$xml->to`). [S1] - **`[]` on an element or the root** β€” array-indexes into repeated sibling elements (e.g., `$xml->book[0]`, `$xml->book[1]`). [S1] - **`['attrName']`** β€” reads an XML attribute's value (distinct from `->` for elements). [S1] - **`$xml->children()`** β€” used inside `foreach` to loop through all repeated child elements. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Basic node value access: `$xml = simplexml_load_file("note.xml"); echo $xml->to . "
"; echo $xml->from . "
";`. [S1] - Indexed access into repeated elements: `echo $xml->book[0]->title . "
"; echo $xml->book[1]->title;`. [S1] - Looping all books: `foreach($xml->children() as $books) { echo $books->title . ", "; echo $books->author . ", "; echo $books->year . ", "; echo $books->price . "
"; }`. [S1] - Attribute access: `echo $xml->book[0]['category'] . "
"; echo $xml->book[1]->title['lang'];`. [S1] - Looping attributes: `foreach($xml->children() as $books) { echo $books->title['lang']; echo "
"; }`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) μ†ŒμŠ€μ—μ„œ λͺ¨μˆœλ˜λŠ” μ •λ³΄λŠ” λ°œκ²¬λ˜μ§€ μ•ŠμŒ. ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” books.xmlμ—μ„œ μ—¬λŸ¬ μ±…μ˜ 제λͺ©/μ €μž/연도/가격을 순회 좜λ ₯ν•˜λŠ” 것이 SimpleXML 쑰회의 λŒ€ν‘œ μ‹€μ „ 사둀닀. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Looping through repeated elements and their attributes (PHP): ```php $xml = simplexml_load_file("books.xml") or die("Error: Cannot create object"); foreach ($xml->children() as $books) { echo $books->title . ", " . $books->author . ", " . $books->year . ", " . $books->price . "
"; echo $books->title['lang'] . "
"; // attribute of the title element } ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.90 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[PHP Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[PHP XML SimpleXML Read]], [[PHP XML Parser Expat]] - **μ°Έμ‘° λ§₯락:** SimpleXML λ…Έλ“œ/속성 쑰회 β€” Expat 이벀트 기반 νŒŒμ„œ μ±•ν„°λ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” PHP SimpleXML - Get Values β€” https://www.w3schools.com/php/php_xml_simplexml_get.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "PHP SimpleXML - Get Values" page (Astra wiki-curation, P-Reinforce v3.1 format).