vBulletin v6.0.4

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

Table of Contents

Properties

$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

Methods

__construct()  : mixed
Constructor
__serialize()  : array<string|int, mixed>
__sleep()  : array<string|int, mixed>
__unserialize()  : void
__wakeup()  : void
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()  : array<string|int, mixed>
Get a list from the parsed xml array
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.
parse()  : mixed
Parses XML document into an array
parse_xml()  : bool
Handle encoding issues as well as parsing the XML into an array
set_encoding()  : mixed
Overrides the character encoding for the input XML.
set_target_encoding()  : mixed
Sets the target charset encoding for the parsed XML.

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 = \false

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

__serialize()

public __serialize() : array<string|int, mixed>
Return values
array<string|int, mixed>

__sleep()

public __sleep() : array<string|int, mixed>
Return values
array<string|int, mixed>

__unserialize()

public __unserialize(array<string|int, mixed> $serialized) : void
Parameters
$serialized : array<string|int, 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

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

getList()

Get a list from the parsed xml array

public static getList(array<string|int, mixed> $parentxml, string $listname) : array<string|int, mixed>

A common way to format lists in xml is ...

The problem is a single item is ambiguous

It could be a one element list or it could be a scalar child -- we only know from the context of the data, which the parser doesn't know. Our parser assumes that it is a scalar value unless there are multiple tags with the same name. Therefor so the first is rendered as:

tag['subtag'] = [0 => $element, 1 => $element]

While the second is:

tag['subtag'] = $element.

Rather than handle each list element as a special case if there is only one item in the xml, this function will examine the element passed and if it isn't a 0 indexed array as expect will wrap the single element in an [] call. The first case is not affected and the second is converted to tag['subtag'] = [0 => $element], which is what we'd actually expect.

This is why we should use JSON.

Parameters
$parentxml : array<string|int, mixed>

-- The parsed XML array containing the list. This must be the direct parent of the list

$listname : string

-- The tag name for the list values

Return values
array<string|int, mixed>

the list properly regularized to a numerically indexed array.

handle_cdata()

XML parser callback. Handles CDATA values.

public handle_cdata(mixed $parser, mixed $data) : mixed
Parameters
$parser : mixed
$data : mixed

handle_element_end()

XML parser callback. Handles tag closes.

public handle_element_end(mixed $parser, mixed $name) : mixed
Parameters
$parser : mixed
$name : 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

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

set_encoding()

Overrides the character encoding for the input XML.

public set_encoding(mixed $encoding) : mixed
Parameters
$encoding : 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

        
On this page

Search results