1 module deepmagic.dom.xml.xml_instruction; 2 3 import deepmagic.dom; 4 5 class XMLInstruction : Item 6 { 7 private string content; 8 9 /** 10 * Construct an XML Instruction section 11 * 12 * Params: 13 * content = the body of the instruction segment 14 * 15 * Throws: XIException if the segment body is illegal (contains ">") 16 * 17 * Examples: 18 * -------------- 19 * auto item = new XMLInstruction("ATTLIST"); 20 * // constructs <!ATTLIST> 21 * -------------- 22 */ 23 this(string content) 24 { 25 if (content.indexOf(">") != -1) throw new XIException(content); 26 this.content = content; 27 } 28 29 /** 30 * Compares two XML instructions for equality 31 * 32 * Examples: 33 * -------------- 34 * XMLInstruction item1,item2; 35 * if (item1 == item2) { } 36 * -------------- 37 */ 38 override bool opEquals(Object o) 39 { 40 const item = toType!(const Item)(o); 41 const t = cast(XMLInstruction)item; 42 return t !is null && content == t.content; 43 } 44 45 /** 46 * Compares two XML instructions 47 * 48 * You should rarely need to call this function. It exists so that 49 * XmlInstructions can be used as associative array keys. 50 * 51 * Examples: 52 * -------------- 53 * XMLInstruction item1,item2; 54 * if (item1 < item2) { } 55 * -------------- 56 */ 57 override int opCmp(Object o) 58 { 59 const item = toType!(const Item)(o); 60 const t = cast(XMLInstruction)item; 61 return t !is null 62 && (content != t.content ? (content < t.content ? -1 : 1 ) : 0 ); 63 } 64 65 /** 66 * Returns the hash of an XMLInstruction 67 * 68 * You should rarely need to call this function. It exists so that 69 * XmlInstructions can be used as associative array keys. 70 */ 71 override size_t toHash() const { return hash(content); } 72 73 /** 74 * Returns a string representation of this XmlInstruction 75 */ 76 override string toString() const { return "<!" ~ content ~ ">"; } 77 78 override @property bool isEmptyXML() const { return false; } /// Returns false always 79 }