MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | OPTIONAL |
| 2 | EXPERIMENTAL |
| 3 | SYNOPSIS |
| 4 | #include <xml.h> |
| 5 | |
| 6 | string xml_generate(mixed *xml) |
| 7 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 8 | DESCRIPTION |
| 9 | Converts the given <xml> array into an XML conform string, if |
| 10 | possible. The <xml> argument array must have the following structure. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 11 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 12 | It must contain tag arrays of three elements, with the following |
| 13 | indices: |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 14 | |
| 15 | string XML_TAG_NAME |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 16 | The name of the XML tag. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 17 | |
| 18 | mapping XML_TAG_ATTRIBUTES |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 19 | 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 24 | |
| 25 | mixed * XML_TAG_CONTENTS |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 26 | 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 29 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 30 | If the xml tag does not contain anything, the element is |
| 31 | set 0. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 32 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 33 | In case the parameter does not follow these rules, errors are raised. |
| 34 | The method returns a valid XML string otherwise. |
| 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 38 | |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 39 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 40 | EXAMPLES |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 41 | xml_generate(({ "abc", 0, 0 })) -> "<abc/>" |
| 42 | xml_generate(({ "abc", ([ "xyz" : "cde" ]), 0 })) -> "<abc xyz="cde"/>" |
| 43 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 44 | mixed *xml = ({ "book" |
| 45 | , ([ "language" : "common" ]) |
| 46 | , ({ ({ "title" |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 47 | , 0 |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 48 | , ({ "This is a title" }) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 49 | }) |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 50 | , ({ "chapter" |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 51 | , 0 |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 52 | , ({ "This is a chapter" }) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 53 | }) |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 54 | , ({ "chapter" |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 55 | , 0 |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 56 | , ({ "We want " |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 57 | , ({ "b" |
| 58 | , 0 |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 59 | , ({ "bold" }) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 60 | }) |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 61 | , "here" |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 62 | }) |
| 63 | }) |
| 64 | }) |
| 65 | }) |
| 66 | |
| 67 | xml_generate(xml) |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 68 | -> "<book language="common"><title>This is the title</title>" |
| 69 | "<chapter>This is a chapter</chapter><chapter>We want " |
| 70 | "<b>bold</b> here.</chapter></book>" |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 71 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 72 | HISTORY |
| 73 | Added in LDMud 3.3.718. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 74 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 75 | SEE ALSO |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 76 | xml_parse(E) |