Max 5 API Reference
00001 #ifndef __JIT_XML_H__ 00002 #define __JIT_XML_H__ 00003 00004 /* 00005 a minimal DOM implementation informed by W3 Document Object Model (Core) Level: 00006 http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core.html 00007 00008 The DOM presents documents as a hierarchy of Node objects that also implement other, 00009 more specialized interfaces. Some types of nodes may have child nodes of various types, 00010 and others are leaf nodes that cannot have anything below them in the document structure. 00011 The node types, and which node types they may have as children, are as follows: 00012 00013 00014 - Document: Element (maximum of one), ProcessingInstruction, Comment, DocumentType 00015 * DocumentFragment: Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference 00016 (*) DocumentType: no children 00017 * EntityReference: Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference 00018 - Element: Element, Text, Comment, ProcessingInstruction, CDATASection, EntityReference 00019 - Attr: Text, EntityReference 00020 * ProcessingInstruction: no children 00021 - Comment: no children 00022 - Text: no children 00023 - CDATASection: no children 00024 * Entity: Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference 00025 * Notation: no children 00026 00027 currently no support for items marked with * 00028 later could move into kernel if desired 00029 00030 */ 00031 00032 // everything is a subclass of xml node. so for convenience, we begin each object struct with 00033 // t_jit_xml_node. comment, text, and cdata objects all begin with a t_jit_xml_charnode object 00034 00035 typedef struct _jit_xml_node 00036 { 00037 t_object ob; 00038 t_symbol *nodename; 00039 t_atom *nodevalue; // atom list 00040 long nodevaluecount; 00041 char *nodestring; 00042 t_symbol *nodetype; 00043 struct _jit_xml_node *parentnode; 00044 t_jit_linklist *childnodes; 00045 struct _jit_xml_node *firstchild; 00046 struct _jit_xml_node *lastchild; 00047 struct _jit_xml_node *previoussibling; 00048 struct _jit_xml_node *nextsibling; 00049 t_jit_linklist *attributes; 00050 struct _jit_xml_document *ownerdocument; 00051 char nodeflags; 00052 } t_jit_xml_node; 00053 00054 // nodeflags 00055 enum { 00056 NODE_VALUE_NOT_SET = 0, 00057 NODE_VALUE_SET_AS_ATOMS, 00058 NODE_VALUE_SET_AS_STRING 00059 }; 00060 00061 typedef struct _jit_xml_charnode 00062 { 00063 t_jit_xml_node node; 00064 // might want to move the following into a jit_string class. 00065 // we don't have any 16bit char support currently, but DOM 00066 // specifies that DOMString types should be in such a format 00067 long length; 00068 char *data; 00069 } t_jit_xml_charnode; 00070 00071 typedef struct _jit_xml_text 00072 { 00073 t_jit_xml_charnode charnode; 00074 } t_jit_xml_text; 00075 00076 typedef struct _jit_xml_comment 00077 { 00078 t_jit_xml_charnode charnode; 00079 } t_jit_xml_comment; 00080 00081 typedef struct _jit_xml_cdata 00082 { 00083 t_jit_xml_charnode charnode; 00084 } t_jit_xml_cdata; 00085 00086 typedef struct _jit_xml_attribute 00087 { 00088 t_jit_xml_node node; 00089 long specified; 00090 } t_jit_xml_attribute; 00091 00092 typedef struct _jit_xml_element 00093 { 00094 t_jit_xml_node node; 00095 char singletag; // is single tag 00096 } t_jit_xml_element; 00097 00098 typedef struct _jit_xml_document 00099 { 00100 t_jit_xml_node node; 00101 t_symbol *filename; 00102 short path; 00103 t_jit_xml_node *parsernode; 00104 long parserdepth; 00105 char hasheader; 00106 t_symbol *encoding; // without header, this is UTF-8 by default 00107 } t_jit_xml_document; 00108 00109 // prototypes 00110 00111 // jit_xml_node 00112 t_jit_err jit_xml_node_addinterface(t_class *c); 00113 t_jit_err jit_xml_node_insertbefore(t_jit_xml_node *x, t_jit_xml_node *newchild, t_jit_xml_node *refchild); 00114 t_jit_err jit_xml_node_replacechild(t_jit_xml_node *x, t_jit_xml_node *newchild, t_jit_xml_node *refchild); 00115 t_jit_err jit_xml_node_removechild(t_jit_xml_node *x, t_jit_xml_node *refchild); 00116 t_jit_err jit_xml_node_appendchild(t_jit_xml_node *x, t_jit_xml_node *newchild); 00117 long jit_xml_node_haschildnodes(t_jit_xml_node *x); 00118 t_jit_xml_node *jit_xml_node_clonenode(t_jit_xml_node *x, long deep); 00119 t_jit_err jit_xml_node_removeallchildren(t_jit_xml_node *x); 00120 t_jit_err jit_xml_node_nodevalue(t_jit_xml_node *x, void *attr, long ac, t_atom *av); 00121 t_jit_err jit_xml_node_getnodevalue(t_jit_xml_node *x, void *attr, long *ac, t_atom **av); 00122 t_jit_err jit_xml_node_setnodevalasstring(t_jit_xml_node *x, char *s); 00123 t_jit_err jit_xml_node_getnodevalasstring(t_jit_xml_node *x, long *len, char **s); 00124 t_jit_err jit_xml_node_new(t_jit_xml_node *x, t_symbol *nodetype); 00125 t_jit_err jit_xml_node_free(t_jit_xml_node *x); 00126 // utils 00127 t_symbol *jit_xml_node_getnodevalue_sym(t_jit_xml_node *x); 00128 t_jit_err jit_xml_node_nodevalue_sym(t_jit_xml_node *x, t_symbol *s); 00129 long jit_xml_node_getnodevalue_long(t_jit_xml_node *x); 00130 t_jit_err jit_xml_node_nodevalue_long(t_jit_xml_node *x, long c); 00131 float jit_xml_node_getnodevalue_float(t_jit_xml_node *x); 00132 t_jit_err jit_xml_node_nodevalue_float(t_jit_xml_node *x, float f); 00133 long jit_xml_node_getnodevalue_sym_array(t_jit_xml_node *x, long max, t_symbol **vals); 00134 t_jit_err jit_xml_node_nodevalue_sym_array(void *x, long count, t_symbol **vals); 00135 long jit_xml_node_getnodevalue_long_array(t_jit_xml_node *x, long max, long *vals); 00136 t_jit_err jit_xml_node_nodevalue_long_array(void *x, long count, long *vals); 00137 long jit_xml_node_getnodevalue_float_array(t_jit_xml_node *x, long max, float *vals); 00138 t_jit_err jit_xml_node_nodevalue_float_array(void *x, long count, float *vals); 00139 00140 00141 // jit_xml_charnode 00142 t_jit_err jit_xml_charnode_addinterface(t_class *c); 00143 char *jit_xml_charnode_substringdata(t_jit_xml_charnode *x, long offset, long count); 00144 t_jit_err jit_xml_charnode_appenddata(t_jit_xml_charnode *x, char *data); 00145 t_jit_err jit_xml_charnode_insertdata(t_jit_xml_charnode *x, long offset, char *data); 00146 t_jit_err jit_xml_charnode_deletedata(t_jit_xml_charnode *x, long offset, long count); 00147 t_jit_err jit_xml_charnode_replacedata(t_jit_xml_charnode *x, long offset, long count, char *data); 00148 t_jit_err jit_xml_charnode_new(t_jit_xml_charnode *x, t_symbol *nodetype); 00149 t_jit_err jit_xml_charnode_free(t_jit_xml_charnode *x); 00150 00151 // jit_xml_document 00152 t_jit_err jit_xml_init(void); 00153 void jit_xml_document_filename(t_jit_xml_document *x, t_object *attr, long argc, t_atom *argv); 00154 t_jit_err jit_xml_document_read(t_jit_xml_document *x, t_symbol *s, long ac, t_atom *av); 00155 t_jit_err jit_xml_document_write(t_jit_xml_document *x, t_symbol *s, long ac, t_atom *av); 00156 void jit_xml_node_write(t_jit_xml_node *x, t_filehandle fh, long depth); 00157 void jit_xml_document_print(t_jit_xml_document *x); 00158 t_jit_xml_element *jit_xml_document_createelement(t_jit_xml_document *x, t_symbol *tagname); 00159 t_jit_xml_text *jit_xml_document_createtextnode(t_jit_xml_document *x, char *data); 00160 t_jit_xml_comment *jit_xml_document_createcomment(t_jit_xml_document *x, char *data); 00161 t_jit_xml_cdata *jit_xml_document_createcdatasection(t_jit_xml_document *x, char *data); 00162 t_jit_xml_attribute *jit_xml_document_createattribute(t_jit_xml_document *x, t_symbol *name); 00163 t_jit_linklist *jit_xml_document_getelementsbytagname(t_jit_xml_document *x, t_symbol *tagname); 00164 void jit_xml_document_xmlparse_element_start(t_jit_xml_document *x, const char *el, const char **attr); 00165 void jit_xml_document_xmlparse_element_end(t_jit_xml_document *x, const char *el); 00166 void jit_xml_document_xmlparse_default(t_jit_xml_document *x, const char *s, int len); 00167 void jit_xml_document_xmlparse_characterdata(t_jit_xml_document *x, const char *s, int len); 00168 void jit_xml_document_xmlparse_cdata_start(t_jit_xml_document *x); 00169 void jit_xml_document_xmlparse_cdata_end(t_jit_xml_document *x); 00170 void jit_xml_document_xmlparse_comment(t_jit_xml_document *x, const char *s); 00171 void jit_xml_document_xmlparse_doctype_start(t_jit_xml_document *x, const char *s); 00172 void jit_xml_document_xmlparse_doctype_end(t_jit_xml_document *x); 00173 void jit_xml_document_createheader(t_jit_xml_document *x, t_symbol *encoding); 00174 void *jit_xml_document_new(t_symbol *s, long argc, t_atom *argv); 00175 void jit_xml_document_free(t_jit_xml_document *x); 00176 00177 // jit_xml_element 00178 t_jit_err jit_xml_element_getattribute(t_jit_xml_element *x, t_symbol *attrname, long *ac, t_atom **av); 00179 t_jit_err jit_xml_element_setattribute(t_jit_xml_element *x, t_symbol *attrname, long ac, t_atom *av); 00180 t_jit_err jit_xml_element_removeattribute(t_jit_xml_element *x, t_symbol *attrname); 00181 t_jit_xml_attribute *jit_xml_element_getattributenode(t_jit_xml_element *x, t_symbol *attrname); 00182 t_jit_xml_attribute *jit_xml_element_setattributenode(t_jit_xml_element *x, t_jit_xml_attribute *attr); 00183 t_jit_xml_attribute * jit_xml_element_removeattributenode(t_jit_xml_element *x, t_jit_xml_attribute *attr); 00184 t_jit_linklist *jit_xml_element_getelementsbytagname(t_jit_xml_element *x, t_symbol *tagname); 00185 long jit_xml_element_symcompare(t_jit_xml_attribute *x,t_symbol *name); 00186 void *jit_xml_element_new(t_symbol *s, long argc, t_atom *argv); 00187 void jit_xml_element_free(t_jit_xml_element *x); 00188 // utils 00189 t_symbol *jit_xml_element_getattribute_sym(t_jit_xml_element *x, t_symbol *attrname); 00190 t_jit_err jit_xml_element_setattribute_sym(t_jit_xml_element *x, t_symbol *attrname, t_symbol *s); 00191 long jit_xml_element_getattribute_long(t_jit_xml_element *x, t_symbol *attrname); 00192 t_jit_err jit_xml_element_setattribute_long(t_jit_xml_element *x, t_symbol *attrname, long c); 00193 float jit_xml_element_getattribute_float(t_jit_xml_element *x, t_symbol *attrname); 00194 t_jit_err jit_xml_element_setattribute_float(t_jit_xml_element *x, t_symbol *attrname, float f); 00195 long jit_xml_element_getattribute_sym_array(t_jit_xml_element *x, t_symbol *attrname, long max, t_symbol **vals); 00196 t_jit_err jit_xml_element_setattribute_sym_array(void *x, t_symbol *attrname, long count, t_symbol **vals); 00197 long jit_xml_element_getattribute_long_array(t_jit_xml_element *x, t_symbol *attrname, long max, long *vals); 00198 t_jit_err jit_xml_element_setattribute_long_array(void *x, t_symbol *attrname, long count, long *vals); 00199 long jit_xml_element_getattribute_float_array(t_jit_xml_element *x, t_symbol *attrname, long max, float *vals); 00200 t_jit_err jit_xml_element_setattribute_float_array(void *x, t_symbol *attrname, long count, float *vals); 00201 00202 // jit_xml_attribute 00203 long jit_xml_attr_symcompare(t_jit_xml_attribute *x,t_symbol *name); 00204 void *jit_xml_attribute_new(t_symbol *s, long argc, t_atom *argv); 00205 void jit_xml_attribute_free(t_jit_xml_attribute *x); 00206 00207 // jit_xml_text 00208 void *jit_xml_text_new(t_symbol *s, long argc, t_atom *argv); 00209 t_jit_xml_text *jit_xml_text_splittext(t_jit_xml_text *x, long offset); 00210 void jit_xml_text_free(t_jit_xml_text *x); 00211 00212 // jit_xml_comment 00213 void *jit_xml_comment_new(t_symbol *s, long argc, t_atom *argv); 00214 void jit_xml_comment_free(t_jit_xml_comment *x); 00215 00216 // jit_xml_cdata 00217 void *jit_xml_cdata_new(t_symbol *s, long argc, t_atom *argv); 00218 t_jit_xml_cdata *jit_xml_cdata_splittext(t_jit_xml_cdata *x, long offset); 00219 void jit_xml_cdata_free(t_jit_xml_cdata *x); 00220 00221 #endif //__JIT_XML_H__
Copyright © 2008, Cycling '74