void c_SimpleXMLElementIterator::reset_iterator() {
  assert(m_parent.get() != nullptr);
  delete m_iter1; m_iter1 = nullptr;
  delete m_iter2; m_iter2 = nullptr;

  if (m_parent->m_is_attribute) {
    m_iter1 = new ArrayIter(m_parent->m_attributes.toArray());
    return;
  }

  // When I'm a node like $node->name, we iterate through all my siblings with
  // same name of mine.
  if (m_parent->m_is_property) {
    String name = m_parent->t_getname();
    Object obj = create_element(m_parent->m_root, m_parent->m_doc,
                                m_parent->m_node->parent,
                                "", false);
    m_parent = obj.getTyped<c_SimpleXMLElement>();
    Variant children = m_parent->m_children[name];
    m_parent->m_children = make_map_array(name, children);
    // fall through
  }

  if (m_parent->m_is_text) {
    return;
  }

  if (m_parent->m_children.toArray().size() == 1) {
    ArrayIter iter(m_parent->m_children.toArray());
    if (iter.second().isObject()) {
      c_SimpleXMLElement *elem = iter.second().toObject().
        getTyped<c_SimpleXMLElement>();
      if (elem->m_is_text && elem->m_free_text) {
        return;
      }
    }
  }

  m_iter1 = new ArrayIter(m_parent->m_children.toArray());
  if (!m_iter1->end() && m_iter1->second().isArray()) {
    m_iter2 = new ArrayIter(m_iter1->second().toArray());
  }
}
void c_SimpleXMLElementIterator::reset_iterator() {
  assert(m_parent.get() != nullptr);
  delete m_iter1; m_iter1 = nullptr;
  delete m_iter2; m_iter2 = nullptr;

  if (m_parent->m_is_attribute) {
    m_iter1 = new ArrayIter(m_parent->m_attributes.toArray());
    return;
  }

   
   
  if (m_parent->m_is_property) {
    String name = m_parent->t_getname();
    Object obj = create_element(m_parent->m_root, m_parent->m_doc,
                                m_parent->m_node->parent,
                                "", false);
    m_parent = obj.getTyped<c_SimpleXMLElement>();
    Variant children = m_parent->m_children[name];
    m_parent->m_children = make_map_array(name, children);
     
  }

  if (m_parent->m_is_text) {
    return;
  }

  if (m_parent->m_children.toArray().size() == 1) {
    ArrayIter iter(m_parent->m_children.toArray());
    if (iter.second().isObject()) {
      c_SimpleXMLElement *elem = iter.second().toObject().
        getTyped<c_SimpleXMLElement>();
      if (elem->m_is_text && elem->m_free_text) {
        return;
      }
    }
  }

  m_iter1 = new ArrayIter(m_parent->m_children.toArray());
  if (!m_iter1->end() && m_iter1->second().isArray()) {
    m_iter2 = new ArrayIter(m_iter1->second().toArray());
  }
}