Beispiel #1
0
queryFavouriteFolder::queryFavouriteFolder(xmlTextReaderPtr reader, wxString title) : queryFavouriteItem(title, wxT(""))
{
	id = -2;

	// Element of type <foo />, meaning empty folder
	if (xmlTextReaderIsEmptyElement(reader))
		return;

	while (xmlTextReaderRead(reader))
	{
		int type = xmlTextReaderNodeType(reader);

		if (type == 15)
			return; // Close on parent element
		if (xmlTextReaderNodeType(reader) != 1)
			continue; // Any unknown element type

		wxString nodename = WXSTRING_FROM_XML(xmlTextReaderConstName(reader));

		xmlChar *ctitle = xmlTextReaderGetAttribute(reader, XML_STR("title"));
		if (!ctitle)
			continue; // We ignore nodes without title
		wxString title = WXSTRING_FROM_XML(ctitle);
		xmlFree(ctitle);

		if (nodename == wxT("favourite"))
		{
			xmlChar *cont = xmlTextReaderReadString(reader);
			if (!cont)
				continue; // No contents, so ignore node

			favourites.Add(new queryFavouriteItem(title, WXSTRING_FROM_XML(cont)));
			xmlFree(cont);
			SkipToEndElement(reader);
		}
		else if (nodename == wxT("folder"))
		{
			favourites.Add(new queryFavouriteFolder(reader, title));
		}
	}
}
Beispiel #2
0
queryMacroList::queryMacroList(xmlTextReaderPtr reader)
{
	// Element of type <foo />, meaning empty folder
	if (xmlTextReaderIsEmptyElement(reader))
		return;

	while (xmlTextReaderRead(reader))
	{
		int type = xmlTextReaderNodeType(reader);

		if (type == 15)
			return; // Close on parent element
		if (xmlTextReaderNodeType(reader) != 1)
			continue; // Any unknown element type

		wxString nodename = WXSTRING_FROM_XML(xmlTextReaderConstName(reader));

		xmlChar *ckey = xmlTextReaderGetAttribute(reader, XML_STR("key"));
		if (!ckey)
			continue;
		wxString key = WXSTRING_FROM_XML(ckey);
		xmlFree(ckey);

		xmlChar *cname = xmlTextReaderGetAttribute(reader, XML_STR("name"));
		if (!cname)
			continue;
		wxString name = WXSTRING_FROM_XML(cname);
		xmlFree(cname);

		if (nodename == wxT("macro"))
		{
			xmlChar *cquery = xmlTextReaderReadString(reader);
			if (!cquery)
				continue;
			wxString query = WXSTRING_FROM_XML(cquery);
			xmlFree(cquery);
			macros.Add(new queryMacroItem(key, name, query));
			SkipToEndElement(reader);
		}
	}
}
Beispiel #3
0
wxString frmReport::XslProcessReport(const wxString &xml, const wxString &xsl)
{
	xmlChar *output = 0;
	xmlDocPtr ssDoc = 0, xmlDoc = 0, resDoc = 0;
	xsltStylesheetPtr ssPtr = 0;
	int length;

	wxBeginBusyCursor();

	// Apply the stylesheet
	xmlSubstituteEntitiesDefault (1); // Substitute entities
	xmlLoadExtDtdDefaultValue = 1; // Load external entities

	// Parse the stylesheet
	ssDoc = xmlParseDoc(XML_FROM_WXSTRING(xsl));
	if (!ssDoc)
	{
		wxEndBusyCursor();
		wxLogError(_("Failed to parse the XML stylesheet!"));
		goto cleanup;
	}

	ssPtr = xsltParseStylesheetDoc(ssDoc);
	if (!ssPtr)
	{
		wxEndBusyCursor();
		wxLogError(_("Failed to parse the XSL stylesheet!"));
		goto cleanup;
	}

	// Parse the data
	xmlDoc = xmlParseDoc(XML_FROM_WXSTRING(xml));
	if (!xmlDoc)
	{
		wxEndBusyCursor();
		wxLogError(_("Failed to parse the XML document!"));
		goto cleanup;
	}

	// Apply the stylesheet
	resDoc = xsltApplyStylesheet(ssPtr, xmlDoc, NULL);
	if (!resDoc)
	{
		wxEndBusyCursor();
		wxLogError(_("Failed to apply the XSL stylesheet to the XML document!"));
		goto cleanup;
	}

	// Get the result
	xsltSaveResultToString (&output, &length, resDoc, ssPtr);
	if (!resDoc)
	{
		wxEndBusyCursor();
		wxLogError(_("Failed to read the processed document!"));
		goto cleanup;
	}

cleanup:

	// Cleanup
	if (resDoc)
		xmlFreeDoc(resDoc);

	if (xmlDoc)
		xmlFreeDoc(xmlDoc);

	if (ssPtr)
		xsltFreeStylesheet(ssPtr);

	// This crashes - dunno why :-(
	// if (ssDoc)
	//  xmlFreeDoc(ssDoc);

	xsltCleanupGlobals();

	wxEndBusyCursor();

	if (output)
		return WXSTRING_FROM_XML(output);
	else
		return wxEmptyString;
}