parse_xml
Parse an XML string into a dynamic value.
Each element becomes a property keyed by its name. Attributes become
properties named @ plus the attribute name, and character data becomes
#text. Repeated sibling elements become an array. An element with no
attributes and no content is null. An element holding only text and no
attributes is that text, read as a long or a real when it is unsigned
digits with at most one dot; attribute values are read the same way.
The parser never reads a DTD. A <!DOCTYPE> is skipped, entities it
declares are not expanded, and nothing external is ever fetched: only the
five predefined entities and numeric character references are decoded,
and any other &name; stays as written.
Malformed XML, an invalid character reference, nesting deeper than 128 elements and input over 1 MiB give null. A dynamic argument is returned unchanged.
Syntax
parse_xml(xml)Parameters
Prop
Type
Returns: dynamic
Examples
Example 1
print parse_xml('<event id="7"><source>auth</source><code>401</code></event>')| print_0 (dynamic) |
|---|
| {"event":{"@id":7,"code":401,"source":"auth"}} |
Example 2
print parse_xml('<a><b>1</b><b>2</b><c x="y"/></a>').a.b| print_0 (dynamic) |
|---|
| [1,2] |