00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00031
00032 #ifndef __MXML_ELEMENT_H__
00033 #define __MXML_ELEMENT_H__
00034
00035 #include "zmmf/zmmf.h"
00036
00037 #include "mxml.h"
00038
00039 #include "node.h"
00040
00041 namespace mxml
00042 {
00043
00044 class Element : public Node
00045 {
00046 protected:
00047 zmm::String name;
00048 zmm::Ref<zmm::Array<Attribute> > attributes;
00049 void addAttribute(zmm::Ref<Attribute> attr);
00050 void addAttribute(zmm::String name, zmm::String value, enum mxml_value_type type = mxml_string_type);
00051 bool arrayType;
00052 zmm::String arrayName;
00053 zmm::String textKey;
00054
00055 public:
00056 Element(zmm::String name);
00057 Element(zmm::String name, zmm::Ref<Context> context);
00058 zmm::String getAttribute(zmm::String name);
00059 void setAttribute(zmm::String name, zmm::String value, enum mxml_value_type type = mxml_string_type);
00060 zmm::String getText();
00061 enum mxml_value_type getVTypeText();
00062
00063 inline zmm::String getName() { return name; }
00064 void setName(zmm::String name) { this->name = name; }
00065
00066 int attributeCount();
00067 zmm::Ref<Attribute> getAttribute(int index);
00068
00069 void setText(zmm::String text, enum mxml_value_type type = mxml_string_type);
00070
00071 int childCount(enum mxml_node_types type = mxml_node_all);
00072 zmm::Ref<Node> getChild(int index, enum mxml_node_types type = mxml_node_all, bool remove = false);
00073 zmm::Ref<Node> getFirstChild(enum mxml_node_types type = mxml_node_all) { return getChild(0, type); }
00074 void removeChild(int index, enum mxml_node_types type = mxml_node_all);
00075 void appendChild(zmm::Ref<Node> child);
00076 void insertChild(int index, zmm::Ref<Node> child);
00077
00078 void removeWhitespace();
00079 void indent(int level = 0);
00080
00081 zmm::Ref<Element> getFirstElementChild() { return getElementChild(0); }
00082 zmm::Ref<Element> getElementChild(int index) { return RefCast(getChild(index, mxml_node_element), Element); }
00083 int elementChildCount() { return childCount(mxml_node_element); }
00084
00085 void removeElementChild(int index) { removeChild(index, mxml_node_element); }
00086 bool removeElementChild(zmm::String name, bool removeAll);
00087
00088 void appendElementChild(zmm::Ref<Element> child) { appendChild(RefCast(child, Node)); };
00089 void appendTextChild(zmm::String name, zmm::String text, enum mxml_value_type type = mxml_string_type);
00090
00091 int getChildIdByName(zmm::String name);
00092 zmm::Ref<Element> getChildByName(zmm::String name);
00093 zmm::String getChildText(zmm::String name);
00094
00095 bool isArrayType() { return arrayType; }
00096
00097
00098 zmm::String getArrayName() { return arrayName; }
00099 void setArrayName(zmm::String arrayName) { arrayType = true; this->arrayName = arrayName; }
00100
00101 zmm::String getTextKey() { return textKey; }
00102 void setTextKey(zmm::String textKey) { this->textKey = textKey; }
00103
00104 protected:
00105 virtual void print_internal(zmm::Ref<zmm::StringBuffer> buf, int indent);
00106
00107 friend class Parser;
00108 };
00109
00110
00111 }
00112
00113 #endif // __MXML_ELEMENT_H__