本文整理汇总了C++中xmlParseFile函数的典型用法代码示例。如果您正苦于以下问题:C++ xmlParseFile函数的具体用法?C++ xmlParseFile怎么用?C++ xmlParseFile使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xmlParseFile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv)
{
xmlDocPtr doc;
char buf[1024];
FILE *f;
size_t l;
printf("- From file\n");
doc = xmlParseFile(argv[1]);
printf("encoding: %s\ncharset: %d\n",
doc->encoding, doc->charset);
xmlFreeDoc(doc);
f = fopen(argv[1], "r");
l = fread(buf, 1, 1024, f);
printf("- From memory\n");
doc = xmlParseMemory(buf, l);
printf("encoding: %s\ncharset: %d\n",
doc->encoding, doc->charset);
xmlFreeDoc(doc);
return 0;
}
示例2: parseDoc
Map* parseDoc(char* filename){
xmlDocPtr doc;
xmlNodePtr root_element;
doc = xmlParseFile(filename);
if (doc == NULL) {
fprintf(stderr, "Failed to parse %s\n", filename);
return NULL;
}
root_element = xmlDocGetRootElement(doc);
if (root_element == NULL){
fprintf(stderr, "empty document\n");
xmlFreeDoc(doc);
return NULL;
}
Map* map = malloc(sizeof(Map));
map = parseElements(doc, root_element);
xmlFreeDoc(doc);
return map;
}
示例3: ParseFlowListTag
short ParseFlowListTag( char *fname, void **list )
{
xmlDocPtr doc = NULL;
xmlNodePtr current;
FLOWCOMP rootComp;
short result = -1;
if ( list == NULL ) goto Err1;
if ( (doc = xmlParseFile( fname )) == NULL ) goto Err1;
current = xmlDocGetRootElement( doc );
if ( (current == NULL) || xmlStrcmp( current->name, (const xmlChar *)"maintenance-resource" ) ){
goto Err2;
}
memset( &rootComp, 0, sizeof(FLOWCOMP) );
current = current->xmlChildrenNode;
while ( current != NULL ){
if ( (!xmlStrcmp( current->name, (const xmlChar *)"flowlist" )) ){
if ( ParseFlowTag( current->xmlChildrenNode, &rootComp ) != 0 ) goto Err2;
break;
}
current = current->next;
}
*list = rootComp.next;
result = 0;
EXIT:
xmlFreeDoc( doc );
return result;
Err2:
FreeFlowCompList( rootComp.next );
Err1:
goto EXIT;
}
示例4: interpret_oglerc
int interpret_oglerc(char *filename)
{
xmlDocPtr doc;
xmlNodePtr cur;
doc = xmlParseFile(filename);
if(doc != NULL) {
cur = xmlDocGetRootElement(doc);
while(cur != NULL) {
if(!xmlIsBlankNode(cur)) {
if(!strcmp("ogle_conf", cur->name)) {
interpret_ogle_conf(doc, cur);
}
}
cur = cur->next;
}
xmlFreeDoc(doc);
return 0;
} else {
WARNING("Couldn't load config file\n");
return -1;
}
}
示例5: xmlParseFile
bool CZBConfiguration::ReadModelsFile(const char *_file)
{
std::cout << "parsing models file " << std::string(_file) << std::endl;
doc = xmlParseFile(_file);
if(doc==NULL)
{
//std::cerr << "XML file " << std::string(_file) << " empty" << std::endl;
return false;
}
root_element = xmlDocGetRootElement(doc);
for( xmlNode *level_1 = root_element->children ; level_1 != NULL ; level_1 = level_1->next)
{
// end_devices_models level
if(!xmlStrcmp(level_1->name,(const char *)"end_devices_model"))
for( xmlNode *level_2 = level_1->children ; level_2 != NULL; level_2 = level_2->next)
{
// model level
if(!xmlStrcmp(level_2->name,(const char *)"model"))
for( xmlNode *level_3 = level2->children; level_3 != NULL ; level_3 = level_3->next )
{
// channel level
}
if(!xmlStrcmp(level_2->name,(const char *)"models_version"))
{
}
}
}
return true;
}
示例6: loadCfg
/***
loadCfg: This function loads cfg file to RAM memory using libxml API functions
xmlfile: Cfg's file name
*/
void loadCfg(char *xmlfile)
{
xmlDoc *doc = NULL;
xmlNode *root_element = NULL;
LIBXML_TEST_VERSION
doc = xmlParseFile(xmlfile);
if (doc == NULL) {
printf("error: could not parse file file.xml\n");
exit(1);
}
root_element = xmlDocGetRootElement(doc);
puts("carregando nodos\n");
loadNodes(getElement(root_element, "nodes"));
puts("construindo arestas\n");
buildGraphFromEdges(getElement(root_element, "edges"));
xmlFreeDoc(doc);
xmlCleanupParser();
}
示例7: findTags
static void
findTags (void)
{
xmlNode *i;
xmlDocPtr doc = xmlParseFile(getInputFileName());
xmlNode *root;
if (doc == NULL) {
g_warning ("could not parse file");
}
root = xmlDocGetRootElement(doc);
for (i = root->children; i; i = i->next)
{
xmlNode *j;
if (!i->name)
continue;
if (strcmp ((const char*)i->name, "namespace") !=0)
continue;
for (j = i->children; j; j = j->next)
{
makeTags (j, NULL);
}
}
}
示例8: xmlParseFile
int File::loadXML(const char *filename, Context *ctx) {
xmlDocPtr doc = NULL;
xmlNodePtr root;
int length;
doc = xmlParseFile(filename);
if (!doc) {
fprintf(stderr, "could not parse XML\n");
return false;
}
root = doc->xmlRootNode;
length = setXML(root, ctx);
xmlFreeDoc(doc);
return length;
fail:
if (doc) {
xmlFreeDoc(doc);
}
return 0;
}
示例9: load_player_objects_from_file
bool
load_player_objects_from_file(struct creature *ch, const char *path)
{
int axs = access(path, W_OK);
if (axs != 0) {
if (errno != ENOENT) {
errlog("Unable to open xml equipment file '%s': %s",
path, strerror(errno));
return -1;
} else {
return 1; // normal no eq file
}
}
xmlDocPtr doc = xmlParseFile(path);
if (!doc) {
errlog("XML parse error while loading %s", path);
return -1;
}
xmlNodePtr root = xmlDocGetRootElement(doc);
if (!root) {
xmlFreeDoc(doc);
errlog("XML file %s is empty", path);
return 1;
}
for (xmlNodePtr node = root->xmlChildrenNode; node; node = node->next) {
if (xmlMatches(node->name, "object"))
(void)load_object_from_xml(NULL, ch, NULL, node);
}
xmlFreeDoc(doc);
return 0;
}
示例10: xmlCleanupParser
Manifest *create_manifest(const gchar *manifest_file, const unsigned int flags, const gchar *container_filter, const gchar *component_filter)
{
xmlDocPtr doc;
xmlNodePtr node_root;
Manifest *manifest;
/* Parse the XML document */
if((doc = xmlParseFile(manifest_file)) == NULL)
{
g_printerr("Error with parsing the manifest XML file!\n");
xmlCleanupParser();
return NULL;
}
/* Retrieve root element */
node_root = xmlDocGetRootElement(doc);
if(node_root == NULL)
{
g_printerr("The manifest XML file is empty!\n");
xmlFreeDoc(doc);
xmlCleanupParser();
return NULL;
}
/* Parse manifest */
manifest = parse_manifest(node_root, flags, container_filter, component_filter);
/* Cleanup */
xmlFreeDoc(doc);
xmlCleanupParser();
/* Return manifest */
return manifest;
}
示例11: gpa_printer_new_from_file
/**
* gpa_printer_new_from_file:
* @file:
*
* Load a new printer from @filename, file should contain a XML description
*
* Return Value:
**/
static GPANode *
gpa_printer_new_from_file (const gchar *file)
{
GPANode *printer = NULL;
xmlDocPtr doc;
xmlNodePtr node;
doc = xmlParseFile (file);
if (!doc) {
g_warning ("Could not parse %s\n", file);
return NULL;
}
node = doc->xmlRootNode;
printer = gpa_printer_new_from_tree (node);
xmlFreeDoc (doc);
if (!printer || !gpa_node_verify (printer)) {
g_warning ("Could not load printer from %s", file);
printer = NULL;
}
return printer;
}
示例12: _currentGameDescription
GameManager::GameManager () :
_currentGameDescription(0), _enginePath(GlobalRegistry().get(RKEY_ENGINE_PATH)), _cleanedEnginePath(
DirectoryCleaned(_enginePath)), _emptyString("")
{
GlobalRegistry().addKeyObserver(this, RKEY_ENGINE_PATH);
// greebo: Register this class in the preference system so that the constructPreferencePage() gets called.
GlobalPreferenceSystem().addConstructor(this);
// TODO Remove this and read the game.xml data from the xmlregistry, too
std::string strGameFilename = Environment::Instance().getAppPath() + "game.xml";
xmlDocPtr pDoc = xmlParseFile(strGameFilename.c_str());
if (pDoc) {
_currentGameDescription = new GameDescription(pDoc, strGameFilename);
// Import this information into the registry
//GlobalRegistry().importFromFile(strGameFilename, "");
xmlFreeDoc(pDoc);
} else {
gtkutil::errorDialog(_("XML parser failed to parse game.xml"));
}
initialise();
}
示例13: config_parse_file
int config_parse_file(const char *filename, ice_config_t *configuration)
{
xmlDocPtr doc;
xmlNodePtr node;
if (filename == NULL || strcmp(filename, "") == 0) return CONFIG_EINSANE;
xmlInitParser();
doc = xmlParseFile(filename);
if (doc == NULL) {
return CONFIG_EPARSE;
}
node = xmlDocGetRootElement(doc);
if (node == NULL) {
xmlFreeDoc(doc);
xmlCleanupParser();
return CONFIG_ENOROOT;
}
if (strcmp(node->name, "icecast") != 0) {
xmlFreeDoc(doc);
xmlCleanupParser();
return CONFIG_EBADROOT;
}
config_init_configuration(configuration);
configuration->config_filename = (char *)strdup(filename);
_parse_root(doc, node->xmlChildrenNode, configuration);
xmlFreeDoc(doc);
return 0;
}
示例14: readinput_init
void readinput_init(){
if(myid == 0) {
doc = xmlParseFile("input");
if (doc == NULL ) {
fprintf(stderr,"input file not parsed successfully. \n");
#if defined(HAVE_MPI)
MPI_Finalize();
#endif
exit(0);
}
cur = xmlDocGetRootElement(doc);
if (cur == NULL) {
fprintf(stderr,"input file is empty\n");
xmlFreeDoc(doc);
#if defined(HAVE_MPI)
MPI_Finalize();
#endif
exit(0);
}
}
}
示例15: create_file
void create_file(char *to, char *from, char *msg){
int rc;
xmlTextWriterPtr writer;
xmlDocPtr doc;
xmlNodePtr node, root;
xmlChar *tmp;
if(doc = xmlParseFile(to)){
root = xmlDocGetRootElement(doc);
xmlNodePtr pNode = xmlNewNode(0, (xmlChar*)"mes");
//xmlSetProp(pNode, (const xmlChar*) "id", (const xmlChar*) "val");
xmlSetProp(pNode, (const xmlChar*) "from", (const xmlChar*) from);
xmlNodeSetContent(pNode, (xmlChar*)msg);
xmlAddChild(root, pNode);
xmlSaveFileEnc(to, doc, MY_ENCODING);
xmlFreeDoc(doc);
}else{
doc = xmlNewDoc(BAD_CAST XML_DEFAULT_VERSION);
node = xmlNewDocNode(doc, NULL, BAD_CAST "inbox", NULL);
xmlDocSetRootElement(doc, node);
writer = xmlNewTextWriterTree(doc, node, 0);
rc = xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL);
rc = xmlTextWriterStartElement(writer, BAD_CAST "mes");
//rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "id", BAD_CAST "1");
rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "from", BAD_CAST from);
rc = xmlTextWriterEndAttribute(writer);
rc = xmlTextWriterWriteString(writer, (const xmlChar*) msg);
rc = xmlTextWriterEndElement(writer);
rc = xmlTextWriterEndDocument(writer);
xmlFreeTextWriter(writer);
xmlSaveFileEnc(to, doc, MY_ENCODING);
xmlFreeDoc(doc);
}
}