int main(int argc, char **argv) { xmlParserCtxtPtr ctxt; xmlsatParseState state; if (argc<2) { printf("Usage: %s [-fta] filename.xmlsat\n",argv[0]); } else { if (argc==2) { ctxt = (xmlParserCtxtPtr)xmlCreateFileParserCtxt(argv[1]); } else if (argc==3) { if (strcmp(argv[1],"-fta")==0) { fta=1; } ctxt = (xmlParserCtxtPtr)xmlCreateFileParserCtxt(argv[2]); } if (ctxt == NULL) { fprintf(stderr,"ERROR: can not open file\n"); } ctxt->sax = &xmlsatSAXParser; ctxt->userData = &state; xmlParseDocument(ctxt); ctxt->sax = NULL; xmlFreeParserCtxt(ctxt); } return 0; }
XDocument* XParser::Parse(const char* szPath, bool keep_blank/*=false*/) { if(szPath==NULL) return NULL; xmlKeepBlanksDefault(keep_blank?1:0); xmlDoValidityCheckingDefaultValue =0; xmlParserCtxtPtr pxParseCtxt = NULL; pxParseCtxt = xmlCreateFileParserCtxt(szPath); if(pxParseCtxt==NULL) { return NULL; } if(pxParseCtxt->directory == NULL) { char* directory = xmlParserGetDirectory(szPath); pxParseCtxt->directory = (char*)xmlStrdup((xmlChar*)directory); } if(!ParseContext(pxParseCtxt)) { xmlFreeParserCtxt(pxParseCtxt); return NULL; } XDocument* pagXmlDoc = NULL; pagXmlDoc = new XDocument(pxParseCtxt->myDoc); xmlFreeParserCtxt(pxParseCtxt); return pagXmlDoc; }
// A modified version of XmlSAXParseFile in gnome-xml. This one lets us set // the user_data that is passed to the various callbacks, to make it possible // to avoid lots of global variables. gboolean oreganoXmlSAXParseFile (xmlSAXHandlerPtr sax, gpointer user_data, const gchar *filename) { g_return_val_if_fail (filename != NULL, FALSE); gboolean parser_failed, ret = TRUE; xmlParserCtxtPtr ctxt; ctxt = xmlCreateFileParserCtxt (filename); if (ctxt == NULL) return FALSE; ctxt->sax = sax; ctxt->userData = user_data; #if defined(LIBXML_VERSION) && LIBXML_VERSION >= 20000 xmlKeepBlanksDefault (0); #endif parser_failed = FALSE; if (xmlParseDocument (ctxt) < 0) { // FIXME post a message to the log buffer with as much details as possible g_message ("Failed to parse \"%s\"", filename); ret = FALSE; parser_failed = TRUE; } else { ret = ctxt->wellFormed ? TRUE : FALSE; if (sax != NULL) ctxt->sax = NULL; } if (!parser_failed) xmlFreeParserCtxt (ctxt); return ret; }
xmlDocPtr soap_xmlParseFile(const char *filename) { xmlParserCtxtPtr ctxt = NULL; xmlDocPtr ret; zend_bool old_allow_url_fopen; /* xmlInitParser(); */ old_allow_url_fopen = PG(allow_url_fopen); PG(allow_url_fopen) = 1; ctxt = xmlCreateFileParserCtxt(filename); PG(allow_url_fopen) = old_allow_url_fopen; if (ctxt) { zend_bool old; 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;*/ #if LIBXML_VERSION >= 20703 ctxt->options |= XML_PARSE_HUGE; #endif old = php_libxml_disable_entity_loader(1); xmlParseDocument(ctxt); php_libxml_disable_entity_loader(old); 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 (ret) { cleanup_xml_node((xmlNodePtr)ret); } return ret; }
void SaxParser::parse_file(const Glib::ustring& filename) { if(context_) { throw parse_error("Attempt to start a second parse while a parse is in progress."); } KeepBlanks k(KeepBlanks::Default); context_ = xmlCreateFileParserCtxt(filename.c_str()); parse(); }
int RS_XML(libXMLEventParse)(const char *fileName, RS_XMLParserData *parserData, RS_XML_ContentSourceType asText, int saxVersion) { xmlSAXHandlerPtr xmlParserHandler; xmlParserCtxtPtr ctx; int status; switch(asText) { case RS_XML_TEXT: ctx = xmlCreateDocParserCtxt(CHAR_TO_XMLCHAR(fileName)); break; case RS_XML_FILENAME: ctx = xmlCreateFileParserCtxt(fileName); break; case RS_XML_CONNECTION: ctx = RS_XML_xmlCreateConnectionParserCtxt((USER_OBJECT_) fileName); break; default: ctx = NULL; } if(ctx == NULL) { PROBLEM "Can't parse %s", fileName ERROR; } xmlParserHandler = (xmlSAXHandlerPtr) S_alloc(sizeof(xmlSAXHandler), 1); /* Make certain this is initialized so that we don't have any references to unwanted routines! */ memset(xmlParserHandler, '\0', sizeof(xmlSAXHandler)); RS_XML(initXMLParserHandler)(xmlParserHandler, saxVersion); parserData->ctx = ctx; ctx->userData = parserData; ctx->sax = xmlParserHandler; status = xmlParseDocument(ctx); ctx->sax = NULL; xmlFreeParserCtxt(ctx); return(status); /* Free(xmlParserHandler); */ }
static int ncXmlSAXParseFile(xmlSAXHandlerPtr sax, void *user_data, const char *filename) { int ret = 0; xmlParserCtxtPtr ctxt = xmlCreateFileParserCtxt(filename); if (!ctxt) return -1; ctxt->sax = sax; ctxt->userData = user_data; xmlParseDocument(ctxt); ret = ctxt->wellFormed ? 0 : -1; if (sax) ctxt->sax = NULL; xmlFreeParserCtxt(ctxt); return ret; }
bool LibxmlSaxParser::parseFile( const char* fileName ) { mParserContext = xmlCreateFileParserCtxt(fileName); if ( !mParserContext ) { ParserError error(ParserError::SEVERITY_CRITICAL, ParserError::ERROR_COULD_NOT_OPEN_FILE, 0, 0, 0, 0, fileName); getParser()->getErrorHandler()->handleError(error); return false; } if (mParserContext->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler) { xmlFree(mParserContext->sax); } mParserContext->sax = &SAXHANDLER; mParserContext->userData = (void*)this; initializeParserContext(); xmlParseDocument(mParserContext); mParserContext->sax = 0; if ( mParserContext->myDoc ) { xmlFreeDoc(mParserContext->myDoc); mParserContext->myDoc = 0; } xmlFreeParserCtxt(mParserContext); mParserContext = 0; return true; }
std::auto_ptr<document> dom_parser::parse_file(const std::string& file_name) { set_global_variables global_variables; // Create a libxml2 parser context for parsing the xml file. dom_parser_context_wrapper context( xmlCreateFileParserCtxt(file_name.c_str()) ); if (context.get() == 0) { std::string what = "fail to parse xml file " + file_name + ": " + "unable to create libxml2 parser context"; throw dom_error(what); } if (context.get()->directory == 0) { const xmlChar* dir = detail::to_xml_chars(xmlParserGetDirectory(file_name.c_str())); context.get()->directory = const_cast<char*>(detail::to_chars(xmlStrdup(dir))); } // Parse xml file under the constructed parser context. xmlDoc* px = parse_in_context(context.get()); assert(px != 0); return std::auto_ptr<document>(new document(px)); }
int main(int argc, char* argv[]) { xmlParserCtxtPtr ctxt=NULL; xmlsubsParseState state; int i; state.fontfilename=NULL; state.use_freetype=0; fprintf(stderr,"argc=%d\n",argc); i=1; while (i < argc) { if (strcmp(argv[i],"-freetype")==0) { state.use_freetype=1; } else if (strcmp(argv[i],"-font")==0) { i++; state.fontfilename=argv[i]; } else { if (ctxt==NULL) { ctxt = (xmlParserCtxtPtr)xmlCreateFileParserCtxt(argv[i]); } } i++; } if (ctxt == NULL) { fprintf(stderr,"Usage: %s [-freetype] [-font font.ttf] filename.xml\n",argv[0]); exit(1); } ctxt->sax = &xmlsubsSAXParser; ctxt->userData = &state; xmlParseDocument(ctxt); ctxt->sax = NULL; xmlFreeParserCtxt(ctxt); fprintf(stderr,"Finished!\n"); exit(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; }
bool HandlerBase::Parse( const iStringT& fname ) { // FName converted to the ascii CvtTA<> fnameAnsi( fname.CStr() ); context_ = xmlCreateFileParserCtxt( fnameAnsi ); if ( !context_ ) throw SaxError(); xmlSAXHandler sh = { 0,0,0,0,0, 0, //zGetEntity, 0,0,0,0,0,0, zStartDocument, zEndDocument, zStartElement, zEndElement, 0, zCharacters, 0,0, zComment, zWarning, zzError, zFatalError, 0, zCDATABlock, 0 }; context_->sax = &sh; context_->userData = this; xmlSubstituteEntitiesDefault( 1 ); xmlKeepBlanksDefault( 0 ); xmlParseDocument( context_ ); bool wellFormed = context_->wellFormed ? true : false; context_->sax = 0; xmlFreeParserCtxt( context_ ); return wellFormed; }
{ } xmlDocPtr soap_xmlParseFile(const char *filename TSRMLS_DC) { xmlParserCtxtPtr ctxt = NULL; xmlDocPtr ret; zend_bool old_allow_url_fopen; /* xmlInitParser(); */ old_allow_url_fopen = PG(allow_url_fopen); PG(allow_url_fopen) = 1; ctxt = xmlCreateFileParserCtxt(filename); PG(allow_url_fopen) = old_allow_url_fopen; 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 {
/* * call-seq: * parse_file(filename) * * Parse file given +filename+ */ static VALUE parse_file(VALUE klass, VALUE filename) { xmlParserCtxtPtr ctxt = xmlCreateFileParserCtxt(StringValuePtr(filename)); return Data_Wrap_Struct(klass, NULL, deallocate, ctxt); }
/* parser for the complete xml file */ GList *parseDoc (char *docname) { xmlDocPtr doc; xmlNodePtr cur; xmlParserCtxtPtr ctxt; eventlist = g_list_alloc (); /* allocates memory for new list */ if (getValidate() == TRUE) { ctxt = xmlCreateFileParserCtxt(docname); if (ctxt == NULL) { exit (1); } ctxt->validate = 1; /* check the XML's DTD */ xmlParseDocument(ctxt); if (!ctxt->valid) { g_print ("Please correct this problem or grootevent isn't able to run.\n" "Hint: You could also disable validating (--help for more infos)\n"); exit (1); } } doc = xmlParseFile (docname); if (doc == NULL) { fprintf (stderr, "Document not parsed successfully. \n"); return NULL; } cur = xmlDocGetRootElement (doc); if (cur == NULL) { fprintf (stderr, "empty document\n"); xmlFreeDoc (doc); return NULL; } if (xmlStrcmp (cur->name, (const xmlChar *) "grootevent")) { fprintf (stderr, "document of the wrong type, root node != grootevent\n"); xmlFreeDoc (doc); return NULL; } cur = cur->xmlChildrenNode; while (cur != NULL) { if ((!xmlStrcmp (cur->name, (const xmlChar *) "eventinfo"))) { parseEventInfo (doc, cur); } cur = cur->next; } xmlFreeDoc (doc); return eventlist; }