コード例 #1
0
ファイル: testReader.c プロジェクト: shines77/libs3_example
static void handleFile(const char *filename) {
    xmlTextReaderPtr reader;
    int ret;

    if (count) {
	elem = 0;
	attrs = 0;
    }

    reader = xmlNewTextReaderFilename(filename);
    if (reader != NULL) {
	if (valid)
	    xmlTextReaderSetParserProp(reader, XML_PARSER_VALIDATE, 1);

	/*
	 * Process all nodes in sequence
	 */
	ret = xmlTextReaderRead(reader);
	while (ret == 1) {
	    processNode(reader);
	    ret = xmlTextReaderRead(reader);
	}

	/*
	 * Done, cleanup and status
	 */
	xmlFreeTextReader(reader);
	if (ret != 0) {
	    printf("%s : failed to parse\n", filename);
	} else if (count)
	    printf("%s : %d elements, %d attributes\n", filename, elem, attrs);
    } else {
	fprintf(stderr, "Unable to open %s\n", filename);
    }
}
コード例 #2
0
ファイル: dax-parser.c プロジェクト: dlespiau/dax-svg
/**
 * dax_dom_document_new_from_file:
 *
 * Creates a new #DaxDomDocument. FIXME
 *
 * Return value: the newly created #DaxDomDocument instance
 */
DaxDomDocument *
dax_dom_document_new_from_file (const gchar  *filename,
                                GError      **error)
{
    DaxDomDocument *document;
    GFile *file, *directory;
    ParserContext ctx;
    gchar *base_uri;

    ctx.reader = xmlNewTextReaderFilename(filename);
    if (ctx.reader == NULL)
        return NULL;

    document = dax_document_new();
    ctx.current_node = DAX_DOM_NODE (document);

    /* Set up the base uri */
    file = g_file_new_for_commandline_arg (filename);
    directory = g_file_get_parent (file);
    base_uri = g_file_get_uri (directory);
    dax_dom_document_set_base_iri (document, base_uri);
    g_free (base_uri);
    g_object_unref (file);
    g_object_unref (directory);

    dax_dom_document_parse_and_setup (document, &ctx);

    return document;
}
コード例 #3
0
ファイル: tile_map_parse.c プロジェクト: mdegs/dabes_engine
TileMap *TileMap_parse(char *filename, Engine *engine) {
  TileMap *map = TileMap_create();

  xmlTextReaderPtr reader;
  int ret;
  TileMapParseStatus status = TILEMAP_PARSE_OK;

  reader = xmlNewTextReaderFilename(filename);
  if (reader != NULL) {
    ret = xmlTextReaderRead(reader);
    while (ret == 1) {
      status = TileMap_parse_map(reader, engine, map);
      ret = xmlTextReaderRead(reader);
    }
    xmlFreeTextReader(reader);
    if (ret != 0) {
      printf("%s : failed to parse\n", filename);
    }
  } else {
    printf("Unable to open %s", filename);
  }
  
  check(status == TILEMAP_PARSE_OK, "Error parsing tile map");
  return map;
error:
  TileMap_destroy(map);
  return NULL;
}
コード例 #4
0
//-----------------------------------------
bool RngValidator::run(const std::string& xml_file_pathname, const std::string& rng_file_pathname)
//-----------------------------------------
{
    // TODO handle multiple RNG files (eg viz)
    
    // RELAX NG Parser Context
    xmlRelaxNGParserCtxtPtr ctxt = xmlRelaxNGNewParserCtxt(rng_file_pathname.c_str());
    xmlRelaxNGSetParserErrors(ctxt,
                              (xmlRelaxNGValidityErrorFunc)RngValidator::rngErr,
                              (xmlRelaxNGValidityWarningFunc)RngValidator::rngWarn,
                              NULL);

    xmlRelaxNGPtr schema = xmlRelaxNGParse(ctxt);
    xmlRelaxNGFreeParserCtxt(ctxt);

    xmlTextReaderPtr reader = xmlNewTextReaderFilename(xml_file_pathname.c_str());

    xmlTextReaderRelaxNGSetSchema(reader, schema);

    xmlTextReaderSetErrorHandler(reader, (xmlTextReaderErrorFunc)RngValidator::readerErr, NULL);
    xmlTextReaderSetStructuredErrorHandler(reader, (xmlStructuredErrorFunc)RngValidator::structErr, NULL);

    while (xmlTextReaderRead(reader));

    const bool valid = xmlTextReaderIsValid(reader) == 1;

    xmlFreeTextReader(reader);
    xmlRelaxNGFree(schema);

    return valid;
}
コード例 #5
0
ファイル: xmlread.c プロジェクト: egawata/hatena_blog
int main(int argc, char *argv[])
{
    xmlTextReaderPtr reader;
    int ret;

    //  Readerの作成
    reader = xmlNewTextReaderFilename("./sample.xml");
    if ( !reader ) {
        printf("Failed to open XML file.\n");
        return 1;
    }

    printf("-----------------------\n"); 
    
    //  次のノードに移動 
    ret = xmlTextReaderRead(reader);
    while (ret == 1) {
        //  現在のノードを処理
        processNode(reader);

        //  次のノードに移動
        ret = xmlTextReaderRead(reader);
    }
    
    //  Reader のすべてのリソースを開放
    xmlFreeTextReader(reader);

    //  xmlTextReaderRead の戻り値が -1 だった場合はパースエラー
    if (ret == -1) {
        printf("Parse error.\n");
        return 1;
    }

    return 0;
}
コード例 #6
0
ファイル: oval_defModel.c プロジェクト: GovReady/openscap
int oval_definition_model_merge(struct oval_definition_model *model, const char *file)
{
	__attribute__nonnull__(model);

	int ret;

	xmlTextReader *reader = xmlNewTextReaderFilename(file);
	if (reader == NULL) {
		oscap_seterr(OSCAP_EFAMILY_GLIBC, "%s '%s'", strerror(errno), file);
		return -1;
	}

	/* setup context */
	struct oval_parser_context context;
	context.reader = reader;
	context.definition_model = model;
	context.user_data = NULL;
	xmlTextReaderSetErrorHandler(reader, &libxml_error_handler, &context);
	/* jump into oval_definitions */
	while (xmlTextReaderRead(reader) == 1 && xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT) ;
	/* start parsing */
	ret = oval_definition_model_parse(reader, &context);
	xmlFreeTextReader(reader);

	return ret;
}
コード例 #7
0
static void
load_mime_from_xml (void)
{
	xmlTextReaderPtr reader;
	const char *xml_file;
	int ret;
	LibreImpuestoMimePermission permission = LIBRE_IMPUESTO_MIME_PERMISSION_UNKNOWN;

	g_return_if_fail (mime_table == NULL);

	mime_table = g_hash_table_new_full (g_str_hash, g_str_equal,
					    xmlFree, NULL);

	xml_file = libre_impuesto_file ("mime-types-permissions.xml");
	if (xml_file == NULL)
	{
		g_warning ("MIME types permissions file not found!\n");
		return;
	}

	reader = xmlNewTextReaderFilename (xml_file);
	if (reader == NULL)
	{
		g_warning ("Could not load MIME types permissions file!\n");
		return;
	}

	ret = xmlTextReaderRead (reader);
	while (ret == 1)
	{
		const xmlChar *tag;
		xmlReaderTypes type;

		tag = xmlTextReaderConstName (reader);
		type = xmlTextReaderNodeType (reader);

		if (xmlStrEqual (tag, (const xmlChar *)"safe") && type == XML_READER_TYPE_ELEMENT)
		{
			permission = LIBRE_IMPUESTO_MIME_PERMISSION_SAFE;
		}
		else if (xmlStrEqual (tag, (const xmlChar *)"unsafe") && type == XML_READER_TYPE_ELEMENT)
		{
			permission = LIBRE_IMPUESTO_MIME_PERMISSION_UNSAFE;
		}
		else if (xmlStrEqual (tag, (const xmlChar *)"mime-type"))
		{
			xmlChar *type;

			type = xmlTextReaderGetAttribute (reader, (const xmlChar *)"type");
			g_hash_table_insert (mime_table, type,
					     GINT_TO_POINTER (permission));
		}

		ret = xmlTextReaderRead (reader);
	}

	xmlFreeTextReader (reader);
}
コード例 #8
0
ファイル: xmlreader.c プロジェクト: matsuu/konoha
/* @method This! XmlReader.new(String filename) */
METHOD XmlReader_new(Ctx *ctx, knh_sfp_t *sfp)
{
    char* filename = (char*)p_char(sfp[1]);
    xmlTextReaderPtr reader = xmlNewTextReaderFilename(filename);
    if(reader == NULL) {
        KNH_THROWs(ctx, "XmlReader: cant load file");
    }
    knh_Glue_init(ctx,sfp[0].glue,reader,knh_xmlreader_gfree);
    KNH_RETURN(ctx,sfp,sfp[0].o);
}
コード例 #9
0
ファイル: xml_glue.c プロジェクト: Kouhei-Moriya/konoha3
//## @Native XmlReader XmlReader.new(String path);
static KMETHOD XmlReader_new(KonohaContext *kctx, KonohaStack *sfp)
{
	const char *path = kString_text(sfp[1].asString);
	xmlTextReaderPtr r = xmlNewTextReaderFilename(path);
	struct kXmlReaderVar *xml = (struct kXmlReaderVar *)KLIB new_kObject(kctx, OnStack, KGetReturnType(sfp), 0);
	if(r == NULL) {
		//kreportf(ErrTag, sfp[K_RTNIDX].uline, "could not create XmlReader Object from %s", path);
	}
	xml->reader = (xmlTextReaderPtr)r;
	KReturn(xml);
}
コード例 #10
0
XmlReader::XmlReader(const char *fileName)
{
    mImpl = xmlNewTextReaderFilename(fileName);
    if(!mImpl)
    {
        std::stringstream msg;
        msg << "Couldn't read xml file " << fileName;
        throw Exception(msg.str());
    }

    Advance();
}
コード例 #11
0
ファイル: xml_parser.cpp プロジェクト: hunanhd/vns
void openXMLDocument (const char * __filename)
{

  reader = xmlNewTextReaderFilename (__filename);

  if (! reader)
    {

      fprintf (stderr, "unable to open '%s'.\n", __filename);
      exit (1);
    }
}
コード例 #12
0
ファイル: xml-reader.c プロジェクト: GNOME/gnome-builder
gboolean
xml_reader_load_from_path (XmlReader   *reader,
                           const gchar *path)
{
  g_return_val_if_fail (XML_IS_READER (reader), FALSE);

  xml_reader_clear (reader);

  if ((reader->xml = xmlNewTextReaderFilename (path)))
    xmlTextReaderSetErrorHandler (reader->xml, xml_reader_error_cb, reader);

  return (reader->xml != NULL);
}
コード例 #13
0
ファイル: fucheck.c プロジェクト: fepz/fucheck
xmlTextReaderPtr getDoc(char *file) 
{
	xmlTextReaderPtr reader;

	reader = xmlNewTextReaderFilename(file);

	if (reader == NULL) {
		fprintf(stderr, "Unable to open %s\n", file);
		exit(EXIT_FAILURE);
	}

	return reader;
}
コード例 #14
0
ファイル: protoXml.cpp プロジェクト: Nhuongld/nsj
bool ProtoXml::IterParser::Open(const char* fileName, const char* filterPath)
{
    Close();  // just in case already open
    if (NULL == (reader_ptr = xmlNewTextReaderFilename(fileName)))
    {
        PLOG(PL_ERROR, "ProtoXml::IterParser::Open() xmlNewTextReaderFilename() error: %s\n",
             GetErrorString());
        return false;
    }
    if (NULL != filterPath)
        IterFilterBase::SetFilter(filterPath);
    return true;
}  // end ProtoXml::IterParser::Open()
コード例 #15
0
/*Read values from XML21 file 读取XML21,pm2pm物理机之间的时延带宽信息文件*/
int get_pm2pm_from_xml21(char *filename)
{

    xmlTextReaderPtr reader;
	xmlChar *name;
    
	int swc=0,psc=0,ssc=0;

	int ret=0;
	
    reader = xmlNewTextReaderFilename(filename);
	
    if (reader != NULL) {
        ret = xmlTextReaderRead(reader);
		
		name = xmlTextReaderName(reader);/*获取reader的元素名称*/
		if (name == NULL)
			name = xmlStrdup(BAD_CAST "--");
		
		/*在这个例子中,我们需要确认文档是正确的类型。“DATA”是在这个示例中使用文档的根类型。*/
		if (xmlStrcmp(name, (xmlChar *) "DATA")) {
			fprintf(stderr,"document of the wrong type, root node != DATA");
			xmlFree(name);
			xmlFreeTextReader(reader);
		}	
        
		while (ret == 1) {
            process_XML21_Node(reader, &swc,&psc,&ssc);
			
            ret = xmlTextReaderRead(reader);
	    }
        
		xmlFreeTextReader(reader);

        if (ret != 0) {
            printf("%s : failed to parse\n", filename);
        }
    
	} 
	else 
	    printf("Unable to open %s\n", filename);
    
	_xpthis->sd->sw_total=swc; /*更新共享数据的全局变量*/
	_xpthis->sd->p2s_total=psc;
	_xpthis->sd->s2s_total=ssc;

	ret=swc+1;

	return ret;

}
コード例 #16
0
/*Read values from XML2 file 读取XML2文件*/
static int get_request_from_xml1(char *filename) 
{
    xmlTextReaderPtr reader;
	xmlChar *name;
    
	int reqc=-1,parac=-1;
	int ret=0;
	
    reader = xmlNewTextReaderFilename(filename);
	
    if (reader != NULL) {
        ret = xmlTextReaderRead(reader);
		
		name = xmlTextReaderName(reader);/*获取reader的元素名称*/
		if (name == NULL)
			name = xmlStrdup(BAD_CAST "--");
		
		/*在这个例子中,我们需要确认文档是正确的类型。“DATA”是在这个示例中使用文档的根类型。*/
		if (xmlStrcmp(name, (const xmlChar *) "CONTROLOR")) {
			fprintf(stderr,"document of the wrong type, root node != CONTROLOR");
			xmlFree(name);
			xmlFreeTextReader(reader);
			return ret;
		}
		
		
        while (ret == 1) {/*处理每个节点*/
            process_XML1_Node(reader, &reqc, &parac);
			
            ret = xmlTextReaderRead(reader);
	    }
        
		xmlFreeTextReader(reader);

        if (ret != 0) {
            printf("%s : failed to parse\n", filename);
        }
    
	} 
	else 
	    printf("Unable to open %s\n", filename);
    
	
	/*更新共享数据*/
	_xpthis->sd->req_total=reqc+1;
	
	

	return ret;
}
コード例 #17
0
ファイル: xmlparser.cpp プロジェクト: forthyen/SDesk
XMLParser::XMLParser( intf_thread_t *pIntf, const string &rFileName ):
    SkinObject( pIntf )
{
    m_pReader = xmlNewTextReaderFilename( rFileName.c_str() );
    if( !m_pReader )
    {
        msg_Err( getIntf(), "Failed to open %s for parsing",
                 rFileName.c_str() );
        return;
    }

    // Activate DTD validation
    xmlTextReaderSetParserProp( m_pReader, XML_PARSER_DEFAULTATTRS, 1 );
    xmlTextReaderSetParserProp( m_pReader, XML_PARSER_VALIDATE, 1 );

    // Set the error handler
    xmlTextReaderSetErrorHandler( m_pReader, handleError, this );
}
コード例 #18
0
/*Read values from XML22 file 读取XML22,虚拟机之间的流量信息文件*/
int get_vm2vm_from_xml22(char *filename) 
{
    xmlTextReaderPtr reader;
	xmlChar *name;
    
	int vd=-1,ret=0;
	
    reader = xmlNewTextReaderFilename(filename);
	
    if (reader != NULL) {
        ret = xmlTextReaderRead(reader);
		
		name = xmlTextReaderName(reader);/*获取reader的元素名称*/
		if (name == NULL)
			name = xmlStrdup(BAD_CAST "--");
		
		/*在这个例子中,我们需要确认文档是正确的类型。“DATA”是在这个示例中使用文档的根类型。*/
		if (xmlStrcmp(name, (xmlChar *) "DATA")) {
			fprintf(stderr,"document of the wrong type, root node != DATA");
			xmlFree(name);
			xmlFreeTextReader(reader);
			return ret;
		}		
		
        while (ret == 1) {
            process_XML22_Node(reader,&vd);
			
            ret = xmlTextReaderRead(reader);
	    }
        
		xmlFreeTextReader(reader);

        if (ret != 0) {
            printf("%s : failed to parse\n", filename);
        }
    
	} 
	else 
	    printf("Unable to open %s\n", filename);
    
	_xpthis->sd->v2v_total=vd+1;/*在全局共享数据区记录v2v的总数*/
	
	return ret;
}
コード例 #19
0
ファイル: apixmlread.c プロジェクト: actility/ong
/*DEF*/void *XoReadXmlEx(char *filename,char *roottype,int flags,int *err)
{
	xmlTextReaderPtr reader	= NULL;
	void		 *obj;

	*err	= 0;
	reader = xmlNewTextReaderFilename(filename);
	if (reader == NULL) 
	{
		char	tmperr[256];
		sprintf(tmperr,"XoReadXmlEx(%s) : cannot create reader file\n", 
								filename);
		XOERR(tmperr,0);
		return	NULL;
	}
	obj	= XoReadXmlReader(reader,roottype,flags,err);
	xmlFreeTextReader(reader);
	return	obj;
}
コード例 #20
0
	/**
	 * Streams XML file using callback
	**/
	int streamFile(char *filename, char *objPath, ruleExecInfo_t* rei) {
		xmlTextReaderPtr reader;
		int ret;

		rodsLog( LOG_NOTICE, "Calling streamFile()\n");
		
		reader = xmlNewTextReaderFilename(filename);
		if (reader != NULL) {
			ret = xmlTextReaderRead(reader);
			while (ret == 1 && end == 0) {
				processNode(reader, objPath, rei);
				ret = xmlTextReaderRead(reader);
			}
			xmlFreeTextReader(reader);
			end = 0;
		} else {
			printf("Unable to open %s\n", filename);
		}
		return 0;
	}
コード例 #21
0
ファイル: apixmlobix.c プロジェクト: sanyaade-iot/ong
/*DEF*/void *XoReadObixEx(char *filename,void *unused,int flags,int *err)
{
    xmlTextReaderPtr reader	= NULL;
    void		 *obj;

    flags	= flags | XOML_PARSE_OBIX;
    *err	= 0;
    reader = xmlNewTextReaderFilename(filename);
    if (reader == NULL)
    {
        char	tmperr[256];
        sprintf(tmperr,"XoReadObixEx(%s):cannot create reader file\n",
                filename);
        XOERR(tmperr,0);
        return	NULL;
    }
    obj	= XoReadXmlReader(reader,NULL,flags,err);
    xmlFreeTextReader(reader);
    return	obj;
}
コード例 #22
0
BEXMLTextReader::BEXMLTextReader ( const string path )
{
	last_node = false;
	
	boost::filesystem::path file = path;
	bool file_exists = boost::filesystem::exists ( file );

	if ( file_exists ) {

		reader = xmlNewTextReaderFilename ( path.c_str() );

		if ( reader != NULL ) {
			xml_document = xmlTextReaderCurrentDoc ( reader );
		} else {
			throw BEXMLReaderInterface_Exception ( last_error() );
		}
		
	} else {
		throw BEXMLReaderInterface_Exception ( kNoSuchFileOrDirectoryError );
	}

}
コード例 #23
0
ファイル: osm2pgsql.c プロジェクト: azzaxp/osm2pgsql
void streamFile(char *filename) {
   xmlTextReaderPtr reader;
   int ret;

   reader = xmlNewTextReaderFilename(filename);
   if (reader != NULL) {
      ret = xmlTextReaderRead(reader);
      while (ret == 1) {
         processNode(reader);
         ret = xmlTextReaderRead(reader);
      }

      if (ret != 0) {
         fprintf(stderr, "%s : failed to parse\n", filename);
         return;
      }

      xmlFreeTextReader(reader);
   } else {
      fprintf(stderr, "Unable to open %s\n", filename);
   }
}
コード例 #24
0
ファイル: xmltv.c プロジェクト: AlwinEsch/pvr.stalker
sc_list_t *sc_xmltv_parse(const char *filename) {
    xmlTextReaderPtr reader = NULL;
    sc_list_t *channels = NULL;
    sc_list_t *programmes = NULL;
    int ret;
    sc_list_node_t *node = NULL;

    reader = xmlNewTextReaderFilename(filename);
    if (!reader)
        return NULL;

    channels = sc_list_create();
    programmes = sc_list_create();

    for (ret = xmlTextReaderRead(reader); ret == 1; ret = xmlTextReaderRead(reader)) {
        if (sc_xmltv_check_current_reader_node(reader, XML_READER_TYPE_ELEMENT, SC_XMLTV_CHANNEL_NAME,
                                               SC_XMLTV_CHANNEL_DEPTH)) {
            node = sc_list_node_create(sc_xmltv_parse_channel(reader));
            sc_list_node_append(channels, node);
        }
        if (sc_xmltv_check_current_reader_node(reader, XML_READER_TYPE_ELEMENT, SC_XMLTV_PROGRAMME_NAME,
                                               SC_XMLTV_PROGRAMME_DEPTH)) {
            node = sc_list_node_create(sc_xmltv_parse_programme(reader));
            sc_list_node_append(programmes, node);
        }
    }

    xmlFreeTextReader(reader);

    node = channels->first;
    while (node) {
        sc_xmltv_link_progs_to_chan(programmes, (sc_xmltv_channel_t *) node->data);
        node = node->next;
    }

    sc_xmltv_list_free(SC_XMLTV_PROGRAMME, &programmes);

    return channels;
}
コード例 #25
0
bool Table::rewind()
{
  xmlTextReaderPtr reader = NULL;

  if ( (reader = xmlNewTextReaderFilename(getName().c_str())) == NULL)
  {
    cout<<endl<<"Essai d'ouvrir "<< getName() <<endl;
    cout << "erreur fatale " << endl;
    return (false);
  }

  xmlTextReaderRead(reader);

  // initialisation du xmlReader
  setXmlReader(reader);
  // Utilise readHeader()
  readHeader();

  // le tuple courant est 0
  currentTuple = 0;

  return (true);
}
コード例 #26
0
ファイル: xml_parser.cpp プロジェクト: BlueBrain/FlowVR
int streamXmlFile(const char *filename, Q3ListViewItem* item) {
	xmlTextReaderPtr reader;
	int ret;

	reader = xmlNewTextReaderFilename(filename);
	if (reader != NULL) {
		ret = xmlTextReaderRead(reader);
		while (ret == 1) {
			processNode(reader, &item);
			ret = xmlTextReaderRead(reader);
		}
		xmlFreeTextReader(reader);
		if (ret != 0) {
			printf("%s : failed to parse\n", filename);
			return 0;
		}
	} else {
		printf("Unable to open %s\n", filename);
		return 0;
	}

	return 1;
}
コード例 #27
0
static void
load_iso_entries (int iso,
		  GFunc read_entry_func,
		  gpointer user_data)
{
	xmlTextReaderPtr reader;
	ParserState state = STATE_START;
	xmlChar iso_entries[32], iso_entry[32];
	char *filename;
	int ret = -1;

	cedit_debug_message (DEBUG_PLUGINS, "Loading ISO-%d codes", iso);

	filename = g_strdup_printf (ISO_CODES_PREFIX "/share/xml/iso-codes/iso_%d.xml", iso);
	reader = xmlNewTextReaderFilename (filename);
	if (reader == NULL) goto out;

	xmlStrPrintf (iso_entries, sizeof (iso_entries), (const xmlChar *)"iso_%d_entries", iso);
	xmlStrPrintf (iso_entry, sizeof (iso_entry), (const xmlChar *)"iso_%d_entry", iso);

	ret = xmlTextReaderRead (reader);

	while (ret == 1)
	{
		const xmlChar *tag;
		xmlReaderTypes type;

		tag = xmlTextReaderConstName (reader);
		type = xmlTextReaderNodeType (reader);

		if (state == STATE_ENTRIES &&
		    type == XML_READER_TYPE_ELEMENT &&
		    xmlStrEqual (tag, iso_entry))
		{
			read_entry_func (reader, user_data);
		}
		else if (state == STATE_START &&
			 type == XML_READER_TYPE_ELEMENT &&
			 xmlStrEqual (tag, iso_entries))
		{
			state = STATE_ENTRIES;
		}
		else if (state == STATE_ENTRIES &&
			 type == XML_READER_TYPE_END_ELEMENT &&
			 xmlStrEqual (tag, iso_entries))
		{
			state = STATE_STOP;
		}
		else if (type == XML_READER_TYPE_SIGNIFICANT_WHITESPACE ||
			 type == XML_READER_TYPE_WHITESPACE ||
			 type == XML_READER_TYPE_TEXT ||
			 type == XML_READER_TYPE_COMMENT)
		{
			/* eat it */
		}
		else
		{
			/* ignore it */
		}

		ret = xmlTextReaderRead (reader);
	}

	xmlFreeTextReader (reader);

out:
	if (ret < 0 || state != STATE_STOP)
	{
		g_warning ("Failed to load ISO-%d codes from %s!\n",
			   iso, filename);
	}

	g_free (filename);
}
コード例 #28
0
GWeatherParser *
_gweather_parser_new (void)
{
    GWeatherParser *parser;
    int zlib_support;
    int keep_going;
    char *filename;
    char *tagname, *format;
    time_t now;
    struct tm tm;

    _gweather_gettext_init ();

    parser = g_slice_new0 (GWeatherParser);

    zlib_support = xmlHasFeature (XML_WITH_ZLIB);

    filename = g_build_filename (GWEATHER_XML_LOCATION_DIR, "Locations.xml", NULL);

    if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR) && zlib_support) {
        g_free (filename);
	filename = g_build_filename (GWEATHER_XML_LOCATION_DIR, "Locations.xml.gz", NULL);
    }

    /* Open the xml file containing the different locations */
    parser->xml = xmlNewTextReaderFilename (filename);
    g_free (filename);

    if (parser->xml == NULL)
	goto error_out;

    /* fast forward to the first element */
    do {
	/* if we encounter a problem here, exit right away */
	if (xmlTextReaderRead (parser->xml) != 1)
	    goto error_out;
    } while (xmlTextReaderNodeType (parser->xml) != XML_READER_TYPE_ELEMENT);

    /* check the name and format */
    tagname = (char *) xmlTextReaderName (parser->xml);
    keep_going = tagname && !strcmp (tagname, "gweather");
    xmlFree (tagname);

    if (!keep_going)
	goto error_out;

    format = (char *) xmlTextReaderGetAttribute (parser->xml, (xmlChar *) "format");
    keep_going = format && !strcmp (format, "1.0");
    xmlFree (format);

    if (!keep_going)
	goto error_out;

    /* Get timestamps for the start and end of this year */
    now = time (NULL);
    tm = *gmtime (&now);
    tm.tm_mon = 0;
    tm.tm_mday = 1;
    tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
    parser->year_start = mktime (&tm);
    tm.tm_year++;
    parser->year_end = mktime (&tm);

    parser->metar_code_cache = g_hash_table_new_full (g_str_hash, g_str_equal,
						      NULL, gweather_location_list_free);
    parser->timezone_cache = g_hash_table_new_full (g_str_hash, g_str_equal,
						    NULL, (GDestroyNotify) gweather_timezone_unref);
    parser->country_code_cache = g_hash_table_new_full (g_str_hash, g_str_equal,
							NULL, (GDestroyNotify) gweather_location_unref);

    return parser;

error_out:
    _gweather_parser_free (parser);
    return NULL;
}
コード例 #29
0
static rrd_t *parse_file(
    const char *filename)
{
    xmlTextReaderPtr reader;
    int       status;

    rrd_t    *rrd;
    stdioXmlReaderContext *sctx = NULL;

    /* special handling for XML on stdin (like it is the case when using
       the pipe interface) */
    if (strcmp(filename, "-") == 0) {
		sctx = (stdioXmlReaderContext *) malloc(sizeof(*sctx));
	if (sctx == NULL) {
	    rrd_set_error("parse_file: malloc failed.");
	    return (NULL);
	}
	sctx->stream = stdin;
	sctx->freeOnClose = 1;
	sctx->closed = 0;
	sctx->eofchar = 0x1A; /* ctrl-Z */

	xmlSetGenericErrorFunc(NULL, ignoringErrorFunc);

        reader = xmlReaderForIO(stdioXmlInputReadCallback,
                                stdioXmlInputCloseCallback,
                                sctx, 
                                filename,
                                NULL,
                                0);
    } else {
        reader = xmlNewTextReaderFilename(filename);
    } 
    if (reader == NULL) {
	if (sctx != NULL) free(sctx);

        rrd_set_error("Could not create xml reader for: %s",filename);
        return (NULL);
    }

    /* NOTE: from now on, sctx will get freed implicitly through
     * xmlFreeTextReader and its call to
     * stdioXmlInputCloseCallback. */

    if (expect_element(reader,"rrd") != 0) {
        xmlFreeTextReader(reader);
        return (NULL);
    }

    rrd = (rrd_t *) malloc(sizeof(rrd_t));
    if (rrd == NULL) {
        rrd_set_error("parse_file: malloc failed.");
        xmlFreeTextReader(reader);
        return (NULL);
    }
    memset(rrd, '\0', sizeof(rrd_t));

    rrd->stat_head = (stat_head_t *) malloc(sizeof(stat_head_t));
    if (rrd->stat_head == NULL) {
        rrd_set_error("parse_tag_rrd: malloc failed.");
        xmlFreeTextReader(reader);
        free(rrd);
        return (NULL);
    }
    memset(rrd->stat_head, '\0', sizeof(stat_head_t));

    strncpy(rrd->stat_head->cookie, "RRD", sizeof(rrd->stat_head->cookie));
    rrd->stat_head->float_cookie = FLOAT_COOKIE;

    rrd->live_head = (live_head_t *) malloc(sizeof(live_head_t));
    if (rrd->live_head == NULL) {
        rrd_set_error("parse_tag_rrd: malloc failed.");
        xmlFreeTextReader(reader);
        free(rrd->stat_head);
        free(rrd);
        return (NULL);
    }
    memset(rrd->live_head, '\0', sizeof(live_head_t));

    status = parse_tag_rrd(reader, rrd);

    xmlFreeTextReader(reader);

    if (status != 0) {
        local_rrd_free(rrd);
        rrd = NULL;
    }

    return (rrd);
}                       /* rrd_t *parse_file */
コード例 #30
0
gboolean
biji_lazy_deserialize_internal (BijiLazyDeserializer *self)
{
  BijiNoteObj* n = self->priv->note;
  xmlDocPtr doc;
  xmlNodePtr cur;
  xmlChar     *version; 

  doc = xmlParseFile (biji_note_obj_get_path (n));

  if (doc == NULL ) 
  {
    g_warning ("File not parsed successfully");
    return FALSE;
  }

  cur = xmlDocGetRootElement (doc);

  if (cur == NULL) 
  {
    g_warning ("File empty");
    xmlFreeDoc(doc);
    return FALSE;
  }

  if (xmlStrcmp(cur->name, (const xmlChar *) "note")) 
  {
    g_message ("document of the wrong type, root node != note");
    xmlFreeDoc(doc);
    return FALSE;
  }

  /* Switch there for note type
   * Despite not yet handled */

  version = xmlGetNoNsProp (cur, BAD_CAST "version");

  /* Bijiben type */
  if (g_strcmp0 ((gchar*) cur->ns->href, BIJI_NS) ==0) {
    self->priv->type = BIJIBEN_1;
  }

  /* Tomboy type */
  else {
    if (g_strcmp0 ((gchar*) cur->ns->href, TOMBOY_NS) == 0)
    {
      if (g_strcmp0 ((const gchar*) version, "0.1") == 0)
        self->priv->type = TOMBOY_1;

      if (g_strcmp0 ((const gchar*) version, "0.2") == 0)
        self->priv->type = TOMBOY_2;

      if (g_strcmp0 ((const gchar*) version, "0.3") == 0)
        self->priv->type = TOMBOY_3;
    }

  /* Wow this note won't be loaded i guess */
    else {
      self->priv->type = NO_TYPE;
    }
  }

  xmlFree (version);

  self->priv->r = xmlNewTextReaderFilename (biji_note_obj_get_path (n));
  biji_parse_file (self);
  xmlFreeDoc (doc);

  return TRUE ;
}