vB_XML_Parser
in package
Uses
vB_Trait_NoSerialize
vBulletin XML Parsing Object
This class allows the parsing of an XML document to an array
Tags
Table of Contents
- $include_first_tag : bool
- Kludge to include the top level element since this parser was written to not return it and now all of the XML functions assume it to not be there
- $cdata : string
- Current CData being parsed
- $encoding : string
- The encoding of the input xml.
- $error_code : int
- Error code from XML object prior to releases of resources. This needs to be done to avoid a segfault in PHP 4. See Bug#24425
- $error_line : int
- Error line number from XML object prior to releases of resources. This needs to be done to avoid a segfault in PHP 4. See Bug#24425
- $error_no : int
- Error number (0 for no error)
- $escape_html : bool
- Whether to escape html in cdata.
- $legacy_mode : bool
- Whether to behave in legacy mode for compatibility.
- $ncr_encode : bool
- Specifies whether to NCR encode multibyte.
- $parseddata : array<string|int, mixed>
- The final, outputtable data
- $stack : array<string|int, mixed>
- Intermediate stack value used while parsing.
- $tag_count : int
- Number of tags open currently
- $target_encoding : string
- Specified target encoding.
- $xmldata : int
- The actual XML data being processed
- $memory_checked : mixed
- __construct() : mixed
- Constructor
- __serialize() : mixed
- __sleep() : mixed
- __unserialize() : mixed
- __wakeup() : mixed
- add_node() : mixed
- Adds node with appropriate logic, multiple values get added to array where unique are their own entry
- disable_legacy_mode() : mixed
- Disables legacy mode.
- encode() : string
- Encodes data to the target encoding.
- error_code() : int
- Returns parser error code
- error_line() : int
- Returns parser error line number
- error_no() : int
- Returns parser error number
- error_string() : mixed
- Returns parser error string
- get_target_encoding() : mixed
- getList() : mixed
- Get the list array for a sub element.
- handle_cdata() : mixed
- XML parser callback. Handles CDATA values.
- handle_element_end() : mixed
- XML parser callback. Handles tag closes.
- handle_element_start() : mixed
- XML parser callback. Handles tag opens.
- legacy_parse_xml() : bool
- Handle encoding issues as well as parsing the XML into an array
- parse() : mixed
- Parses XML document into an array
- parse_xml() : bool
- Handle encoding issues as well as parsing the XML into an array
- resolve_target_encoding() : mixed
- Resolves the target encoding of the output.
- set_encoding() : mixed
- Overrides the character encoding for the input XML.
- set_target_encoding() : mixed
- Sets the target charset encoding for the parsed XML.
- unescape_cdata() : mixed
- Adds node with appropriate logic, multiple values get added to array where unique are their own entry
Properties
$include_first_tag
Kludge to include the top level element since this parser was written to not return it and now all of the XML functions assume it to not be there
public
bool
$include_first_tag
= alse
$cdata
Current CData being parsed
protected
string
$cdata
= ''
$encoding
The encoding of the input xml.
protected
string
$encoding
This can be overridden by the client code.
Tags
$error_code
Error code from XML object prior to releases of resources. This needs to be done to avoid a segfault in PHP 4. See Bug#24425
protected
int
$error_code
= 0
$error_line
Error line number from XML object prior to releases of resources. This needs to be done to avoid a segfault in PHP 4. See Bug#24425
protected
int
$error_line
= 0
$error_no
Error number (0 for no error)
protected
int
$error_no
= 0
$escape_html
Whether to escape html in cdata.
protected
bool
$escape_html
$legacy_mode
Whether to behave in legacy mode for compatibility.
protected
bool
$legacy_mode
= rue
Tags
$ncr_encode
Specifies whether to NCR encode multibyte.
protected
bool
$ncr_encode
By default this is disabled and out of range characters will be displayed incorrectly.
$parseddata
The final, outputtable data
protected
array<string|int, mixed>
$parseddata
= array()
$stack
Intermediate stack value used while parsing.
protected
array<string|int, mixed>
$stack
= array()
$tag_count
Number of tags open currently
protected
int
$tag_count
= 0
$target_encoding
Specified target encoding.
protected
string
$target_encoding
If this is not set then the target encoding will be resolved from language settings.
Tags
$xmldata
The actual XML data being processed
protected
int
$xmldata
= ''
$memory_checked
private
static mixed
$memory_checked
= alse
Methods
__construct()
Constructor
public
__construct(mixed $xml[, mixed $path = '' ][, mixed $readencoding = false ][, mixed $extend_memory = true ]) : mixed
Parameters
- $xml : mixed
- $path : mixed = ''
- $readencoding : mixed = false
- $extend_memory : mixed = true
Return values
mixed —__serialize()
public
__serialize() : mixed
Return values
mixed —__sleep()
public
__sleep() : mixed
Return values
mixed —__unserialize()
public
__unserialize(mixed $serialized) : mixed
Parameters
- $serialized : mixed
Return values
mixed —__wakeup()
public
__wakeup() : mixed
Return values
mixed —add_node()
Adds node with appropriate logic, multiple values get added to array where unique are their own entry
public
add_node(mixed &$children, mixed $name, mixed $value) : mixed
Parameters
- $children : mixed
- $name : mixed
- $value : mixed
Return values
mixed —disable_legacy_mode()
Disables legacy mode.
public
disable_legacy_mode([mixed $disable = true ]) : mixed
With legacy mode disabled character encoding is handled correctly however legacy dependencies will break.
Parameters
- $disable : mixed = true
Return values
mixed —encode()
Encodes data to the target encoding.
public
encode(mixed $data) : string
Parameters
- $data : mixed
Return values
string —The reencoded string
error_code()
Returns parser error code
public
error_code() : int
Return values
int —error line code
error_line()
Returns parser error line number
public
error_line() : int
Return values
int —error line number
error_no()
Returns parser error number
public
error_no() : int
Return values
int —error number
error_string()
Returns parser error string
public
error_string() : mixed
Return values
mixed —error message
get_target_encoding()
public
get_target_encoding() : mixed
Return values
mixed —getList()
Get the list array for a sub element.
public
static getList(mixed $xmlArray) : mixed
Consider a standard list:
This is interpreted as a list and products array('tag' => array('value2'));
However if there is only one item in the list, the xml is ambiguous
This is interpreted as a single field of the parent elements This is interpreted as a list and products array('tag' => 'value2');
There is no way for the parser to know if the latter should be an element with one field, or a list with one item. This function assumes that the value is a list and looks for the single element and converts it to a single element list. If there are multiple elements it will automatically force the element into an array.
usage is vB_XML_Parser::getList($var['tag']);
Parameters
- $xmlArray : mixed
Return values
mixed —handle_cdata()
XML parser callback. Handles CDATA values.
public
handle_cdata(mixed $parser, mixed $data) : mixed
Parameters
- $parser : mixed
- $data : mixed
Return values
mixed —handle_element_end()
XML parser callback. Handles tag closes.
public
handle_element_end(mixed $parser, mixed $name) : mixed
Parameters
- $parser : mixed
- $name : mixed
Return values
mixed —handle_element_start()
XML parser callback. Handles tag opens.
public
handle_element_start(mixed $parser, mixed $name, mixed $attribs) : mixed
Parameters
- $parser : mixed
- $name : mixed
- $attribs : mixed
Return values
mixed —legacy_parse_xml()
Handle encoding issues as well as parsing the XML into an array
public
legacy_parse_xml() : bool
Return values
bool —Success
parse()
Parses XML document into an array
public
parse([mixed $encoding = 'ISO-8859-1' ][, mixed $emptydata = true ]) : mixed
Parameters
- $encoding : mixed = 'ISO-8859-1'
- $emptydata : mixed = true
Return values
mixed —array or false on error
parse_xml()
Handle encoding issues as well as parsing the XML into an array
public
parse_xml() : bool
Return values
bool —Success
resolve_target_encoding()
Resolves the target encoding of the output.
public
resolve_target_encoding() : mixed
Return values
mixed —set_encoding()
Overrides the character encoding for the input XML.
public
set_encoding(mixed $encoding) : mixed
Parameters
- $encoding : mixed
Return values
mixed —set_target_encoding()
Sets the target charset encoding for the parsed XML.
public
set_target_encoding(mixed $target_encoding[, mixed $ncr_encode = false ][, mixed $escape_html = false ]) : mixed
Parameters
- $target_encoding : mixed
- $ncr_encode : mixed = false
- $escape_html : mixed = false
Return values
mixed —unescape_cdata()
Adds node with appropriate logic, multiple values get added to array where unique are their own entry
public
unescape_cdata(mixed $xml) : mixed
Parameters
- $xml : mixed