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