void glist(xmlNode *action, int pid) { xmlNode *child = NULL; xmlNode *cur = action; if (strcmp(cur->name, "action") == 0) { for ( cur = action->children; cur; cur = cur->next) { if ( !xmlNodeIsText(cur) && !strcmp(cur->name, "script")) { for ( child = action->children; child; child = child->next) { if(!xmlNodeIsText(child) && !strcmp(child->name, "req_resource")) { set_glist(child,pid); } if(!xmlNodeIsText(child) && !strcmp(child->name, "prov_resource")) { set_glist(child,pid); } } } } } }
static void populate_model_from_file (GvcSoundThemeChooser *chooser, GtkTreeModel *model, const char *filename) { xmlDocPtr doc; xmlNodePtr root; xmlNodePtr child; gboolean exists; exists = g_file_test (filename, G_FILE_TEST_EXISTS); if (! exists) { return; } doc = xmlParseFile (filename); if (doc == NULL) { return; } root = xmlDocGetRootElement (doc); for (child = root->children; child; child = child->next) { if (xmlNodeIsText (child)) { continue; } if (xmlStrcmp (child->name, GVC_SOUND_SOUND) != 0) { continue; } populate_model_from_node (chooser, model, child); } xmlFreeDoc (doc); }
static int parse_include (xmlNodePtr include, void *arg) { char *pattern = NULL; int ret = 0; xmlNodePtr node = include->xmlChildrenNode; if (xmlNodeIsText (node) == 0) return -1; pattern = (char *)xmlNodeListGetString (node->doc, node, 1); do { #if HAVE_GLOB glob_t globbuf; if (glob (pattern, 0, NULL, &globbuf) == 0) { int i; for (i=0; i<globbuf.gl_pathc; i++) { xmlDocPtr sub_doc = xmlParseFile (globbuf.gl_pathv[i]); if (sub_doc) { xmlNodePtr sub_node = xmlDocGetRootElement (sub_doc); if (sub_node) xmlAddNextSibling (include, sub_node); xmlFreeDoc (sub_doc); continue; } ret = -1; break; } } globfree (&globbuf); #elif HAVE_DECL_FINDFIRSTFILE WIN32_FIND_DATA filedata; HANDLE hFind = FindFirstFile (pattern, &filedata); do { if ((filedata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { xmlDocPtr sub_doc = xmlParseFile (filedata.cFileName); if (sub_doc) { xmlNodePtr sub_node = xmlDocGetRootElement (sub_doc); if (sub_node) xmlAddNextSibling (include, sub_node); xmlFreeDoc (sub_doc); continue; } ret = -1; break; } } while (FindNextFile (hFind, &filedata) != 0); FindClose (hFind); #endif } while (0); xmlFree (pattern); return ret; }
XPFCapability* PluginOILFilter::CreateColourNode(xmlNodePtr pNode) { XPFCapability* pCap = NULL; wxString strName = CXMLUtils::ConvertToWXString(pNode->name); if (strName == _T("#text") || xmlNodeIsText(pNode)) { wxString str = CXMLUtils::ConvertToWXString(xmlNodeGetContent(pNode)); TRACEUSER("Phil", _T("CreateColourNode ignoring text %s\n"), (LPCTSTR)str); return(NULL); } XPFConvertType AsType = XPFCONVTYPE_UNKNOWN; BOOL bOK = GetConvertAsType(pNode, &AsType); if (!bOK) { TRACEUSER("Phil", _T("CreateColourNode GetConvertAsType failed\n")); return NULL; } if (strName == _T("Colour")) { pCap = new XPFCColour(AsType); } else { ERROR1(NULL, _R(IDE_XPF_BADXML_UNEXPECTED_COLOURTYPE)); } xmlNodePtr pChild; pChild = pNode->children; XPFCapability* pLast = NULL; while (pChild) { XPFCapability* pCapNode = CreateColourNode(pChild); if (pCapNode) { // If we have a node then add it to the list // If we do not have a node already then set m_pObjects if (pLast) { pLast->SetNext(pCapNode); } else { pCap->SetChild(pCapNode); } pLast = pCapNode; } pChild = pChild->next; } return(pCap); }
static void parseStyle (xmlDocPtr doc, xmlNodePtr cur, FB2Content *fb) { xmlChar *content; xmlChar *prop; int start = fb->utf8_current_index; prop = xmlGetProp(cur, (const xmlChar *)"name"); cur = cur->children; while (cur != NULL) { if (xmlNodeIsText(cur)) { content = xmlNodeGetContent(cur); if (content) bufferAppend(content, xmlStrlen(content), fb); xmlFree(content); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"style")) { parseStyle(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"strong")) { content = xmlNodeGetContent(cur->children); if (content) { int st = fb->utf8_current_index; bufferAppend(content, xmlStrlen(content), fb); addMark(st, fb->utf8_current_index, STRONG_TYPE, NULL, fb); } xmlFree(content); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"emphasis")) { content = xmlNodeGetContent(cur->children); if (content) { int st = fb->utf8_current_index; bufferAppend(content, xmlStrlen(content), fb); addMark(st, fb->utf8_current_index, EMPHASIS_TYPE, NULL, fb); } xmlFree(content); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"a")) { parseLink(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"image")) { parseImage(doc, cur, fb); } cur = cur->next; } if (prop && (!xmlStrcmp(prop, (const xmlChar *)"italic"))) { addMark(start, fb->utf8_current_index, EMPHASIS_TYPE, NULL, fb); xmlFree(prop); } return; }
/* always use this when checking node->next or node->children * to avoid random XML_TEXT_NODEs from formatting * failure to do so will result in unexpected parsing errors */ inline xmlNode * xml_safenext(xmlNode *node) { xmlNode *node2 = node; if (!node2) return NULL; else if (xmlNodeIsText(node2)) return node2->next; return node2; }
static BtPersistence * bt_song_info_persistence_load (const GType type, const BtPersistence * const persistence, xmlNodePtr node, GError ** err, va_list var_args) { const BtSongInfo *const self = BT_SONG_INFO (persistence); GST_DEBUG ("PERSISTENCE::song-info"); g_assert (node); for (node = node->children; node; node = node->next) { if (!xmlNodeIsText (node)) { xmlNodePtr const child_node = node->children; if (child_node && xmlNodeIsText (child_node) && !xmlIsBlankNode (child_node)) { xmlChar *const elem = xmlNodeGetContent (child_node); if (elem) { const gchar *const property_name = (gchar *) node->name; GST_DEBUG (" \"%s\"=\"%s\"", property_name, elem); // depending on the name of the property, treat it's type if (!strncmp (property_name, "info", 4) || !strncmp (property_name, "name", 4) || !strncmp (property_name, "genre", 5) || !strncmp (property_name, "author", 6) || !strncmp (property_name, "create-dts", 10) || !strncmp (property_name, "change-dts", 10) ) { g_object_set ((gpointer) self, property_name, elem, NULL); } else if (!strncmp (property_name, "bpm", 3) || !strncmp (property_name, "tpb", 3) || !strncmp (property_name, "bars", 4)) { g_object_set ((gpointer) self, property_name, atol ((char *) elem), NULL); } xmlFree (elem); } } } } return BT_PERSISTENCE (persistence); }
static void gtodo_client_cleanup_doc (GTodoClient *cl) { xmlNodePtr level1, next1; level1 = cl->root->xmlChildrenNode; while(level1 != NULL){ xmlNodePtr level2, next2; next1 = level1->next; if(xmlNodeIsText(level1)) { xmlUnlinkNode(level1); xmlFreeNode(level1); } else { level2 = level1->xmlChildrenNode; while(level2 != NULL) { xmlNodePtr level3, next3; next2 = level2->next; if(xmlNodeIsText(level2)) { xmlUnlinkNode(level2); xmlFreeNode(level2); } else { level3 = level2->xmlChildrenNode; while (level3 != NULL) { // xmlNodePtr level4, next4; next3 = level3->next; if(xmlNodeIsText(level3)) { xmlUnlinkNode(level3); xmlFreeNode(level3); } level3 = next3; } } level2 = next2; } } level1 = next1; } }
static void parseBinary (xmlDocPtr doc, xmlNodePtr cur, FB2Content *fb) { xmlChar *content; xmlChar *prop; if(fb->num_binaries == BUF_SIZE-1) return; /* initialize new binary buffer */ fb->binaries[fb->num_binaries] = (FB2Binary *) malloc(sizeof(FB2Binary)); fb->binaries[fb->num_binaries]->buffer = (char *) malloc(BUF_SIZE); fb->binaries[fb->num_binaries]->buffer_size = BUF_SIZE; fb->binaries[fb->num_binaries+1] = NULL; fb->binaries[fb->num_binaries]->current_index = 0; fb->binaries[fb->num_binaries]->id[0] = '\0'; fb->binaries[fb->num_binaries]->content_type[0] = '\0'; /* id */ prop = xmlGetProp(cur, (const xmlChar *)"id"); if (prop) strncpy(fb->binaries[fb->num_binaries]->id, prop, BUF_SIZE); xmlFree(prop); /* content-type */ prop = xmlGetProp(cur, (const xmlChar *)"content-type"); if (prop) strncpy(fb->binaries[fb->num_binaries]->content_type, prop, BUF_SIZE); xmlFree(prop); cur = cur->children; while (cur != NULL) { if (xmlNodeIsText(cur)) { content = xmlNodeGetContent(cur); if (content) { bufferAppend(content, xmlStrlen(content), fb); } xmlFree(content); } cur = cur->next; } bufferAppend("\0", 1, fb); fb->num_binaries++; return; }
static gint plugin_ui_hook_construct (EPluginHook *hook, EPlugin *plugin, xmlNodePtr node) { EPluginUIHookPrivate *priv; priv = E_PLUGIN_UI_HOOK_GET_PRIVATE (hook); /* XXX The EPlugin should be a property of EPluginHookClass. * Then it could be passed directly to g_object_new() and * we wouldn't have to chain up here. */ /* Chain up to parent's construct() method. */ E_PLUGIN_HOOK_CLASS (parent_class)->construct (hook, plugin, node); for (node = node->children; node != NULL; node = node->next) { xmlNodePtr child; xmlBufferPtr buffer; const gchar *content; gchar *id; if (strcmp ((gchar *) node->name, "ui-manager") != 0) continue; id = e_plugin_xml_prop (node, "id"); if (id == NULL) { g_warning ("<ui-manager> requires 'id' property"); continue; } /* Extract the XML content below <ui-manager> */ buffer = xmlBufferCreate (); child = node->children; while (child != NULL && xmlNodeIsText (child)) child = child->next; if (child != NULL) xmlNodeDump (buffer, node->doc, child, 2, 1); content = (const gchar *) xmlBufferContent (buffer); g_hash_table_insert ( priv->ui_definitions, id, g_strdup (content)); xmlBufferFree (buffer); } return 0; }
/** * bt_persistence_load_hashtable: * @hashtable: (element-type utf8 utf8): a #GHashTable * @node: the list xml node * * Iterates over the xml-node and deserializes elements into the hashtable. * * Returns: %TRUE if all elements have been deserialized. */ gboolean bt_persistence_load_hashtable (GHashTable * hashtable, xmlNodePtr node) { xmlChar *key, *value; // iterate over children for (node = node->children; node; node = node->next) { if (!xmlNodeIsText (node) && !strncmp ((char *) node->name, "property\0", 9)) { key = xmlGetProp (node, XML_CHAR_PTR ("key")); value = xmlGetProp (node, XML_CHAR_PTR ("value")); //GST_DEBUG(" [%s] => [%s]",key,value); g_hash_table_insert (hashtable, key, value); // do not free, as the hastable now owns the memory //xmlFree(key);xmlFree(value); } } return TRUE; }
/** * rb_static_playlist_source_load_from_xml: * @source: an #RBStaticPlaylistSource * @node: XML node to load from * * Loads the playlist contents from the specified XML document node. */ void rb_static_playlist_source_load_from_xml (RBStaticPlaylistSource *source, xmlNodePtr node) { xmlNodePtr child; for (child = node->children; child; child = child->next) { xmlChar *location; if (xmlNodeIsText (child)) continue; if (xmlStrcmp (child->name, RB_PLAYLIST_LOCATION)) continue; location = xmlNodeGetContent (child); rb_static_playlist_source_add_location (source, (char *) location, -1); xmlFree (location); } }
static void parseEpigraph (xmlDocPtr doc, xmlNodePtr cur, FB2Content *fb) { xmlChar *content; cur = cur->children; while (cur != NULL) { if (xmlNodeIsText(cur)) { /* content = xmlNodeGetContent(cur); bufferAppend(content, xmlStrlen(content), fb); xmlFree(content); */ } else if (!xmlStrcmp(cur->name, (const xmlChar *)"cite")) { parseCite(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"poem")) { parsePoem(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"p")) { parseP(doc, cur, 1, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"empty-line")) { bufferAppend("\n", 1, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"text-author")) { content = xmlNodeGetContent(cur->children); if (content) { bufferAppend("\t", 1, fb); bufferAppend(content, xmlStrlen(content), fb); bufferAppend("\n", 1, fb); } xmlFree(content); } cur = cur->next; } return; }
/** * lgl_xml_paper_parse_papers_doc: * @papers_doc: libxml #xmlDocPtr tree, representing a papers definition file. * * Read paper definitions from a libxml #xmlDocPtr tree. * * Returns: a list of #lglPaper structures. * */ GList * lgl_xml_paper_parse_papers_doc (xmlDocPtr papers_doc) { GList *papers = NULL; xmlNodePtr root, node; lglPaper *paper; LIBXML_TEST_VERSION; root = xmlDocGetRootElement (papers_doc); if (!root || !root->name) { g_message ("\"%s\" is not a glabels paper file (no root node)", papers_doc->name); xmlFreeDoc (papers_doc); return papers; } if (!lgl_xml_is_node (root, "Glabels-paper-sizes")) { g_message ("\"%s\" is not a glabels paper file (wrong root node)", papers_doc->name); xmlFreeDoc (papers_doc); return papers; } for (node = root->xmlChildrenNode; node != NULL; node = node->next) { if (lgl_xml_is_node (node, "Paper-size")) { paper = lgl_xml_paper_parse_paper_node (node); papers = g_list_append (papers, paper); } else { if ( !xmlNodeIsText(node) ) { if (!lgl_xml_is_node (node, "comment")) { g_message ("bad node = \"%s\"",node->name); } } } } return papers; }
char* XmlParser::getTextByXPath(const char* xpathExpr) const { xmlXPathObjectPtr xpathObj = xmlXPathEvalExpression((const xmlChar *)xpathExpr, xpathCtx_); if (xpathObj == NULL || xpathObj->nodesetval == NULL || xpathObj->nodesetval->nodeTab == NULL) { xmlXPathFreeObject(xpathObj); return NULL; } //TODO:maybe it is not the first chid xmlNodePtr n = xpathObj->nodesetval->nodeTab[0]->children; char *str = NULL; if (xmlNodeIsText(n)) { if (n->content) { str = strdup((const char*)n->content); } } xmlXPathFreeObject(xpathObj); return str; }
static void populate_model_from_node (GvcSoundThemeChooser *chooser, GtkTreeModel *model, xmlNodePtr node) { xmlNodePtr child; xmlChar *filename; xmlChar *name; filename = NULL; name = xml_get_and_trim_names (node); for (child = node->children; child; child = child->next) { if (xmlNodeIsText (child)) { continue; } if (xmlStrcmp (child->name, GVC_SOUND_FILENAME) == 0) { filename = xmlNodeGetContent (child); } else if (xmlStrcmp (child->name, GVC_SOUND_NAME) == 0) { /* EH? should have been trimmed */ } } if (filename != NULL && name != NULL) { gtk_list_store_insert_with_values (GTK_LIST_STORE (model), NULL, G_MAXINT, ALERT_IDENTIFIER_COL, filename, ALERT_DISPLAY_COL, name, ALERT_SOUND_TYPE_COL, _("Built-in"), ALERT_ACTIVE_COL, FALSE, -1); } xmlFree (filename); xmlFree (name); }
static BtPersistence * bt_wavetable_persistence_load (const GType type, const BtPersistence * const persistence, xmlNodePtr node, GError ** err, va_list var_args) { const BtWavetable *const self = BT_WAVETABLE (persistence); xmlNodePtr child_node; GST_DEBUG ("PERSISTENCE::wavetable"); g_assert (node); for (child_node = node->children; child_node; child_node = child_node->next) { if ((!xmlNodeIsText (child_node)) && (!strncmp ((char *) child_node->name, "wave\0", 5))) { GError *err = NULL; BtWave *const wave = BT_WAVE (bt_persistence_load (BT_TYPE_WAVE, NULL, child_node, &err, "song", self->priv->song, NULL)); if (err != NULL) { // collect failed waves gchar *const name, *const uri; g_object_get (wave, "name", &name, "uri", &uri, NULL); gchar *const str = g_strdup_printf ("%s: %s", name, uri); bt_wavetable_remember_missing_wave (self, str); g_free (name); g_free (uri); GST_WARNING ("Can't create wavetable: %s", err->message); g_error_free (err); } g_object_unref (wave); } } return BT_PERSISTENCE (persistence); }
static void chatroom_manager_parse_chatroom (EmpathyChatroomManager *manager, xmlNodePtr node) { EmpathyChatroomManagerPriv *priv; EmpathyChatroom *chatroom; EmpathyAccount *account; xmlNodePtr child; gchar *str; gchar *name; gchar *room; gchar *account_id; gboolean auto_connect; priv = GET_PRIV (manager); /* default values. */ name = NULL; room = NULL; auto_connect = TRUE; account_id = NULL; for (child = node->children; child; child = child->next) { gchar *tag; if (xmlNodeIsText (child)) { continue; } tag = (gchar *) child->name; str = (gchar *) xmlNodeGetContent (child); if (strcmp (tag, "name") == 0) { name = g_strdup (str); } else if (strcmp (tag, "room") == 0) { room = g_strdup (str); } else if (strcmp (tag, "auto_connect") == 0) { if (strcmp (str, "yes") == 0) { auto_connect = TRUE; } else { auto_connect = FALSE; } } else if (strcmp (tag, "account") == 0) { account_id = g_strdup (str); } xmlFree (str); } account = empathy_account_manager_get_account (priv->account_manager, account_id); if (!account) { g_free (name); g_free (room); g_free (account_id); return; } chatroom = empathy_chatroom_new_full (account, room, name, auto_connect); empathy_chatroom_set_favorite (chatroom, TRUE); add_chatroom (manager, chatroom); g_signal_emit (manager, signals[CHATROOM_ADDED], 0, chatroom); g_free (name); g_free (room); g_free (account_id); }
XPFCapability* PluginOILFilter::CreateAttributeNode(xmlNodePtr pNode) { XPFCapability* pCap = NULL; wxString strName = CXMLUtils::ConvertToWXString(pNode->name); if (strName == _T("#text") || xmlNodeIsText(pNode)) { wxString str = CXMLUtils::ConvertToWXString(xmlNodeGetContent(pNode)); TRACEUSER("Phil", _T("CreateAttributeNode ignoring text %s\n"), (LPCTSTR)str); return(NULL); } XPFConvertType AsType = XPFCONVTYPE_UNKNOWN; BOOL bOK = GetConvertAsType(pNode, &AsType); if (!bOK) { TRACEUSER("Phil", _T("CreateAttributeNode GetConvertAsType failed\n")); return NULL; } if (strName == _T("Fill")) { XPFProp Shape = XPFP_UNKNOWN; bOK = GetXPFProp(pNode, _T("shape"), aFillShapes, &Shape); XPFProp Repeat = XPFP_UNKNOWN; bOK = GetXPFProp(pNode, _T("repeat"), aFillRepeats, &Repeat); XPFBOOL bMultistage = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("multistage"), &bMultistage); XPFProp Effect = XPFP_UNKNOWN; bOK = GetXPFProp(pNode, _T("effect"), aColourEffects, &Effect); XPFBOOL bProfile = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("profile"), &bProfile); XPFBOOL bContone = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("contone"), &bContone); pCap = new XPFCFill(AsType, Shape, Repeat, bMultistage, Effect, bProfile, bContone); } else if (strName == _T("FillTrans")) { XPFProp Shape = XPFP_UNKNOWN; bOK = GetXPFProp(pNode, _T("shape"), aFillShapes, &Shape); XPFProp Type = XPFP_UNKNOWN; bOK = GetXPFProp(pNode, _T("type"), aTransTypes, &Type); XPFProp Repeat = XPFP_UNKNOWN; bOK = GetXPFProp(pNode, _T("repeat"), aFillRepeats, &Repeat); XPFBOOL bProfile = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("profile"), &bProfile); pCap = new XPFCFillTrans(AsType, Shape, Type, Repeat, bProfile); } else if (strName == _T("Line")) { XPFBOOL bDash = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("dash"), &bDash); XPFBOOL bArrowhead = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("arrowhead"), &bArrowhead); XPFProp Cap = XPFP_UNKNOWN; bOK = GetXPFProp(pNode, _T("cap"), aLineCaps, &Cap); XPFProp Join = XPFP_UNKNOWN; bOK = GetXPFProp(pNode, _T("join"), aLineJoins, &Join); XPFBOOL bStroke = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("stroke"), &bStroke); XPFBOOL bBrush = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("brush"), &bBrush); pCap = new XPFCLine(AsType, bDash, bArrowhead, Cap, Join, bStroke, bBrush); } else if (strName == _T("LineTrans")) { XPFProp Type = XPFP_UNKNOWN; bOK = GetXPFProp(pNode, _T("type"), aTransTypes, &Type); pCap = new XPFCLineTrans(AsType, Type); } else if (strName == _T("Feather")) { pCap = new XPFCFeather(AsType); } else { ERROR1(NULL, _R(IDE_XPF_BADXML_UNEXPECTED_ATTRTYPE)); } xmlNodePtr pChild; pChild = pNode->children; XPFCapability* pLast = NULL; while (pChild) { XPFCapability* pCapNode = CreateAttributeNode(pChild); if (pCapNode) { // If we have a node then add it to the list // If we do not have a node already then set m_pObjects if (pLast) { pLast->SetNext(pCapNode); } else { pCap->SetChild(pCapNode); } pLast = pCapNode; } pChild = pChild->next; } return(pCap); }
XPFCapability* PluginOILFilter::CreateObjectNode(xmlNodePtr pNode) { XPFCapability* pCap = NULL; wxString strName = CXMLUtils::ConvertToWXString(pNode->name); if (strName == _T("#text") || xmlNodeIsText(pNode)) { wxString str = CXMLUtils::ConvertToWXString(xmlNodeGetContent(pNode)); TRACEUSER("Phil", _T("CreateObjectNode ignoring text %s\n"), (LPCTSTR)str); return(NULL); } XPFConvertType AsType = XPFCONVTYPE_UNKNOWN; BOOL bOK = GetConvertAsType(pNode, &AsType); if (!bOK) { TRACEUSER("Phil", _T("CreateObjectNode GetConvertAsType failed\n")); return NULL; } if (strName == _T("Layer")) { // Read the visible and locked attributes XPFBOOL bVisible = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("visible"), &bVisible); XPFBOOL bLocked = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("locked"), &bLocked); XPFBOOL bPrintable = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("printable"), &bPrintable); XPFBOOL bActive = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("active"), &bActive); XPFBOOL bBackground = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("background"), &bBackground); XPFBOOL bGuide = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("guide"), &bGuide); XPFProp ContentOnly = XPFP_UNKNOWN; bOK = GetXPFProp(pNode, _T("onlycontent"), aContentOnly, &ContentOnly); pCap = new XPFCLayer(AsType, bVisible, bLocked, bPrintable, bActive, bBackground, bGuide, ContentOnly); } else if (strName == _T("Contour")) { pCap = new XPFCContour(AsType); } else if (strName == _T("Shadow")) { // Read the type attribute XPFProp Type = XPFP_UNKNOWN; bOK = GetXPFProp(pNode, _T("type"), aShadowTypes, &Type); pCap = new XPFCShadow(AsType, Type); } else if (strName == _T("Bevel")) { // Read the type and side attributes XPFProp Type = XPFP_UNKNOWN; bOK = GetXPFProp(pNode, _T("type"), aBevelTypes, &Type); XPFProp Side = XPFP_UNKNOWN; bOK = GetXPFProp(pNode, _T("side"), aBevelSides, &Side); pCap = new XPFCBevel(AsType, Type, Side); } else if (strName == _T("Blend")) { // Read the effect, oncurve, posprofile and attrprofile attributes XPFProp Effect = XPFP_UNKNOWN; bOK = GetXPFProp(pNode, _T("effect"), aColourEffects, &Effect); XPFBOOL bOnCurve = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("oncurve"), &bOnCurve); XPFBOOL bObjProfile = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("posprofile"), &bObjProfile); XPFBOOL bAttrProfile = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("attrprofile"), &bAttrProfile); pCap = new XPFCBlend(AsType, Effect, bOnCurve, bObjProfile, bAttrProfile); } else if (strName == _T("Mould")) { // Read the as and type attributes XPFProp Type = XPFP_UNKNOWN; bOK = GetXPFProp(pNode, _T("type"), aMouldTypes, &Type); XPFBOOL bGradFill = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("gradfill"), &bGradFill); pCap = new XPFCMould(AsType, Type, bGradFill); } else if (strName == _T("Rectangle")) { // Read the as, rounded and complex attributes XPFBOOL bComplex = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("complex"), &bComplex); XPFBOOL bRounded = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("rounded"), &bRounded); XPFBOOL bStellated = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("stellated"), &bStellated); XPFBOOL bReformed = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("reformed"), &bReformed); pCap = new XPFCRectangle(AsType, bComplex, bRounded, bStellated, bReformed); } else if (strName == _T("Ellipse")) { // Read the as and complex attributes XPFBOOL bComplex = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("complex"), &bComplex); pCap = new XPFCEllipse(AsType, bComplex); } else if (strName == _T("Polygon")) { // Read the as, rounded, stellated and reformed attributes XPFBOOL bRounded = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("rounded"), &bRounded); XPFBOOL bStellated = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("stellated"), &bStellated); XPFBOOL bReformed = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("reformed"), &bReformed); pCap = new XPFCPolygon(AsType, bRounded, bStellated, bReformed); } else if (strName == _T("Bitmap")) { // Read the complex and contone attributes XPFBOOL bComplex = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("complex"), &bComplex); XPFBOOL bContone = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("contone"), &bContone); pCap = new XPFCBitmap(AsType, bComplex, bContone); } else if (strName == _T("Text")) { // Read the onpath, complex and plain attributes XPFBOOL bOnPath = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("onpath"), &bOnPath); XPFBOOL bComplex = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("complex"), &bComplex); XPFBOOL bPlain = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("plain"), &bPlain); XPFBOOL bAutoKern = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("autokern"), &bAutoKern); XPFBOOL bJustified = XPFB_UNKNOWN; bOK = GetXPFBOOL(pNode, _T("justified"), &bJustified); pCap = new XPFCText(AsType, bOnPath, bComplex, bPlain, bAutoKern, bJustified); } else if (strName == _T("ClipView")) { pCap = new XPFCClipView(AsType); } else if (strName == _T("BitmapEffect")) { pCap = new XPFCBitmapEffect(AsType); } else if (strName == _T("Feather")) { pCap = new XPFCFeather(AsType); } else { ERROR1(NULL, _R(IDE_XPF_BADXML_UNEXPECTED_OBJTYPE)); } xmlNodePtr pChild; pChild = pNode->children; XPFCapability* pLast = NULL; while (pChild) { XPFCapability* pCapNode = CreateObjectNode(pChild); if (pCapNode) { // If we have a node then add it to the list // If we do not have a node already then set m_pObjects if (pLast) { pLast->SetNext(pCapNode); } else { pCap->SetChild(pCapNode); } pLast = pCapNode; } pChild = pChild->next; } return(pCap); }
static int noit_console_config_show(noit_console_closure_t ncct, int argc, char **argv, noit_console_state_t *state, void *closure) { noit_hash_iter iter = NOIT_HASH_ITER_ZERO; const char *k; int klen; void *data; int i, cnt, titled = 0, cliplen = 0; const char *path = "", *basepath = NULL; char xpath[1024]; noit_conf_t_userdata_t *info = NULL; noit_hash_table *config; xmlXPathObjectPtr pobj = NULL; xmlXPathContextPtr xpath_ctxt = NULL, current_ctxt; xmlDocPtr master_config = NULL; xmlNodePtr node = NULL; noit_conf_xml_xpath(&master_config, &xpath_ctxt); if(argc > 1) { nc_printf(ncct, "too many arguments\n"); return -1; } info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA); if(info && info->path) path = basepath = info->path; if(!info && argc == 0) { nc_printf(ncct, "argument required when not in configuration mode\n"); return -1; } if(argc == 1) path = argv[0]; if(!basepath) basepath = path; /* { / } is a special case */ if(!strcmp(basepath, "/")) basepath = ""; if(!strcmp(path, "/")) path = ""; if(!master_config) { nc_printf(ncct, "no config\n"); return -1; } /* { / } is the only path that will end with a / * in XPath { / / * } means something _entirely different than { / * } * Ever notice how it is hard to describe xpath in C comments? */ /* We don't want to show the root node */ cliplen = strlen("/noit/"); /* If we are in configuration mode * and we are without an argument or the argument is absolute, * clip the current path off */ if(info && (argc == 0 || path[0] != '/')) cliplen += strlen(basepath); if(!path[0] || path[0] == '/') /* base only, or absolute path requested */ snprintf(xpath, sizeof(xpath), "/noit%s/@*", path); else snprintf(xpath, sizeof(xpath), "/noit%s/%s/@*", basepath, path); current_ctxt = xpath_ctxt; pobj = xmlXPathEval((xmlChar *)xpath, current_ctxt); if(!pobj || pobj->type != XPATH_NODESET) { nc_printf(ncct, "no such object\n"); goto bad; } cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); titled = 0; for(i=0; i<cnt; i++) { node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i); if(!strcmp((char *)node->name, "check")) continue; if(node->children && node->children == xmlGetLastChild(node) && xmlNodeIsText(node->children)) { if(!titled++) nc_printf(ncct, "== Section Settings ==\n"); nc_printf(ncct, "%s: %s\n", xmlGetNodePath(node) + cliplen, xmlXPathCastNodeToString(node->children)); } } xmlXPathFreeObject(pobj); /* Print out all the config settings */ if(!path[0] || path[0] == '/') /* base only, or absolute path requested */ snprintf(xpath, sizeof(xpath), "/noit%s", path); else snprintf(xpath, sizeof(xpath), "/noit%s/%s", basepath, path); pobj = xmlXPathEval((xmlChar *)xpath, current_ctxt); if(!pobj || pobj->type != XPATH_NODESET) { nc_printf(ncct, "no such object\n"); goto bad; } cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); if(cnt > 0) { node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, 0); titled = 0; config = noit_conf_get_hash(node, "config"); while(noit_hash_next(config, &iter, &k, &klen, &data)) { if(!titled++) nc_printf(ncct, "== Section [Aggregated] Config ==\n"); nc_printf(ncct, "config::%s: %s\n", k, (const char *)data); } noit_hash_destroy(config, free, free); free(config); } xmlXPathFreeObject(pobj); /* _shorten string_ turning last { / @ * } to { / * } */ if(!path[0] || path[0] == '/') /* base only, or absolute path requested */ snprintf(xpath, sizeof(xpath), "/noit%s/*", path); else snprintf(xpath, sizeof(xpath), "/noit%s/%s/*", basepath, path); pobj = xmlXPathEval((xmlChar *)xpath, current_ctxt); if(!pobj || pobj->type != XPATH_NODESET) { nc_printf(ncct, "no such object\n"); goto bad; } cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); titled = 0; for(i=0; i<cnt; i++) { node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i); if(!strcmp((char *)node->name, "check")) continue; if(!strcmp((char *)node->name, "filterset")) continue; if(!strcmp((char *)xmlGetNodePath(node) + cliplen, "config")) continue; if(!(node->children && node->children == xmlGetLastChild(node) && xmlNodeIsText(node->children))) { if(!titled++) nc_printf(ncct, "== Subsections ==\n"); nc_printf(ncct, "%s\n", xmlGetNodePath(node) + cliplen); } } titled = 0; for(i=0; i<cnt; i++) { node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i); if(!strcmp((char *)node->name, "filterset")) { xmlAttr *attr; char *filter_name = NULL; for(attr=node->properties; attr; attr = attr->next) { if(!strcmp((char *)attr->name, "name")) filter_name = (char *)xmlXPathCastNodeToString(attr->children); } if(filter_name) { nc_printf(ncct, "filterset[@name=\"%s\"]\n", filter_name); xmlFree(filter_name); } else nc_printf(ncct, "fitlerset\n"); } else if(!strcmp((char *)node->name, "check")) { int busted = 1; xmlAttr *attr; char *uuid_str = "undefined"; if(!titled++) nc_printf(ncct, "== Checks ==\n"); for(attr=node->properties; attr; attr = attr->next) { if(!strcmp((char *)attr->name, "uuid")) uuid_str = (char *)xmlXPathCastNodeToString(attr->children); } if(uuid_str) { uuid_t checkid; nc_printf(ncct, "check[@uuid=\"%s\"] ", uuid_str); if(uuid_parse(uuid_str, checkid) == 0) { noit_check_t *check; check = noit_poller_lookup(checkid); if(check) { busted = 0; nc_printf(ncct, "%s`%s`%s", check->target, check->module, check->name); } } } else nc_printf(ncct, "%s ", xmlGetNodePath(node) + cliplen); if(busted) nc_printf(ncct, "[check not in running system]"); nc_write(ncct, "\n", 1); } } xmlXPathFreeObject(pobj); return 0; bad: if(pobj) xmlXPathFreeObject(pobj); return -1; }
GtkWidget * action_detail( xmlNode *action) { char *name = NULL; xmlNode *cur = NULL; GtkWidget *text; xmlNode *child = NULL; int flag = FALSE; cur = action; text = gtk_text_new (NULL, NULL); gtk_widget_set_name (text, "text"); gtk_widget_ref (text); gtk_object_set_data_full (GTK_OBJECT(Peos), "text", text, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (text); GTK_WIDGET_UNSET_FLAGS (text, GTK_CAN_FOCUS); if (strcmp(cur->name, "action") == 0) { //gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL, "ACTION : ", -1); name = xmlGetProp(action, "name"); gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL, "\t\t\t\t\t\t\t\t\t\t\t", -1); gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL, name, -1); gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL,"\n\nState: ", -1); name = xmlGetProp(action, "state"); gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL,name, -1); gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL,"\n", -1); for ( cur = action->children; cur; cur = cur->next) { if ( !xmlNodeIsText(cur) && !strcmp(cur->name, "script")) { for ( child = action->children; child; child = child->next) { if(!xmlNodeIsText(child) && !strcmp(child->name, "req_resource")) { gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL,"\nRequired Resources: ", -1); name = xmlGetProp(child, "name"); gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL,name, -1); /* gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL," Value : ", -1); name = xmlGetProp(child, "value"); gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL,name, -1); gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL," Qualifier: ", -1); name = xmlGetProp(child, "qualifier"); gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL,name, -1); */ gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL,"\n", -1); } if(!xmlNodeIsText(child) && !strcmp(child->name, "prov_resource")) { flag = TRUE; gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL,"\nProvided Resources: ", -1); name = xmlGetProp(child, "name"); gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL,name, -1); /* gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL," Value : ", -1); name = xmlGetProp(child, "value"); gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL,name, -1); gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL," Qualifier: ", -1); name = xmlGetProp(child, "qualifier"); gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL,name, -1); */ gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL,"\n", -1); } } } } if(flag == FALSE) gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL,"\nNo Resources Provided \n", -1); gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL,"\nScript: ", -1); gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL,xmlNodeGetContent(action), -1); } else if ( strcmp(cur->name, "action") != 0) { gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL,"ACTION : ", -1); gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL,action->name, -1); } return text; }
/** * print_xpath_nodes: * nodes: the nodes set. * output: the output file handle. * * Print the node content to the file */ static int print_xpath_nodes(xmlDocPtr doc, xmlNodeSetPtr nodes, FILE *output) { int ret = 0; int size; int i; xmlNodePtr cur; xmlChar *node_child_value_string = NULL; assert(output); size = (nodes) ? nodes->nodeNr : 0; for (i = 0; i < size; ++i) { assert(nodes->nodeTab[i]); if (nodes->nodeTab[i]->type == XML_NAMESPACE_DECL) { fprintf(stderr, "ERR:%s\n", "This executable does not support xml namespacing\n"); ret = -1; goto end; } else if (nodes->nodeTab[i]->type == XML_ELEMENT_NODE) { cur = nodes->nodeTab[i]; if (xmlChildElementCount(cur) == 0) { if (xmlNodeIsText(cur->children)) { node_child_value_string = xmlNodeListGetString(doc, cur->children, 1); if (node_exist) { fprintf(output, "true\n"); } else if (opt_verbose) { fprintf(output, "%s;%s;\n", cur->name, node_child_value_string); } else { fprintf(output, "%s\n", node_child_value_string); } xmlFree(node_child_value_string); } else { /* We don't want to print non-final element */ if (node_exist) { fprintf(output, "true\n"); } else { fprintf(stderr, "ERR:%s\n", "Xpath expression return non-final xml element"); ret = -1; goto end; } } } else { if (node_exist) { fprintf(output, "true\n"); } else { /* We don't want to print non-final element */ fprintf(stderr, "ERR:%s\n", "Xpath expression return non-final xml element"); ret = -1; goto end; } } } else { cur = nodes->nodeTab[i]; if (node_exist) { fprintf(output, "true\n"); } else if (opt_verbose) { fprintf(output, "%s;%s;\n", cur->parent->name, cur->content); } else { fprintf(output, "%s\n", cur->content); } } } /* Command Success */ ret = 0; end: return ret; }
static void chatroom_manager_parse_chatroom (EmpathyChatroomManager *manager, xmlNodePtr node) { EmpathyChatroom *chatroom = NULL; TpAccount *account; xmlNodePtr child; gchar *str; gchar *name; gchar *room; gchar *account_id; gboolean auto_connect; gboolean always_urgent; EmpathyClientFactory *factory; GError *error = NULL; /* default values. */ name = NULL; room = NULL; auto_connect = TRUE; always_urgent = FALSE; account_id = NULL; for (child = node->children; child; child = child->next) { gchar *tag; if (xmlNodeIsText (child)) continue; tag = (gchar *) child->name; str = (gchar *) xmlNodeGetContent (child); if (strcmp (tag, "name") == 0) { name = g_strdup (str); } else if (strcmp (tag, "room") == 0) { room = g_strdup (str); } else if (strcmp (tag, "auto_connect") == 0) { if (strcmp (str, "yes") == 0) auto_connect = TRUE; else auto_connect = FALSE; } else if (!tp_strdiff (tag, "always_urgent")) { if (strcmp (str, "yes") == 0) always_urgent = TRUE; else always_urgent = FALSE; } else if (strcmp (tag, "account") == 0) { account_id = g_strdup (str); } xmlFree (str); } /* account has to be a valid Account object path */ if (!tp_dbus_check_valid_object_path (account_id, NULL) || !g_str_has_prefix (account_id, TP_ACCOUNT_OBJECT_PATH_BASE)) goto out; factory = empathy_client_factory_dup (); account = tp_simple_client_factory_ensure_account ( TP_SIMPLE_CLIENT_FACTORY (factory), account_id, NULL, &error); g_object_unref (factory); if (account == NULL) { DEBUG ("Failed to create account: %s", error->message); g_error_free (error); g_free (name); g_free (room); g_free (account_id); return; } chatroom = empathy_chatroom_new_full (account, room, name, auto_connect); empathy_chatroom_set_favorite (chatroom, TRUE); empathy_chatroom_set_always_urgent (chatroom, always_urgent); add_chatroom (manager, chatroom); g_signal_emit (manager, signals[CHATROOM_ADDED], 0, chatroom); out: g_free (name); g_free (room); g_free (account_id); tp_clear_object (&chatroom); }
glLabel *gl_xml_label_04_parse (xmlNodePtr root, glXMLLabelStatus *status) { glLabel *label; xmlNodePtr node; GObject *object; gboolean rotate_flag; gl_debug (DEBUG_XML, "START"); *status = XML_LABEL_OK; if (!xmlStrEqual (root->name, (xmlChar *)"Label")) { g_message (_("Bad root node = \"%s\""), root->name); *status = XML_LABEL_ERROR_OPEN_PARSE; return NULL; } label = GL_LABEL (gl_label_new ()); rotate_flag = lgl_xml_get_prop_boolean (root, "rotate", FALSE); gl_label_set_rotate_flag (label, rotate_flag, FALSE); for (node = root->xmlChildrenNode; node != NULL; node = node->next) { gl_debug (DEBUG_XML, "node name = \"%s\"", node->name); if (!xmlNodeIsText (node)) { if (xmlStrEqual (node->name, (xmlChar *)"Media_Type")) { if (!xml04_parse_media_description (node, label)) { *status = XML_LABEL_UNKNOWN_MEDIA; } } else if (xmlStrEqual (node->name, (xmlChar *)"Text")) { object = gl_label_text_new (label, FALSE); xml04_parse_object (node, GL_LABEL_OBJECT(object)); xml04_parse_text_props (node, GL_LABEL_TEXT(object)); } else if (xmlStrEqual (node->name, (xmlChar *)"Box")) { object = gl_label_box_new (label, FALSE); xml04_parse_object (node, GL_LABEL_OBJECT(object)); xml04_parse_box_props (node, GL_LABEL_BOX(object)); } else if (xmlStrEqual (node->name, (xmlChar *)"Line")) { object = gl_label_line_new (label, FALSE); xml04_parse_object (node, GL_LABEL_OBJECT(object)); xml04_parse_line_props (node, GL_LABEL_LINE(object)); } else if (xmlStrEqual (node->name, (xmlChar *)"Ellipse")) { object = gl_label_ellipse_new (label, FALSE); xml04_parse_object (node, GL_LABEL_OBJECT(object)); xml04_parse_ellipse_props (node, GL_LABEL_ELLIPSE(object)); } else if (xmlStrEqual (node->name, (xmlChar *)"Image")) { object = gl_label_image_new (label, FALSE); xml04_parse_object (node, GL_LABEL_OBJECT(object)); xml04_parse_image_props (node, GL_LABEL_IMAGE(object)); } else if (xmlStrEqual (node->name, (xmlChar *)"Barcode")) { object = gl_label_barcode_new (label, FALSE); xml04_parse_object (node, GL_LABEL_OBJECT(object)); xml04_parse_barcode_props (node, GL_LABEL_BARCODE(object)); } else if (xmlStrEqual (node->name, (xmlChar *)"Merge_Properties")) { xml04_parse_merge_properties (node, label); } else { g_message (_("bad node = \"%s\""), node->name); } } } gl_debug (DEBUG_XML, "END"); return label; }
/** Checks whether @a n has only allowed attrbutes and attr contents, * as well as only children of type TEXT * * @arg attrs list of allowed attribute names * @arg attr_contents list of allowed attribute contents * (if an entry is NULL, any contetn is allowed) */ gboolean has_only_text_children_and_allowed_attrs(const xmlNodePtr n, const char **attrs, const char **attr_contents) { g_return_val_if_fail(n, FALSE); // elements may have only the mentioned attributes if(n->type==XML_ELEMENT_NODE) { //g_debug("checking elem '%s'...", n->name); // if there are attributes if(n->properties) { g_debug("checking element with attrs... "); // if there are no attributes allowed if(!attrs) return FALSE; g_debug("certain attrs are allowed. "); // for all attributes of the element xmlAttr *nattrs = n->properties; while(nattrs) { g_return_val_if_fail(nattrs->name, FALSE); // check whether attribute is in list of allowed attribute names gboolean allowed = FALSE; const char **attr = attrs; const char **attr_content = attr_contents; xmlChar *attr_value = xmlNodeGetContent(nattrs->children); g_debug("element attr '%s': value='%s'", nattrs->name, attr_value); while(*attr) { // if allowed node exists g_debug("checking allowed attr '%s': attr_content='%s' ", *attr, *attr_content); if(!strcmp((char *) nattrs->name, (char *) *attr) && (!attr_content || !strcmp((char *) attr_value, (char *) *attr_content))) { allowed = TRUE; break; } attr++; if(attr_content) attr_content++; } g_debug("%i ", allowed); xmlFree(attr_value); if(!allowed) return FALSE; nattrs = nattrs->next; } } //g_debug("elem passed allowed attr check.\n"); } // if we reach here, element has only allowed attributes: // check that it has only text children xmlNodePtr n2 = n->children; while(n2) { if(!xmlNodeIsText(n2)) return FALSE; g_assert(n2->children == NULL); n2 = n2->next; } return TRUE; }
static void parseLink (xmlDocPtr doc, xmlNodePtr cur, FB2Content *fb) { xmlChar *content; xmlChar *href_prop, *note_prop; int start = fb->utf8_current_index; /* id */ href_prop = xmlGetProp(cur, (const xmlChar *)"href"); /* type="note" */ note_prop = xmlGetProp(cur, (const xmlChar *)"type"); if (note_prop && (!xmlStrcmp(note_prop, (const xmlChar *)"note"))) bufferAppend("[", 1, fb); cur = cur->children; /*bufferAppend("[", 1, fb);*/ while (cur != NULL) { if (xmlNodeIsText(cur)) { content = xmlNodeGetContent(cur); if (content) bufferAppend(content, xmlStrlen(content), fb); xmlFree(content); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"style")) { parseStyle(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"strong")) { content = xmlNodeGetContent(cur->children); if (content) { int st = fb->utf8_current_index; bufferAppend(content, xmlStrlen(content), fb); addMark(st, fb->utf8_current_index, STRONG_TYPE, NULL, fb); } xmlFree(content); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"emphasis")) { content = xmlNodeGetContent(cur->children); if (content) { int st = fb->utf8_current_index; bufferAppend(content, xmlStrlen(content), fb); addMark(st, fb->utf8_current_index, EMPHASIS_TYPE, NULL, fb); } xmlFree(content); } cur = cur->next; } if (href_prop) { if (note_prop && (!xmlStrcmp(note_prop, (const xmlChar *)"note"))) { bufferAppend("]", 1, fb); addMark(start, fb->utf8_current_index, NOTE_TYPE, href_prop, fb); xmlFree(note_prop); } else { addMark(start, fb->utf8_current_index, LINK_TYPE, href_prop, fb); } xmlFree(href_prop); } return; }
BOOL PluginOILFilter::Init( xmlNode* pFilterNode ) { // This would look a lot neater using functions from xmlutils.h m_InternalName = CXMLUtils::ConvertToWXString(xmlGetProp(pFilterNode, (xmlChar*)"name")); xmlNodePtr pChild = pFilterNode->children; // We will loop round until we run out of child elements // If an element has already been parsed then an error should be indicated while (pChild) { wxString strChildName = CXMLUtils::ConvertToWXString(pChild->name); if (strChildName == _T("#text") || xmlNodeIsText(pChild)) { // ignore it } else if (strChildName == _T("DisplayName")) { xmlChar* pStr = xmlNodeListGetString(pChild->doc, pChild->xmlChildrenNode, 1); wxString sTemp = CXMLUtils::ConvertToWXString(pStr); FilterName = sTemp; xmlFree(pStr); } else if (strChildName == _T("Extensions")) { xmlChar* pStr = xmlNodeListGetString(pChild->doc, pChild->xmlChildrenNode, 1); wxString sTemp = CXMLUtils::ConvertToWXString(pStr); FilterExt = sTemp; xmlFree(pStr); } else if (strChildName == _T("CanImport")) { xmlChar* pStr = xmlNodeListGetString(pChild->doc, pChild->xmlChildrenNode, 1); m_CanImport = CXMLUtils::ConvertToWXString(pStr); xmlFree(pStr); } else if (strChildName == _T("DoImport")) { xmlChar* pStr = xmlNodeListGetString(pChild->doc, pChild->xmlChildrenNode, 1); m_DoImport = CXMLUtils::ConvertToWXString(pStr); xmlFree(pStr); } else if (strChildName == _T("PrepareExport")) { xmlChar* pStr = xmlNodeListGetString(pChild->doc, pChild->xmlChildrenNode, 1); m_PrepareExport = CXMLUtils::ConvertToWXString(pStr); xmlFree(pStr); } else if (strChildName == _T("DoExport")) { xmlChar* pStr = xmlNodeListGetString(pChild->doc, pChild->xmlChildrenNode, 1); m_DoExport = CXMLUtils::ConvertToWXString(pStr); xmlFree(pStr); } else { TRACEUSER("Gerry", _T("Ignoring '%s' element"), strChildName.c_str()); // ERROR1(FALSE, _R(IDE_XPF_BADXML)); } pChild = pChild->next; } // This should be set to some sensible path but I've hardcoded it for now // We should change to making ~/.XaraLX into a directory and store the main config // file and these filter config files in there m_XMLFile.AssignHomeDir(); m_XMLFile.AppendDir(_T(".XaraLXFilters")); m_XMLFile.Mkdir(0777, wxPATH_MKDIR_FULL); m_XMLFile.SetName(m_InternalName); m_XMLFile.SetExt(_T("xml")); m_bImport = !(m_DoImport.IsEmpty()); m_bExport = !(m_DoExport.IsEmpty()); return(m_bImport || m_bExport); // If it doesn't do either then it isn't a filter }
BOOL PluginOILFilter::BuildCapabilityTree(wxString strXmlFilename, CapabilityTree* pCapTree) { // First we need to load the XML into an XML DOM object // Set Parser flags here? // hRes = pDoc->setProperty(CComBSTR(_T("SelectionLanguage")), CComVariant(_T("XPath"))); // hRes = pDoc->put_async(VARIANT_FALSE); // hRes = pDoc->put_preserveWhiteSpace(VARIANT_TRUE); // hRes = pDoc->put_validateOnParse(VARIANT_FALSE); // hRes = pDoc->put_resolveExternals(VARIANT_FALSE); BOOL bOK = TRUE; xmlDocPtr doc; // If string param contains xml (like original Windows version) // wxCharBuffer buf = strXML.mb_str(wxConvUTF8); // doc = xmlParseDoc((const xmlChar*)buf.data()); // buf will be deallocated when it goes out of scope // If string param gives xml filename (like new LX version) wxCharBuffer buf = strXmlFilename.ToAscii(); doc = xmlParseFile(buf.data()); // buf will be deallocated when it goes out of scope #if _DEBUG if (doc==NULL) doc = xmlParseFile("/tmp/XaraLX/capstest.xml"); #endif ERROR1IF(doc==NULL, FALSE, _R(IDE_XPF_BADXML)); // The name of the root element should be XPFilterConfig xmlNodePtr node = xmlDocGetRootElement(doc); wxString strName = CXMLUtils::ConvertToWXString(node->name); if (strName!=_T("XPFilterConfig")) ERROR1(FALSE, _R(IDE_XPF_BADXML)); xmlNodePtr pChild = node->children; INT32 Phase =0; // There are 7 phases to the parsing // We will loop round until we run out of child elements // After parsing a node the phase counter will be set to the phase just parsed // If an element should have already been parsed (using the phase counter) // then an error will be indicated while (pChild && bOK) { wxString strChildName = CXMLUtils::ConvertToWXString(pChild->name); if (strChildName == _T("#text") || xmlNodeIsText(pChild)) { // ignore it } else if (strChildName == _T("Private")) { if (Phase > 0) { ERROR1(FALSE, _R(IDE_XPF_BADXML_PHASE0)); } // Ignore the entire element Phase = 1; } else if (strChildName == _T("Options")) { if (Phase > 1) { ERROR1(FALSE, _R(IDE_XPF_BADXML_PHASE1)); } bOK = ReadOptions(pChild, pCapTree); // Read the options attributes Phase = 2; } else if (strChildName == _T("Rasterise")) { if (Phase > 2) { ERROR1(FALSE, _R(IDE_XPF_BADXML_PHASE2)); } bOK = ReadRasterise(pChild, pCapTree); // Read the dpi and alpha attributes Phase = 3; } else if (strChildName == _T("Spread")) { if (Phase > 3) { ERROR1(FALSE, _R(IDE_XPF_BADXML_PHASE3)); } bOK = ReadSpread(pChild, pCapTree); // Read the as attribute Phase = 4; } else if (strChildName == _T("Objects")) { if (Phase > 4) { ERROR1(FALSE, _R(IDE_XPF_BADXML_PHASE4)); } bOK = ReadObjects(pChild, pCapTree); // Build the tree of XPFCapability derived objects Phase = 5; } else if (strChildName == _T("Attributes")) { if (Phase > 5) { ERROR1(FALSE, _R(IDE_XPF_BADXML_PHASE5)); } bOK = ReadAttributes(pChild, pCapTree); // Build the tree of XPFCapability derived objects Phase = 6; } else if (strChildName == _T("Colour")) { if (Phase > 6) { ERROR1(FALSE, _R(IDE_XPF_BADXML_PHASE6)); } bOK = ReadColour(pChild, pCapTree); // Build the tree of XPFColour objects Phase = 7; } else { ERROR1(FALSE, _R(IDE_XPF_BADXML_UNEXPECTED_PHASE)); } pChild = pChild->next; } xmlFreeDoc(doc); return bOK; }
/** * xml_reader_read_start_element: * @reader: a #XmlReader * @element_name: the name of the element to position the cursor on * * Moves the internal cursor to the first element named @element_name * inside the XML document object model. * * For instance, this example will find the <book> element and * iterate over its children "author" and "copyright" and retrieve * their value: * * |[ * gchar *author, *title; * * xml_reader_read_start_element (reader, "book"); * xml_reader_read_start_element (reader, "author"); * author = g_strdup (xml_reader_get_element_value (reader)); * xml_reader_read_end_element (reader); * xml_reader_read_start_element (reader, "title"); * title = g_strdup (xml_reader_get_element_value (reader)); * xml_reader_read_end_element (reader); * xml_reader_read_end_element (reader); * * g_print ("The author of the book '%s' is %s\n", author, title); * g_free (author); * g_free (title); * ]| * * Return value: %TRUE if the cursor positioning was successful */ gboolean xml_reader_read_start_element (XmlReader *reader, const gchar *element_name) { XmlReaderPrivate *priv; xmlNodePtr cursor, node; g_return_val_if_fail (XML_IS_READER (reader), FALSE); g_return_val_if_fail (element_name != NULL, FALSE); if (xml_reader_get_error (reader, NULL)) return FALSE; priv = reader->priv; cursor = priv->node_cursor; if (!cursor) cursor = priv->current_doc->xmlRootNode; else cursor = cursor->xmlChildrenNode; for (node = cursor; node != NULL; node = node->next) { if (node->type == XML_ELEMENT_NODE && node->name != NULL && strcmp (XML_TO_CHAR (node->name), element_name) == 0) { xmlNodePtr child; priv->parent = priv->node_cursor; priv->node_cursor = node; priv->depth += 1; /* preload the text, if any */ child = priv->node_cursor->xmlChildrenNode; if (child && xmlNodeIsText (child)) { if (priv->cursor_value) xmlFree (priv->cursor_value); priv->cursor_value = xmlNodeGetContent (child); } /* unset the attributes cache */ priv->attr_cursor = priv->node_cursor->properties; if (priv->attr_value) { xmlFree (priv->attr_value); priv->attr_value = NULL; } return TRUE; } } priv->error_state = TRUE; priv->last_error = XML_READER_ERROR_UNKNOWN_NODE; priv->parent = priv->node_cursor; if (!priv->parent) priv->parent = priv->current_doc->xmlRootNode; priv->node_cursor = NULL; priv->attr_cursor = NULL; return FALSE; }