Các hàm phân tích cú pháp XML của PHP
Giới thiệu về trình phân tích cú pháp XML của PHP
Các hàm XML cho phép bạn phân tích cú pháp, nhưng không xác thực, các tài liệu XML.
XML là một định dạng dữ liệu để trao đổi tài liệu có cấu trúc được tiêu chuẩn hóa. Có thể tìm thấy thêm thông tin về XML trong Hướng dẫn về XML của chúng tôi .
Tiện ích mở rộng này sử dụng trình phân tích cú pháp Expat XML.
Expat là một trình phân tích cú pháp dựa trên sự kiện, nó xem một tài liệu XML như một chuỗi các sự kiện. Khi một sự kiện xảy ra, nó sẽ gọi một hàm được chỉ định để xử lý nó.
Expat là trình phân tích cú pháp không xác thực và bỏ qua bất kỳ DTD nào được liên kết với tài liệu. Tuy nhiên, nếu tài liệu không được định hình tốt, nó sẽ kết thúc bằng một thông báo lỗi.
Bởi vì nó là một trình phân tích cú pháp dựa trên sự kiện, không xác thực, Expat rất nhanh và rất phù hợp cho các ứng dụng web.
Các hàm phân tích cú pháp XML cho phép bạn tạo trình phân tích cú pháp XML và xác định trình xử lý cho các sự kiện XML.
Cài đặt
Các hàm XML là một phần của lõi PHP. Không cần cài đặt để sử dụng các chức năng này.
Các hàm phân tích cú pháp XML của PHP
Function | Description |
---|---|
utf8_decode() | Decodes an UTF-8 string to ISO-8859-1 |
utf8_encode() | Encodes an ISO-8859-1 string to UTF-8 |
xml_error_string() | Returns an error string from the XML parser |
xml_get_current_byte_index() | Returns the current byte index from the XML parser |
xml_get_current_column_number() | Returns the current column number from the XML parser |
xml_get_current_line_number() | Returns the current line number from the XML parser |
xml_get_error_code() | Returns an error code from the XML parser |
xml_parse() | Parses an XML document |
xml_parse_into_struct() | Parses XML data into an array |
xml_parser_create_ns() | Creates an XML parser with namespace support |
xml_parser_create() | Creates an XML parser |
xml_parser_free() | Frees an XML parser |
xml_parser_get_option() | Returns options from an XML parser |
xml_parser_set_option() | Sets options in an XML parser |
xml_set_character_data_handler() | Sets up the character data handler for the XML parser |
xml_set_default_handler() | Sets up the default data handler for the XML parser |
xml_set_element_handler() | Sets up start and end element handlers for the XML parser |
xml_set_end_namespace_decl_handler() | Sets up the end namespace declaration handler |
xml_set_external_entity_ref_handler() | Sets up the external entity reference handler for the XML parser |
xml_set_notation_decl_handler() | Sets up notation declaration handler for the XML parser |
xml_set_object() | Allows to use XML parser within an object |
xml_set_processing_instruction_handler() | Sets up processing instruction handler |
xml_set_start_namespace_decl_handler() | Sets up the start namespace declaration handler |
xml_set_unparsed_entity_decl_handler() | Sets handler function for unparsed entity declarations |
Các hằng số phân tích cú pháp XML trong PHP
Constant |
---|
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) |