1 module hunt.xml.Common; 2 3 // dfmt off 4 /++ 5 + An integer indicating which type of node this is. 6 + 7 + Note: 8 + Numeric codes up to 200 are reserved to W3C for possible future use. 9 +/ 10 enum NodeType { 11 Element = 1, //!< An element node. Name contains element name. Value contains text of first data node. 12 Attribute, 13 Text, //!< A data node. Name is empty. Value contains data text. 14 CDATA, //!< A CDATA node. Name is empty. Value contains data text. 15 EntityReference, 16 Entity, 17 ProcessingInstruction, //!< A PI node. Name contains target. Value contains instructions. 18 Comment, //!< A comment node. Name is empty. Value contains comment text. 19 Document, //!< A document node. Name and value are empty. 20 DocumentType, //!< A DOCTYPE node. Name is empty. Value contains DOCTYPE text. 21 22 DocumentFragment, 23 Notation, 24 Declaration //!< A declaration node. Name and value are empty. Declaration parameters (version, encoding and standalone) are in node attributes. 25 //!< Value is unencoded text (used for inserting pre-rendered XML). 26 } 27 // dfmt on 28 29 /** 30 * Parsing flags 31 */ 32 enum ParsingFlags { 33 34 /// Parse flag instructing the parser to not create data nodes. 35 /// Text of first data node will still be placed in value of parent element, unless EelementValues flag is also specified. 36 /// Can be combined with other flags by use of | operator. 37 /// <br><br> 38 DataNodes = 0x1, 39 40 /// Parse flag instructing the parser to not use text of first data node as a value of parent element. 41 /// Can be combined with other flags by use of | operator. 42 /// Note that child data nodes of element node take precendence over its value when printing. 43 /// That is, if element has one or more child data nodes <em>and</em> a value, the value will be ignored. 44 /// Use DataNodes flag to prevent creation of data nodes if you want to manipulate data using values of elements. 45 /// <br><br> 46 EelementValues = 0x2, 47 48 /// Parse flag instructing the parser to not place zero terminators after strings in the source text. 49 /// By default zero terminators are placed, modifying source text. 50 /// Can be combined with other flags by use of | operator. 51 /// <br><br> 52 StringTerminators = 0x4, 53 54 /// Parse flag instructing the parser to not translate entities in the source text. 55 /// By default entities are translated, modifying source text. 56 /// Can be combined with other flags by use of | operator. 57 /// <br><br> 58 EntityTranslation = 0x8, 59 60 /// Parse flag instructing the parser to disable UTF-8 handling and assume plain 8 bit characters. 61 /// By default, UTF-8 handling is enabled. 62 /// Can be combined with other flags by use of | operator. 63 /// <br><br> 64 NoUtf8 = 0x10, 65 66 /// Parse flag instructing the parser to create XML declaration node. 67 /// By default, declaration node is not created. 68 /// Can be combined with other flags by use of | operator. 69 /// <br><br> 70 DeclarationNode = 0x20, 71 72 /// Parse flag instructing the parser to create comments nodes. 73 /// By default, comment nodes are not created. 74 /// Can be combined with other flags by use of | operator. 75 /// <br><br> 76 CommentNodes = 0x40, 77 78 /// Parse flag instructing the parser to create DOCTYPE node. 79 /// By default, doctype node is not created. 80 /// Although W3C specification allows at most one DOCTYPE node, RapidXml will silently accept documents with more than one. 81 /// Can be combined with other flags by use of | operator. 82 /// <br><br> 83 DoctypeNode = 0x80, 84 85 /// Parse flag instructing the parser to create PI nodes. 86 /// By default, PI nodes are not created. 87 /// Can be combined with other flags by use of | operator. 88 /// <br><br> 89 PiNodes = 0x100, 90 91 /// Parse flag instructing the parser to validate closing tag names. 92 /// If not set, name inside closing tag is irrelevant to the parser. 93 /// By default, closing tags are not validated. 94 /// Can be combined with other flags by use of | operator. 95 /// <br><br> 96 ValidateClosingTags = 0x200, 97 98 /// Parse flag instructing the parser to trim all leading and trailing whitespace of data nodes. 99 /// By default, whitespace is not trimmed. 100 /// This flag does not cause the parser to modify source text. 101 /// Can be combined with other flags by use of | operator. 102 /// <br><br> 103 TrimWhitespace = 0x400, 104 105 /// Parse flag instructing the parser to condense all whitespace runs of data nodes to a single space character. 106 /// Trimming of leading and trailing whitespace of data is controlled by TrimWhitespace flag. 107 /// By default, whitespace is not normalized. 108 /// If this flag is specified, source text will be modified. 109 /// Can be combined with other flags by use of | operator. 110 /// <br><br> 111 NormalizeWhitespace = 0x800, 112 113 /// Parse flag to say "Parse only the initial element opening." 114 /// Useful for XMLstreams used in XMPP. 115 OpenOnly = 0x1000, 116 117 /// Parse flag to say "Toss the children of the top node and parse off 118 /// one element. 119 /// Useful for parsing off XMPP top-level elements. 120 ParseOne = 0x2000, 121 122 /// Parse flag to say "Validate XML namespaces fully." 123 /// This will generate additional errors, including unbound prefixes 124 /// and duplicate attributes (with different prefices) 125 ValidateXmlns = 0x4000, 126 127 // Compound flags 128 129 /// Parse flags which represent default behaviour of the parser. 130 /// This is always equal to 0, so that all other flags can be simply ored together. 131 /// Normally there is no need to inconveniently disable flags by anding with their negated (~) values. 132 /// This also means that meaning of each flag is a <i>negation</i> of the default setting. 133 /// For example, if flag name is NoUtf8, it means that utf-8 is <i>enabled</i> by default, 134 /// and using the flag will disable it. 135 /// <br><br> 136 Default = 0, 137 138 /// A combination of parse flags that forbids any modifications of the source text. 139 /// This also results in faster parsing. However, note that the following will occur: 140 /// <ul> 141 /// <li>names and values of nodes will not be zero terminated, you have to use xml_base::name_size() and xml_base::value_size() functions to determine where name and value ends</li> 142 /// <li>entities will not be translated</li> 143 /// <li>whitespace will not be normalized</li> 144 /// </ul> 145 NonDestructive = StringTerminators | EntityTranslation, 146 147 /// A combination of parse flags resulting in fastest possible parsing, without sacrificing important data. 148 /// <br><br> 149 Fastest = NonDestructive | DataNodes, 150 151 /// A combination of parse flags resulting in largest amount of data being extracted. 152 /// This usually results in slowest parsing. 153 /// <br><br> 154 Full = DeclarationNode | CommentNodes | DoctypeNode | PiNodes | ValidateClosingTags, 155 } 156 157 /** 158 * 159 */ 160 class XmlParsingException : Exception { 161 this(string msg, string text) { 162 super(msg ~ " " ~ text); 163 } 164 165 this(string msg, char[] text) { 166 super(msg ~ " " ~ cast(string) text.dup); 167 } 168 } 169 170 171 /** 172 * 173 */ 174 class XmlException : Exception { 175 this(string msg) { 176 super(msg); 177 } 178 }