PHP - XML Parser
XML stands for eXtensible Markup Language, and it is a data format for structured document exchange on the Web. It is a standard defined by The World Wide Web consortium (W3C).
This PHP extension uses the Expat XML parser. Expat is an event-based parser, it views an XML document as a series of events. When an event occurs, it calls a specified function to handle it.
Expat lets you parse, but not validate, XML documents. It supports three source character encodings also provided by PHP: US-ASCII, ISO-8859-1 and UTF-8. UTF-16 is not supported.
Because it is an event-based, non validating parser, Expat is fast and well suited for web applications. This extension lets you create XML parsers and then define handlers for different XML events.
Installation
There is no installation needed to use this extension. This extension is a part of the PHP core. This extension is enabled by default. It may be disabled by using the following option at compile time: --disable-xml.
Runtime Configuration
This extension has no configuration directives defined in php.ini.
PHP XML Parser Functions
Functions | Description |
---|---|
utf8_decode() | Decodes a UTF-8 string to ISO-8859-1. |
utf8_encode() | Encodes an ISO-8859-1 string to UTF-8. |
xml_get_current_byte_index() | Get current byte index for an XML parser. |
xml_get_current_column_number() | Get current column number for an XML parser. |
xml_get_current_line_number() | Get current line number for an XML parser. |
xml_get_error_code() | Get XML parser error code. |
xml_error_string() | Get XML parser error string. |
xml_parse() | Start parsing an XML document. |
xml_parse_into_struct() | Parse XML data into an array structure. |
xml_parser_create() | Create an XML parser. |
xml_parser_create_ns() | Create an XML parser with namespace support. |
xml_parser_free() | Free an XML parser. |
xml_parser_get_option() | Get options from an XML parser. |
xml_parser_set_option() | Set options in an XML parser. |
xml_set_character_data_handler() | Set up character data handler. |
xml_set_default_handler() | Set up default handler. |
xml_set_element_handler() | Set up start and end element handlers. |
xml_set_end_namespace_decl_handler() | Set up end namespace declaration handler. |
xml_set_external_entity_ref_handler() | Set up external entity reference handler. |
xml_set_notation_decl_handler() | Set up notation declaration handler. |
xml_set_object() | Use XML Parser within an object. |
xml_set_processing_instruction_handler() | Set up processing instruction (PI) handler. |
xml_set_start_namespace_decl_handler() | Set up start namespace declaration handler. |
xml_set_unparsed_entity_decl_handler() | Set up unparsed entity declaration handler. |
PHP XML Parser Predefined Constants
The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.
Constants |
---|
XML_ERROR_NONE (Integer) |
XML_ERROR_NO_MEMORY (Integer) |
XML_ERROR_SYNTAX (Integer) |
XML_ERROR_NO_ELEMENTS (Integer) |
XML_ERROR_INVALID_TOKEN (Integer) |
XML_ERROR_UNCLOSED_TOKEN (Integer) |
XML_ERROR_PARTIAL_CHAR (Integer) |
XML_ERROR_TAG_MISMATCH (Integer) |
XML_ERROR_DUPLICATE_ATTRIBUTE (Integer) |
XML_ERROR_JUNK_AFTER_DOC_ELEMENT (Integer) |
XML_ERROR_PARAM_ENTITY_REF (Integer) |
XML_ERROR_UNDEFINED_ENTITY (Integer) |
XML_ERROR_RECURSIVE_ENTITY_REF (Integer) |
XML_ERROR_ASYNC_ENTITY (Integer) |
XML_ERROR_BAD_CHAR_REF (Integer) |
XML_ERROR_BINARY_ENTITY_REF (Integer) |
XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF (Integer) |
XML_ERROR_MISPLACED_XML_PI (Integer) |
XML_ERROR_UNKNOWN_ENCODING (Integer) |
XML_ERROR_INCORRECT_ENCODING (Integer) |
XML_ERROR_UNCLOSED_CDATA_SECTION (Integer) |
XML_ERROR_EXTERNAL_ENTITY_HANDLING (Integer) |
XML_OPTION_CASE_FOLDING (Integer) |
XML_OPTION_TARGET_ENCODING (Integer) |
XML_OPTION_SKIP_TAGSTART (Integer) |
XML_OPTION_SKIP_WHITE (Integer) |
XML_SAX_IMPL (String) - Holds the SAX implementation method. Can be libxml or expat. |