1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
/* Please see the LICENSE file for copyright and distribution information */
/*
* Document-class: LibXML::XML::AttrDecl
*
* At attribute declaration is used in XML::Dtds to define
* what attributes are allowed on an element. An attribute
* declaration defines an attribues name, data type and default
* value (if any).
*/
#include "ruby_libxml.h"
VALUE cXMLAttrDecl;
void rxml_attr_decl_mark(xmlAttributePtr xattr)
{
rxml_node_mark((xmlNodePtr) xattr);
}
VALUE rxml_attr_decl_wrap(xmlAttributePtr xattr)
{
return Data_Wrap_Struct(cXMLAttrDecl, rxml_attr_decl_mark, NULL, xattr);
}
/*
* call-seq:
* attr_decl.doc -> XML::Document
*
* Returns this attribute declaration's document.
*/
static VALUE rxml_attr_decl_doc_get(VALUE self)
{
xmlAttributePtr xattr;
Data_Get_Struct(self, xmlAttribute, xattr);
if (xattr->doc == NULL)
return Qnil;
else
return rxml_document_wrap(xattr->doc);
}
/*
* call-seq:
* attr_decl.name -> "name"
*
* Obtain this attribute declaration's name.
*/
static VALUE rxml_attr_decl_name_get(VALUE self)
{
xmlAttributePtr xattr;
Data_Get_Struct(self, xmlAttribute, xattr);
if (xattr->name == NULL)
return Qnil;
else
return rxml_new_cstr((const char*) xattr->name, xattr->doc->encoding);
}
/*
* call-seq:
* attr_decl.next -> XML::AttrDecl
*
* Obtain the next attribute declaration.
*/
static VALUE rxml_attr_decl_next_get(VALUE self)
{
xmlAttributePtr xattr;
Data_Get_Struct(self, xmlAttribute, xattr);
if (xattr->next == NULL)
return Qnil;
else
return rxml_attr_decl_wrap((xmlAttributePtr)xattr->next);
}
/*
* call-seq:
* attr_decl.type -> num
*
* Obtain this attribute declaration's type node type.
*/
static VALUE rxml_attr_decl_node_type(VALUE self)
{
xmlAttrPtr xattr;
Data_Get_Struct(self, xmlAttr, xattr);
return INT2NUM(xattr->type);
}
/*
* call-seq:
* attr_decl.parent -> XML::Dtd
*
* Obtain this attribute declaration's parent which
* is an instance of a XML::DTD.
*/
static VALUE rxml_attr_decl_parent_get(VALUE self)
{
xmlAttributePtr xattr;
Data_Get_Struct(self, xmlAttribute, xattr);
if (xattr->parent == NULL)
return Qnil;
else
return rxml_dtd_wrap(xattr->parent);
}
/*
* call-seq:
* attr_decl.prev -> (XML::AttrDecl | XML::ElementDecl)
*
* Obtain the previous attribute declaration or the owning
* element declration (not implemented).
*/
static VALUE rxml_attr_decl_prev_get(VALUE self)
{
xmlAttributePtr xattr;
Data_Get_Struct(self, xmlAttribute, xattr);
if (xattr->prev == NULL)
return Qnil;
else
return rxml_attr_decl_wrap((xmlAttributePtr)xattr->prev);
}
/*
* call-seq:
* attr_decl.value -> "value"
*
* Obtain the default value of this attribute declaration.
*/
VALUE rxml_attr_decl_value_get(VALUE self)
{
xmlAttributePtr xattr;
Data_Get_Struct(self, xmlAttribute, xattr);
if (xattr->defaultValue)
return rxml_new_cstr((const char *)xattr->defaultValue, NULL);
else
return Qnil;
}
void rxml_init_attr_decl(void)
{
cXMLAttrDecl = rb_define_class_under(mXML, "AttrDecl", rb_cObject);
rb_define_method(cXMLAttrDecl, "doc", rxml_attr_decl_doc_get, 0);
rb_define_method(cXMLAttrDecl, "name", rxml_attr_decl_name_get, 0);
rb_define_method(cXMLAttrDecl, "next", rxml_attr_decl_next_get, 0);
rb_define_method(cXMLAttrDecl, "node_type", rxml_attr_decl_node_type, 0);
rb_define_method(cXMLAttrDecl, "parent", rxml_attr_decl_parent_get, 0);
rb_define_method(cXMLAttrDecl, "prev", rxml_attr_decl_prev_get, 0);
rb_define_method(cXMLAttrDecl, "value", rxml_attr_decl_value_get, 0);
}
|