blob: 8c243fc5344f8b3acf3fdc27251a1ccdf13bdbb3 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001OPTIONAL
2EXPERIMENTAL
3SYNOPSIS
4 #include <xml.h>
5
Zesstra715ec202025-07-09 22:18:31 +02006 mixed * xml_parse(string xml)
MG Mud User88f12472016-06-24 23:31:02 +02007
Zesstra715ec202025-07-09 22:18:31 +02008DESCRIPTION
9 Parses the given string <xml> as a XML conform string. The string must
10 have only one root tag, subsequent root tags are ignored.
MG Mud User88f12472016-06-24 23:31:02 +020011
Zesstra715ec202025-07-09 22:18:31 +020012 If the xml string is correct, an array is of three elements is
13 returned, where as the following indices are defined:
MG Mud User88f12472016-06-24 23:31:02 +020014
15 string XML_TAG_NAME
Zesstra715ec202025-07-09 22:18:31 +020016 The name of the XML tag.
MG Mud User88f12472016-06-24 23:31:02 +020017
18 mapping XML_TAG_ATTRIBUTES
Zesstra715ec202025-07-09 22:18:31 +020019 All attributes given to the XML tag as mapping where the key
20 is the attribute name and the value is its string value.
21
22 If the xml tag does not contain any attributes, this element
23 is set 0.
MG Mud User88f12472016-06-24 23:31:02 +020024
25 mixed * XML_TAG_CONTENTS
Zesstra715ec202025-07-09 22:18:31 +020026 The contents of this xml tag as array. This array may
27 contain either strings, or arrays of sub-tags again with
28 three elements (see example)
MG Mud User88f12472016-06-24 23:31:02 +020029
Zesstra715ec202025-07-09 22:18:31 +020030 If the xml tag does not contain anything, the element is
31 set 0.
MG Mud User88f12472016-06-24 23:31:02 +020032
Zesstra715ec202025-07-09 22:18:31 +020033 If the XML string is not well formed, or there is not enough memory to
34 parse the whole XML structure into the array an error is raised.
35
36 The function is available only if the driver is compiled with Iksemel
37 support. In that case, __XML_DOM__ is defined.
MG Mud User88f12472016-06-24 23:31:02 +020038
Zesstrad59c3892019-11-28 20:53:39 +010039
Zesstra715ec202025-07-09 22:18:31 +020040EXAMPLES
MG Mud User88f12472016-06-24 23:31:02 +020041 xml_parse("<abc/>") -> ({ "abc", 0, 0 })
42 xml_parse("<abc xyz="cde"/>") -> ({ "abc", ([ "xyz" : "cde" ]), 0 })
43
Zesstra715ec202025-07-09 22:18:31 +020044 xml_parse("<book language="common">" +
45 " <title>This is the title</title>" +
46 " <chapter>This is a chapter</chapter>" +
47 " <chapter>We want <b>bold</b> here.</chapter>" +
48 "</book>")
MG Mud User88f12472016-06-24 23:31:02 +020049
Zesstra715ec202025-07-09 22:18:31 +020050 -> ({ "book"
51 , ([ "language" : "common" ])
52 , ({ ({ "title"
MG Mud User88f12472016-06-24 23:31:02 +020053 , 0
Zesstra715ec202025-07-09 22:18:31 +020054 , ({ "This is a title" })
MG Mud User88f12472016-06-24 23:31:02 +020055 })
Zesstra715ec202025-07-09 22:18:31 +020056 , ({ "chapter"
MG Mud User88f12472016-06-24 23:31:02 +020057 , 0
Zesstra715ec202025-07-09 22:18:31 +020058 , ({ "This is a chapter" })
MG Mud User88f12472016-06-24 23:31:02 +020059 })
Zesstra715ec202025-07-09 22:18:31 +020060 , ({ "chapter"
MG Mud User88f12472016-06-24 23:31:02 +020061 , 0
Zesstra715ec202025-07-09 22:18:31 +020062 , ({ "We want "
MG Mud User88f12472016-06-24 23:31:02 +020063 , ({ "b"
64 , 0
Zesstra715ec202025-07-09 22:18:31 +020065 , ({ "bold" })
MG Mud User88f12472016-06-24 23:31:02 +020066 })
Zesstra715ec202025-07-09 22:18:31 +020067 , "here"
MG Mud User88f12472016-06-24 23:31:02 +020068 })
69 })
70 })
71 })
72
Zesstra715ec202025-07-09 22:18:31 +020073HISTORY
74 Added in LDMud 3.3.718.
MG Mud User88f12472016-06-24 23:31:02 +020075
Zesstra715ec202025-07-09 22:18:31 +020076SEE ALSO
MG Mud User88f12472016-06-24 23:31:02 +020077 xml_generate(E)