Variant f_simplexml_load_string(const String& data,
                                const String& class_name /* = "SimpleXMLElement" */,
                                int64_t options /* = 0 */,
                                const String& ns /* = "" */,
                                bool is_prefix /* = false */) {
  Class* cls;
  if (!class_name.empty()) {
    cls = Unit::loadClass(class_name.get());
    if (!cls) {
      throw_invalid_argument("class not found: %s", class_name.data());
      return uninit_null();
    }
    if (!cls->classof(c_SimpleXMLElement::classof())) {
      throw_invalid_argument(
        "simplexml_load_string() expects parameter 2 to be a class name "
        "derived from SimpleXMLElement, '%s' given",
        class_name.data());
      return uninit_null();
    }
  } else {
    cls = c_SimpleXMLElement::classof();
  }

  xmlDocPtr doc = xmlReadMemory(data.data(), data.size(),
                                nullptr, nullptr, options);
  xmlNodePtr root = xmlDocGetRootElement(doc);
  if (!doc) {
    return false;
  }

  return create_element(nullptr,
                        Resource(NEWOBJ(XmlDocWrapper)(doc, cls->nameRef())),
                        root, ns, is_prefix);
}
Variant f_simplexml_load_string(const String& data,
                                const String& class_name  ,
                                int64_t options  ,
                                const String& ns  ,
                                bool is_prefix  ) {
  Class* cls;
  if (!class_name.empty()) {
    cls = Unit::loadClass(class_name.get());
    if (!cls) {
      throw_invalid_argument("class not found: %s", class_name.data());
      return uninit_null();
    }
    if (!cls->classof(c_SimpleXMLElement::classof())) {
      throw_invalid_argument(
        "simplexml_load_string() expects parameter 2 to be a class name "
        "derived from SimpleXMLElement, '%s' given",
        class_name.data());
      return uninit_null();
    }
  } else {
    cls = c_SimpleXMLElement::classof();
  }

  xmlDocPtr doc = xmlReadMemory(data.data(), data.size(),
                                nullptr, nullptr, options);
  xmlNodePtr root = xmlDocGetRootElement(doc);
  if (!doc) {
    return false;
  }

  return create_element(nullptr,
                        Resource(NEWOBJ(XmlDocWrapper)(doc, cls->nameRef())),
                        root, ns, is_prefix);
}