200-710 · Question #173
What SimpleXML function is used to parse a file?
The correct answer is A. simplexml_load_file(). simplexml_load_file() is correct because it accepts a file path (or URL) as its argument and parses the XML file directly into a SimpleXMLElement object, making it the dedicated function for file-based XML parsing in PHP. Why the distractors are wrong: B…
Question
Options
- Asimplexml_load_file()
- Bsimplexml_load_string()
- Cload()
- DloadFile()
- EloadXML()
- FNone of the above.
How the community answered
(28 responses)- A82% (23)
- C11% (3)
- E4% (1)
- F4% (1)
Explanation
simplexml_load_file() is correct because it accepts a file path (or URL) as its argument and parses the XML file directly into a SimpleXMLElement object, making it the dedicated function for file-based XML parsing in PHP.
Why the distractors are wrong:
- B.
simplexml_load_string()- this is a real PHP function, but it parses an XML string already in memory, not a file on disk. - C.
load()- not a standalone SimpleXML function; this is a method on PHP'sDOMDocumentclass, a different XML API. - D.
loadFile()- doesn't exist in PHP's SimpleXML or standard XML libraries. - E.
loadXML()- also aDOMDocumentmethod (parses an XML string), not a SimpleXML function.
Memory tip: Think of it as a two-function family - simplexml_load_**file**() for files, simplexml_load_**string**() for strings. The suffix tells you what you're feeding it. If it doesn't start with simplexml_, it's not in the SimpleXML extension.
Topics
Community Discussion
No community discussion yet for this question.