Class: LibXML::XML::AttrDecl

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
ext/libxml/ruby_xml_attr_decl.c,
lib/libxml/attr_decl.rb,
ext/libxml/ruby_xml_attr_decl.c

Overview

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).

Instance Method Summary collapse

Instance Method Details

#childObject

call-seq:

attr_decl.child -> nil

Obtain this attribute declaration’s child attribute(s). It will always be nil.



13
14
15
# File 'lib/libxml/attr_decl.rb', line 13

def child
  nil
end

#child?Boolean

call-seq:

attr_decl.child? -> (true|false)

Returns whether this attribute declaration has child attributes.

Returns:

  • (Boolean)


22
23
24
# File 'lib/libxml/attr_decl.rb', line 22

def child?
  not self.children.nil?
end

#docXML::Document

Returns this attribute declaration’s document.

Returns:



39
40
41
42
43
44
45
46
47
# File 'ext/libxml/ruby_xml_attr_decl.c', line 39

static VALUE rxml_attr_decl_doc_get(VALUE self)
{
  xmlAttributePtr xattr;
  TypedData_Get_Struct(self, xmlAttribute, &rxml_attr_decl_type, xattr);
  if (xattr->doc == NULL)
    return Qnil;
  else
    return rxml_registry_lookup(xattr->doc);
}

#doc?Boolean

call-seq:

attr_decl.doc? -> (true|false)

Determine whether this attribute declaration is associated with an XML::Document.

Returns:

  • (Boolean)


31
32
33
# File 'lib/libxml/attr_decl.rb', line 31

def doc?
  not self.doc.nil?
end

#nameObject

Obtain this attribute declaration’s name.



56
57
58
59
60
61
62
63
64
65
# File 'ext/libxml/ruby_xml_attr_decl.c', line 56

static VALUE rxml_attr_decl_name_get(VALUE self)
{
  xmlAttributePtr xattr;
  TypedData_Get_Struct(self, xmlAttribute, &rxml_attr_decl_type, xattr);

  if (xattr->name == NULL)
    return Qnil;
  else
    return rxml_new_cstr( xattr->name, xattr->doc->encoding);
}

#nextXML::AttrDecl

Obtain the next attribute declaration.

Returns:



73
74
75
76
77
78
79
80
81
# File 'ext/libxml/ruby_xml_attr_decl.c', line 73

static VALUE rxml_attr_decl_next_get(VALUE self)
{
  xmlAttributePtr xattr;
  TypedData_Get_Struct(self, xmlAttribute, &rxml_attr_decl_type, xattr);
  if (xattr->next == NULL)
    return Qnil;
  else
    return rxml_attr_decl_wrap((xmlAttributePtr)xattr->next);
}

#next?Boolean

call-seq:

attr_decl.next? -> (true|false)

Determine whether there is a next attribute declaration.

Returns:

  • (Boolean)


39
40
41
# File 'lib/libxml/attr_decl.rb', line 39

def next?
  not self.next.nil?
end

#typeNumeric

Obtain this attribute declaration’s type node type.

Returns:

  • (Numeric)


89
90
91
92
93
94
# File 'ext/libxml/ruby_xml_attr_decl.c', line 89

static VALUE rxml_attr_decl_node_type(VALUE self)
{
  xmlAttributePtr xattr;
  TypedData_Get_Struct(self, xmlAttribute, &rxml_attr_decl_type, xattr);
  return INT2NUM(xattr->type);
}

#node_type_nameObject

call-seq:

attr_decl.node_type_name -> 'attribute declaration'

Returns this attribute declaration’s node type name.



63
64
65
66
67
68
69
# File 'lib/libxml/attr_decl.rb', line 63

def node_type_name
  if node_type == Node::ATTRIBUTE_DECL
    'attribute declaration'
  else
    raise(UnknownType, "Unknown node type: %n", node.node_type);
  end
end

#parentXML::Dtd

Obtain this attribute declaration’s parent which is an instance of a XML::DTD.

Returns:



103
104
105
106
107
108
109
110
111
112
# File 'ext/libxml/ruby_xml_attr_decl.c', line 103

static VALUE rxml_attr_decl_parent_get(VALUE self)
{
  xmlAttributePtr xattr;
  TypedData_Get_Struct(self, xmlAttribute, &rxml_attr_decl_type, xattr);

  if (xattr->parent == NULL)
    return Qnil;
  else
    return rxml_dtd_wrap(xattr->parent);
}

#parent?Boolean

call-seq:

attr_decl.parent? -> (true|false)

Determine whether this attribute declaration has a parent .

Returns:

  • (Boolean)


47
48
49
# File 'lib/libxml/attr_decl.rb', line 47

def parent?
  not self.parent.nil?
end

#prev(XML::AttrDecl | XML::ElementDecl)

Obtain the previous attribute declaration or the owning element declration (not implemented).

Returns:



121
122
123
124
125
126
127
128
129
130
# File 'ext/libxml/ruby_xml_attr_decl.c', line 121

static VALUE rxml_attr_decl_prev_get(VALUE self)
{
  xmlAttributePtr xattr;
  TypedData_Get_Struct(self, xmlAttribute, &rxml_attr_decl_type, xattr);

  if (xattr->prev == NULL)
    return Qnil;
  else
    return rxml_attr_decl_wrap((xmlAttributePtr)xattr->prev);
}

#prev?Boolean

call-seq:

attr_decl.prev? -> (true|false)

Determine whether there is a previous attribute declaration.

Returns:

  • (Boolean)


55
56
57
# File 'lib/libxml/attr_decl.rb', line 55

def prev?
  not self.prev.nil?
end

#to_sObject

call-seq:

attr_decl.to_s -> string

Returns a string representation of this attribute declaration.



75
76
77
# File 'lib/libxml/attr_decl.rb', line 75

def to_s
  "#{name} = #{value}"
end

#valueObject

Obtain the default value of this attribute declaration.



138
139
140
141
142
143
144
145
146
147
148
# File 'ext/libxml/ruby_xml_attr_decl.c', line 138

VALUE rxml_attr_decl_value_get(VALUE self)
{
  xmlAttributePtr xattr;

  TypedData_Get_Struct(self, xmlAttribute, &rxml_attr_decl_type, xattr);

  if (xattr->defaultValue)
    return rxml_new_cstr(xattr->defaultValue, NULL);
  else
    return Qnil;
}