domxml_xmltree
(PHP 4 >= 4.2.0)
domxml_xmltree — Creates a tree of PHP objects from an XML document
Описание
The function parses the XML document in str and returns a tree PHP objects as the parsed document.
This function is isolated from the other functions, which means you cannot access the tree with any of the other functions. Modifying it, for example by adding nodes, makes no sense since there is currently no way to dump it as an XML file.
However this function may be valuable if you want to read a file and investigate the content.
Список параметров
- str
-
The contents of the XML file.
Возвращаемые значения
Returns a tree of Dom objects starting by a DomDocument.
- DomAttribute::name
- DomAttribute::set_value
- DomAttribute::specified
- DomAttribute::value
- DomDocument::add_root
- DomDocument::create_attribute
- DomDocument::create_cdata_section
- DomDocument::create_comment
- DomDocument::create_element_ns
- DomDocument::create_element
- DomDocument::create_entity_reference
- DomDocument::create_processing_instruction
- DomDocument::create_text_node
- DomDocument::doctype
- DomDocument::document_element
- DomDocument::dump_file
- DomDocument::dump_mem
- DomDocument::get_element_by_id
- DomDocument::get_elements_by_tagname
- DomDocument::html_dump_mem
- DomDocument::xinclude
- DomDocumentType::entities
- DomDocumentType::internal_subset
- DomDocumentType::name
- DomDocumentType::notations
- DomDocumentType::public_id
- DomDocumentType::system_id
- DomElement::get_attribute_node
- DomElement::get_attribute
- DomElement::get_elements_by_tagname
- DomElement::has_attribute
- DomElement::remove_attribute
- DomElement::set_attribute_node
- DomElement::set_attribute
- DomElement::tagname
- DomNode::add_namespace
- DomNode::append_child
- DomNode::append_sibling
- DomNode::attributes
- DomNode::child_nodes
- DomNode::clone_node
- DomNode::dump_node
- DomNode::first_child
- DomNode::get_content
- DomNode::has_attributes
- DomNode::has_child_nodes
- DomNode::insert_before
- DomNode::is_blank_node
- DomNode::last_child
- DomNode::next_sibling
- DomNode::node_name
- DomNode::node_type
- DomNode::node_value
- DomNode::owner_document
- DomNode::parent_node
- DomNode::prefix
- DomNode::previous_sibling
- DomNode::remove_child
- DomNode::replace_child
- DomNode::replace_node
- DomNode::set_content
- DomNode::set_name
- DomNode::set_namespace
- DomNode::unlink_node
- DomProcessingInstruction::data
- DomProcessingInstruction::target
- DomXsltStylesheet::process
- DomXsltStylesheet::result_dump_file
- DomXsltStylesheet::result_dump_mem
- domxml_new_doc
- domxml_open_file
- domxml_open_mem
- domxml_version
- domxml_xmltree
- domxml_xslt_stylesheet_doc
- domxml_xslt_stylesheet_file
- domxml_xslt_stylesheet
- domxml_xslt_version
- xpath_eval_expression
- xpath_eval
- xpath_new_context
- xpath_register_ns_auto
- xpath_register_ns
- xptr_eval
- xptr_new_context
Коментарии
This is a genuinely useful function, however, as with any DOM-based markup parser, be mindful of the size of the XML document you are parsing. Representing very large XML files as object structures requires *a lot* of memory and processing, and may even crash your server (which is what happened to my Apache when I tried parsing a 2MB XML file using this function, just for fun... ;).
Replacing line 10 works well, but replacing line 15 causes some errors. I have a tree like:
<admin>
<user level="0">
<username>admin</username>
<password>admin_pass</password>
</user>
<user level="1">
<username>moder</username>
<password>moder_pass</password>
</user>
</admin>
when I remove those brackets only the last <user> is included into array. In this example it would be
<user level="1">
<username>moder</username>
<password>juozux</password>
</user>
no user name admin, etc.
p.s. I don't store passwords in plain text in xml, that was just an example :))
You can modify the returned DomDocument, and dump it as an XML file
by using DomDocument->dump_mem() or DomDocument->dump_file().