示例#1
0
xmlDocPtr soap_xmlParseMemory(const void *buf, size_t buf_size,
                              bool skip_clean /*= true */) {
  xmlParserCtxtPtr ctxt = NULL;
  xmlDocPtr ret;

/*
  xmlInitParser();
*/
  ctxt = xmlCreateMemoryParserCtxt((const char *)buf, buf_size);
  if (ctxt) {
    ctxt->keepBlanks = 0;
    ctxt->sax->ignorableWhitespace = soap_ignorableWhitespace;
    ctxt->sax->comment = soap_Comment;
    ctxt->sax->warning = NULL;
    ctxt->sax->error = NULL;
    /*ctxt->sax->fatalError = NULL;*/
    xmlParseDocument(ctxt);
    if (ctxt->wellFormed) {
      ret = ctxt->myDoc;
      if (ret->URL == NULL && ctxt->directory != NULL) {
        ret->URL = xmlCharStrdup(ctxt->directory);
      }
    } else {
      ret = NULL;
      xmlFreeDoc(ctxt->myDoc);
      ctxt->myDoc = NULL;
    }
    xmlFreeParserCtxt(ctxt);
  } else {
    ret = NULL;
  }

/*
  xmlCleanupParser();
*/

  if (!skip_clean && ret) {
    cleanup_xml_node((xmlNodePtr)ret);
  }
  return ret;
}
示例#2
0
xmlDocPtr soap_xmlParseFile(const char *filename) {
  const char *url = strstr(filename, "://");
  if (url) {
    xmlDocPtr ret;
    xmlParserCtxtPtr ctxt = xmlCreateFileParserCtxt(filename);
    if (ctxt) {
      ctxt->keepBlanks = 0;
      ctxt->sax->ignorableWhitespace = soap_ignorableWhitespace;
      ctxt->sax->comment = soap_Comment;
      ctxt->sax->warning = NULL;
      ctxt->sax->error = NULL;
      /*ctxt->sax->fatalError = NULL;*/
      xmlParseDocument(ctxt);
      if (ctxt->wellFormed) {
        ret = ctxt->myDoc;
        if (ret->URL == NULL && ctxt->directory != NULL) {
          ret->URL = xmlCharStrdup(ctxt->directory);
        }
      } else {
        ret = NULL;
        xmlFreeDoc(ctxt->myDoc);
        ctxt->myDoc = NULL;
      }
      xmlFreeParserCtxt(ctxt);
    } else {
      ret = NULL;
    }
    if (ret) {
      cleanup_xml_node((xmlNodePtr)ret);
    }
    return ret;
  }

  Variant content = f_file_get_contents(filename);
  if (!same(content, false)) {
    String scontent = content.toString();
    return soap_xmlParseMemory(scontent.data(), scontent.size());
  }
  return NULL;
}