Class: Lutaml::Xml::DataModel::XmlElement
- Inherits:
-
Object
- Object
- Lutaml::Xml::DataModel::XmlElement
- Defined in:
- lib/lutaml/xml/data_model.rb
Overview
Represents an XML element with namespace, attributes, and children.
Instance Attribute Summary collapse
-
#attributes ⇒ Array<XmlAttribute>
readonly
Element attributes.
-
#cdata ⇒ Boolean
Whether text content should be wrapped in CDATA section.
-
#children ⇒ Array<XmlElement, String>
readonly
Child elements and text nodes.
-
#explicit_namespace ⇒ Boolean
readonly
Whether this element’s namespace was explicitly declared (from mapping rule) vs inherited from parent or unset.
-
#form ⇒ Symbol?
Form option (:qualified, :unqualified, or nil) :qualified forces prefix format, :unqualified forces default format.
-
#name ⇒ String
Element local name.
-
#namespace_class ⇒ Class?
XmlNamespace class (not instance).
-
#namespace_scope_config ⇒ Array?
Namespace scope configuration (for hoisting).
-
#needs_xmlns_blank ⇒ Boolean
Whether element needs xmlns=“” declaration.
-
#original_namespace_uri ⇒ String?
Original namespace URI (for alias support).
-
#original_xml_element ⇒ Lutaml::Xml::XmlElement?
Original parsed XmlElement (for prefix fallback).
-
#processing_instructions ⇒ Array<XmlProcessingInstruction>
readonly
Processing instructions before this element.
-
#raw_content ⇒ String?
Raw XML content for map_all custom methods.
-
#text_content ⇒ String?
Direct text content (for simple elements).
-
#xml_namespace_prefix ⇒ String?
XML namespace prefix (for doubly-defined namespace support).
-
#xsi_nil ⇒ Boolean
Whether element was created from nil value with render_nil.
Instance Method Summary collapse
-
#add_attribute(attribute) ⇒ self
Add an attribute to this element.
-
#add_child(child) ⇒ self
Add a child element or text node.
- #add_processing_instruction(target, content) ⇒ Object
-
#has_attributes? ⇒ Boolean
Check if element has any attributes.
-
#has_children? ⇒ Boolean
Check if element has any children.
-
#initialize(name, namespace_class = nil, explicit_namespace: false) ⇒ XmlElement
constructor
Initialize a new XML element.
-
#inspect ⇒ String
Detailed inspection for debugging.
-
#qualified_name(prefix = nil) ⇒ String
Get qualified name (prefix:name or name).
-
#to_s ⇒ String
String representation for debugging.
Constructor Details
#initialize(name, namespace_class = nil, explicit_namespace: false) ⇒ XmlElement
Initialize a new XML element
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/lutaml/xml/data_model.rb', line 65 def initialize(name, namespace_class = nil, explicit_namespace: false) @name = name @namespace_class = namespace_class @explicit_namespace = explicit_namespace @attributes = [] @children = [] @text_content = nil @cdata = false @form = nil @processing_instructions = [] end |
Instance Attribute Details
#attributes ⇒ Array<XmlAttribute> (readonly)
Returns Element attributes.
20 21 22 |
# File 'lib/lutaml/xml/data_model.rb', line 20 def attributes @attributes end |
#cdata ⇒ Boolean
Returns Whether text content should be wrapped in CDATA section.
29 30 31 |
# File 'lib/lutaml/xml/data_model.rb', line 29 def cdata @cdata end |
#children ⇒ Array<XmlElement, String> (readonly)
Returns Child elements and text nodes.
23 24 25 |
# File 'lib/lutaml/xml/data_model.rb', line 23 def children @children end |
#explicit_namespace ⇒ Boolean (readonly)
Whether this element’s namespace was explicitly declared (from mapping rule) vs inherited from parent or unset.
81 82 83 |
# File 'lib/lutaml/xml/data_model.rb', line 81 def explicit_namespace @explicit_namespace end |
#form ⇒ Symbol?
Returns Form option (:qualified, :unqualified, or nil) :qualified forces prefix format, :unqualified forces default format.
33 34 35 |
# File 'lib/lutaml/xml/data_model.rb', line 33 def form @form end |
#name ⇒ String
Returns Element local name.
14 15 16 |
# File 'lib/lutaml/xml/data_model.rb', line 14 def name @name end |
#namespace_class ⇒ Class?
Returns XmlNamespace class (not instance).
17 18 19 |
# File 'lib/lutaml/xml/data_model.rb', line 17 def namespace_class @namespace_class end |
#namespace_scope_config ⇒ Array?
Returns Namespace scope configuration (for hoisting).
51 52 53 |
# File 'lib/lutaml/xml/data_model.rb', line 51 def namespace_scope_config @namespace_scope_config end |
#needs_xmlns_blank ⇒ Boolean
Returns Whether element needs xmlns=“” declaration.
36 37 38 |
# File 'lib/lutaml/xml/data_model.rb', line 36 def needs_xmlns_blank @needs_xmlns_blank end |
#original_namespace_uri ⇒ String?
Returns Original namespace URI (for alias support).
48 49 50 |
# File 'lib/lutaml/xml/data_model.rb', line 48 def original_namespace_uri @original_namespace_uri end |
#original_xml_element ⇒ Lutaml::Xml::XmlElement?
Returns Original parsed XmlElement (for prefix fallback).
54 55 56 |
# File 'lib/lutaml/xml/data_model.rb', line 54 def original_xml_element @original_xml_element end |
#processing_instructions ⇒ Array<XmlProcessingInstruction> (readonly)
Returns Processing instructions before this element.
57 58 59 |
# File 'lib/lutaml/xml/data_model.rb', line 57 def processing_instructions @processing_instructions end |
#raw_content ⇒ String?
Returns Raw XML content for map_all custom methods.
42 43 44 |
# File 'lib/lutaml/xml/data_model.rb', line 42 def raw_content @raw_content end |
#text_content ⇒ String?
Returns Direct text content (for simple elements).
26 27 28 |
# File 'lib/lutaml/xml/data_model.rb', line 26 def text_content @text_content end |
#xml_namespace_prefix ⇒ String?
Returns XML namespace prefix (for doubly-defined namespace support).
45 46 47 |
# File 'lib/lutaml/xml/data_model.rb', line 45 def xml_namespace_prefix @xml_namespace_prefix end |
#xsi_nil ⇒ Boolean
Returns Whether element was created from nil value with render_nil.
39 40 41 |
# File 'lib/lutaml/xml/data_model.rb', line 39 def xsi_nil @xsi_nil end |
Instance Method Details
#add_attribute(attribute) ⇒ self
Add an attribute to this element
96 97 98 99 |
# File 'lib/lutaml/xml/data_model.rb', line 96 def add_attribute(attribute) @attributes << attribute self end |
#add_child(child) ⇒ self
Add a child element or text node
87 88 89 90 |
# File 'lib/lutaml/xml/data_model.rb', line 87 def add_child(child) @children << child self end |
#add_processing_instruction(target, content) ⇒ Object
101 102 103 104 105 |
# File 'lib/lutaml/xml/data_model.rb', line 101 def add_processing_instruction(target, content) @processing_instructions << XmlProcessingInstruction.new(target, content) self end |
#has_attributes? ⇒ Boolean
Check if element has any attributes
117 118 119 |
# File 'lib/lutaml/xml/data_model.rb', line 117 def has_attributes? !@attributes.empty? end |
#has_children? ⇒ Boolean
Check if element has any children
110 111 112 |
# File 'lib/lutaml/xml/data_model.rb', line 110 def has_children? !@children.empty? end |
#inspect ⇒ String
Detailed inspection for debugging
163 164 165 |
# File 'lib/lutaml/xml/data_model.rb', line 163 def inspect "#<#{self.class.name} #{self}>" end |
#qualified_name(prefix = nil) ⇒ String
Get qualified name (prefix:name or name)
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/lutaml/xml/data_model.rb', line 125 def qualified_name(prefix = nil) if prefix "#{prefix}:#{name}" elsif namespace_class.respond_to?(:prefix_default) ns_prefix = namespace_class.prefix_default ns_prefix ? "#{ns_prefix}:#{name}" : name else name end end |
#to_s ⇒ String
String representation for debugging
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/lutaml/xml/data_model.rb', line 139 def to_s parts = ["<#{qualified_name}"] if namespace_class parts << " (ns: #{namespace_class})" end if has_attributes? parts << " attrs: #{attributes.length}" end if text_content parts << " text: #{text_content.inspect}" elsif has_children? parts << " children: #{children.length}" end parts << ">" parts.join end |