class Lutaml::Model::XmlAdapter::NokogiriElement

def build_attributes(node)

def build_attributes(node)
  attrs = node.attributes.transform_values(&:value)
  attrs.merge(build_namespace_attributes(node))
end

def build_namespace_attributes(node)

def build_namespace_attributes(node)
  namespace_attrs = {}
  node.own_namespaces.each_value do |namespace|
    namespace_attrs[namespace.attr_name] = namespace.uri
  end
  node.children.each do |child|
    namespace_attrs = namespace_attrs.merge(
      build_namespace_attributes(child),
    )
  end
  namespace_attrs
end

def initialize(node, root_node: nil)

def initialize(node, root_node: nil)
  if root_node
    node.namespaces.each do |prefix, name|
      namespace = XmlNamespace.new(name, prefix)
      root_node.add_namespace(namespace)
    end
  end
  attributes = {}
  node.attributes.transform_values do |attr|
    name = if attr.namespace
             "#{attr.namespace.prefix}:#{attr.name}"
           else
             attr.name
           end
    attributes[name] = XmlAttribute.new(
      name,
      attr.value,
      namespace: attr.namespace&.href,
      namespace_prefix: attr.namespace&.prefix,
    )
  end
  super(
    node.name,
    attributes,
    parse_all_children(node, root_node: root_node || self),
    node.text,
    parent_document: root_node,
    namespace_prefix: node.namespace&.prefix,
  )
end

def parse_all_children(node, root_node: nil)

def parse_all_children(node, root_node: nil)
  node.children.map do |child|
    NokogiriElement.new(child, root_node: root_node)
  end
end

def parse_children(node, root_node: nil)

def parse_children(node, root_node: nil)
  node.children.select(&:element?).map do |child|
    NokogiriElement.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 ||= Nokogiri::XML::Builder.new
  if name == "text"
    builder.text(text)
  else
    builder.send(name, build_attributes(self)) do |xml|
      children.each { |child| child.to_xml(xml) }
    end
  end
  builder
end