class Lutaml::Model::XmlAdapter::OxElement

def build_attributes(node)

def build_attributes(node)
  attrs = node.attributes.transform_values(&:value)
  node.own_namespaces.each_value do |namespace|
    attrs[namespace.attr_name] = namespace.uri
  end
  attrs
end

def initialize(node, root_node: nil)

def initialize(node, root_node: nil)
  if node.is_a?(String)
    super("text", {}, [], node, parent_document: root_node)
  else
    namespace_attributes(node.attributes).each do |(name, value)|
      if root_node
        root_node.add_namespace(XmlNamespace.new(value, name))
      else
        add_namespace(XmlNamespace.new(value, name))
      end
    end
    attributes = node.attributes.each_with_object({}) do |(name, value), hash|
      next if attribute_is_namespace?(name)
      namespace_prefix = name.to_s.split(":").first
      if (n = name.to_s.split(":")).length > 1
        namespace = (root_node || self).namespaces[namespace_prefix]&.uri
        namespace ||= XML_NAMESPACE_URI
        prefix = n.first
      end
      hash[name.to_s] = XmlAttribute.new(
        name.to_s,
        value,
        namespace: namespace,
        namespace_prefix: prefix,
      )
    end
    super(
      node.name.to_s,
      attributes,
      parse_children(node, root_node: root_node || self),
      node.text,
      parent_document: root_node,
    )
  end
end

def namespace_attributes(attributes)

def namespace_attributes(attributes)
  attributes.select { |attr| attribute_is_namespace?(attr) }
end

def nodes

def nodes
  children
end

def parse_children(node, root_node: nil)

def parse_children(node, root_node: nil)
  node.nodes.map do |child|
    OxElement.new(child, root_node: root_node)
  end
end

def text?

def text?
  # false
  children.empty? && text&.length&.positive?
end

def to_xml(builder = nil)

def to_xml(builder = nil)
  builder ||= Ox::Builder.new
  attrs = build_attributes(self)
  if text?
    builder.text(text)
  else
    builder.element(name, attrs) do |el|
      children.each { |child| child.to_xml(el) }
    end
  end
end