What is the purpose of PHP DOMDocument class?
A
Parsing JSON data B
Parsing XML using a tree-based parser C
Handling CSV files D
Connecting to MySQL
Analysis & Theory
DOMDocument is a tree-based XML parser that allows reading, editing, and creating XML documents.
Which function is used to load an XML file with DOMDocument?
A
loadXMLFile() B
dom_load() C
load() D
loadXML()
Analysis & Theory
`load()` loads XML from a file in the DOMDocument object.
What does `loadXML()` do in PHP DOM?
A
Loads XML from a file B
Loads XML from a string C
Converts XML to JSON D
Saves XML to file
Analysis & Theory
`loadXML()` loads XML data from a string into the DOMDocument object.
Which method retrieves a list of elements by their tag name?
A
getElements() B
getElementsByName() C
getElementsByTagName() D
getTags()
Analysis & Theory
`getElementsByTagName()` returns a list of all elements with the specified tag name.
What does this code do?
```
$dom = new DOMDocument();
$dom->load('books.xml');
$elements = $dom->getElementsByTagName('title');
```
A
Deletes all titles B
Updates the titles C
Retrieves all `<title>` elements from books.xml D
Creates a new XML file
Analysis & Theory
It retrieves all `<title>` elements from the XML file `books.xml`.
How do you access the text content of an XML element in DOMDocument?
A
element->nodeValue B
element->value() C
element->text D
element->innerHTML
Analysis & Theory
`nodeValue` is used to get or set the text content of an XML node.
Which function is used to save the DOMDocument object back to an XML file?
A
saveXMLFile() B
xml_save() C
save() D
writeXML()
Analysis & Theory
`save()` writes the DOMDocument content back to an XML file.
What does `createElement()` do in DOMDocument?
A
Deletes an element B
Creates a new XML element node C
Saves the XML document D
Parses JSON
Analysis & Theory
`createElement()` creates a new XML element node.
How do you append a child node to another node in DOMDocument?
A
addChild() B
append() C
appendChild() D
createChild()
Analysis & Theory
`appendChild()` is used to append a child node to a parent node in DOMDocument.
What is the main difference between DOM and SimpleXML in PHP?
A
DOM is for JSON, SimpleXML is for XML B
DOM is tree-based with more control, SimpleXML is simpler and easier for reading C
DOM is faster than SimpleXML D
SimpleXML edits files, DOM cannot
Analysis & Theory
DOM is a tree-based parser offering fine-grained control, while SimpleXML is easier for reading and simple tasks.