void FmncQPrsList::writeXML( xmlTextWriter* wr , string difftag , bool jnumattr , bool shorttags ) { if (difftag.length() == 0) difftag = "FmncQPrsList"; xmlTextWriterStartElement(wr, BAD_CAST difftag.c_str()); if (jnumattr) xmlTextWriterWriteAttribute(wr, BAD_CAST "jnum", BAD_CAST to_string(jnum).c_str()); if (shorttags) { writeString(wr, "tit", Title); writeString(wr, "fnm", Firstname); writeString(wr, "lnm", Lastname); writeString(wr, "grp", stubGrp); writeString(wr, "own", stubOwn); writeString(wr, "org", stubRefFmncMOrg); writeString(wr, "adr", stubRefFmncMAddress); writeString(wr, "sex", srefIxVSex); writeString(wr, "sex2", titIxVSex); writeString(wr, "tel", Tel); writeString(wr, "eml", Eml); } else { writeString(wr, "Title", Title); writeString(wr, "Firstname", Firstname); writeString(wr, "Lastname", Lastname); writeString(wr, "stubGrp", stubGrp); writeString(wr, "stubOwn", stubOwn); writeString(wr, "stubRefFmncMOrg", stubRefFmncMOrg); writeString(wr, "stubRefFmncMAddress", stubRefFmncMAddress); writeString(wr, "srefIxVSex", srefIxVSex); writeString(wr, "titIxVSex", titIxVSex); writeString(wr, "Tel", Tel); writeString(wr, "Eml", Eml); }; xmlTextWriterEndElement(wr); };
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); } }
void OpenDocument::generate_styles_xml(bool right_to_left) // This generates the file "styles.xml" in the OpenDocument. { // Start the new xml document. xmlBufferPtr buffer = xmlBufferCreate(); xmlTextWriterPtr writer = xmlNewTextWriterMemory(buffer, 0); xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL); xmlTextWriterSetIndent(writer, 1); xmlTextWriterStartElement(writer, BAD_CAST "office:document-styles"); xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:office", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:office:1.0"); xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:style", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:style:1.0"); xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:text", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:text:1.0"); xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:table", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:table:1.0"); xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:draw", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"); xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:fo", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"); xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:xlink", BAD_CAST "http://www.w3.org/1999/xlink"); xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:dc", BAD_CAST "http://purl.org/dc/elements/1.1/"); xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:meta", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:meta:1.0"); xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:number", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"); xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:svg", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"); xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:chart", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:chart:1.0"); xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:dr3d", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"); xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:math", BAD_CAST "http://www.w3.org/1998/Math/MathML"); xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:form", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:form:1.0"); xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:script", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:script:1.0"); xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:ooo", BAD_CAST "http://openoffice.org/2004/office"); xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:ooow", BAD_CAST "http://openoffice.org/2004/writer"); xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:oooc", BAD_CAST "http://openoffice.org/2004/calc"); xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:dom", BAD_CAST "http://www.w3.org/2001/xml-events"); xmlTextWriterWriteAttribute(writer, BAD_CAST "office:version", BAD_CAST "1.0"); // Font face declarations. xmlTextWriterStartElement(writer, BAD_CAST "office:font-face-decls"); xmlTextWriterEndElement(writer); // Styles. xmlTextWriterStartElement(writer, BAD_CAST "office:styles"); generate_styles(writer); xmlTextWriterEndElement(writer); // Automatic styles. xmlTextWriterStartElement(writer, BAD_CAST "office:automatic-styles"); xmlTextWriterStartElement(writer, BAD_CAST "style:page-layout"); xmlTextWriterWriteAttribute(writer, BAD_CAST "style:name", BAD_CAST "pm1"); xmlTextWriterStartElement(writer, BAD_CAST "style:page-layout-properties"); extern Settings *settings; xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:page-width", "%.2fcm", settings->genconfig.paper_width_get()); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:page-height", "%.2fcm", settings->genconfig.paper_height_get()); xmlTextWriterWriteAttribute(writer, BAD_CAST "style:print-orientation", BAD_CAST "portrait"); xmlTextWriterWriteAttribute(writer, BAD_CAST "style:num-format", BAD_CAST "1"); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:margin-top", "%.2fcm", settings->genconfig.paper_top_margin_get()); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:margin-bottom", "%.2fcm", settings->genconfig.paper_bottom_margin_get()); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:margin-left", "%.2fcm", settings->genconfig.paper_inside_margin_get()); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:margin-right", "%.2fcm", settings->genconfig.paper_outside_margin_get()); if (right_to_left) { xmlTextWriterWriteAttribute(writer, BAD_CAST "style:writing-mode", BAD_CAST "rl-tb"); xmlTextWriterWriteAttribute(writer, BAD_CAST "writing-mode", BAD_CAST "rl-tb"); } xmlTextWriterEndElement(writer); xmlTextWriterEndElement(writer); xmlTextWriterEndElement(writer); // Master styles. xmlTextWriterStartElement(writer, BAD_CAST "office:master-styles"); xmlTextWriterStartElement(writer, BAD_CAST "style:master-page"); xmlTextWriterWriteAttribute(writer, BAD_CAST "style:name", BAD_CAST "Standard"); xmlTextWriterWriteAttribute(writer, BAD_CAST "style:page-layout-name", BAD_CAST "pm1"); xmlTextWriterEndElement(writer); xmlTextWriterEndElement(writer); // Close document. xmlTextWriterEndElement(writer); // Close document and write it to disk. xmlTextWriterEndDocument(writer); xmlTextWriterFlush(writer); ustring filename = gw_build_filename(workingdirectory, "styles.xml"); g_file_set_contents(filename.c_str(), (const gchar *)buffer->content, -1, NULL); // Free memory. if (writer) xmlFreeTextWriter(writer); if (buffer) xmlBufferFree(buffer); }
int writeXmlAnswsetToFd(MwsAnswset* answset, int fd) { #ifdef TRACE_FUNC_CALLS LOG_TRACE_IN; #endif xmlOutputBuffer* outPtr; xmlTextWriter* writerPtr; size_t qvarNr; int ret; unsigned int i; vector<MwsAnsw*>::iterator it; // Initializing values outPtr = NULL; writerPtr = NULL; ret = -1; qvarNr = answset->qvarNames.size(); if (answset == NULL) { fprintf(stderr, "NULL answset passed to writeXmlAnswsetToFd"); } // Creating the xmlOutputBuffer else if ((outPtr = xmlOutputBufferCreateIO(fdXmlOutputWriteCallback, NULL, &fd, NULL)) == NULL) { fprintf(stderr, "Error while creating the OutputBuffer\n"); } // Creating the xmlTextWriter else if ((writerPtr = xmlNewTextWriter(outPtr)) == NULL) { fprintf(stderr, "Error while creating the TextWriter\n"); } else if ((ret = xmlTextWriterStartDocument(writerPtr, // xmlTextWriter NULL, // XML version ("1.0") NULL, // Encoding ("UTF-8") NULL)) // Standalone ("yes") == -1) { fprintf(stderr, "Error at xmlTextWriterStartDocument\n"); } // MWS timestamp comment else if ((ret = xmlTextWriterWriteComment(writerPtr, BAD_CAST "MwsAnswset generated by " __MWSTIMESTAMP__ " ")) == -1) { fprintf(stderr, "Error at xmlTextWriterStartDocument\n"); } // MWS answset else if ((ret = xmlTextWriterStartElement(writerPtr, BAD_CAST MWSANSWSET_MAIN_NAME)) == -1) { fprintf(stderr, "Error at xmlTextWriterStartElement\n"); } // mws namespace else if ((ret = xmlTextWriterWriteAttribute(writerPtr, BAD_CAST "xmlns:mws", BAD_CAST "http://www.mathweb.org/mws/ns")) == -1) { fprintf(stderr, "Error at xmlTextWriterWriteAttribute\n"); } // attribute size else if ((ret = xmlTextWriterWriteAttribute(writerPtr, BAD_CAST "size", BAD_CAST ToString(answset->answers.size()).c_str())) == -1) { fprintf(stderr, "Error at xmlTextWriterWriteAttribute\n"); } // attribute total else if ((ret = xmlTextWriterWriteAttribute(writerPtr, BAD_CAST "total", BAD_CAST ToString(answset->total).c_str())) == -1) { fprintf(stderr, "Error at xmlTextWriterWriteAttribute\n"); } else // Writing the answers { for (it = answset->answers.begin(); it != answset->answers.end(); it++) { if ((ret = xmlTextWriterStartElement(writerPtr, BAD_CAST MWSANSWSET_ANSW_NAME)) == -1) { fprintf(stderr, "Error at xmlTextWriterStartElement\n"); break; } else if ((ret = xmlTextWriterWriteAttribute(writerPtr, BAD_CAST MWSANSWSET_URI_NAME, BAD_CAST (*it)->uri.c_str())) == -1) { fprintf(stderr, "Error at xmlTextWriterWriteAttribute\n"); break; } else if ((ret = xmlTextWriterWriteAttribute(writerPtr, BAD_CAST MWSANSWSET_XPATH_NAME, BAD_CAST (*it)->xpath.c_str())) == -1) { fprintf(stderr, "Error at xmlTextWriterWriteAttribute\n"); break; } else { // Writing the substitutions for (i = 0; i < qvarNr; i++) { if ((ret = xmlTextWriterStartElement(writerPtr, BAD_CAST MWSANSWSET_SUBSTPAIR_NAME)) == -1) { fprintf(stderr, "Error at xmlTextWriterStartElement\n"); break; } else if ((ret = xmlTextWriterWriteAttribute(writerPtr, BAD_CAST "qvar", BAD_CAST answset->qvarNames[i].c_str())) == -1) { fprintf(stderr, "Error at xmlTextWriterWriteAttribute\n"); break; } else if ((ret = xmlTextWriterWriteAttribute(writerPtr, BAD_CAST "xpath", BAD_CAST (*it)->subst.qvarXpaths[i].c_str())) == -1) { fprintf(stderr, "Error at xmlTextWriterWriteAttribute\n"); break; } else if ((ret = xmlTextWriterEndElement(writerPtr)) == -1) { fprintf(stderr, "Error at xmlTextWriterEndElement\n"); break; } } } if (ret == -1) { fprintf(stderr, "Error while writing xml substpairs\n"); break; } else if ((ret = xmlTextWriterEndElement(writerPtr)) == -1) { fprintf(stderr, "Error at xmlTextWriterEndElement\n"); break; } } } if (ret == -1) { fprintf(stderr, "Error while writing xml answers\n"); } else if ((ret = xmlTextWriterEndElement(writerPtr)) == -1) { fprintf(stderr, "Error at xmlTextWriterEndElement\n"); } // Closing the document else if ((ret = xmlTextWriterEndDocument(writerPtr)) == -1) { fprintf(stderr, "Error at xmlTextWriterEndDocument\n"); } // Flushing the buffer else if ((ret = xmlTextWriterFlush(writerPtr)) == -1) { fprintf(stderr, "Error at xmlTextWriterFlush\n"); } // Everything ok else { ret = 0; } // Cleaning data if (writerPtr) { // This also cleans the outPtr xmlFreeTextWriter(writerPtr); } else if (outPtr) { xmlOutputBufferClose(outPtr); } #ifdef TRACE_FUNC_CALLS LOG_TRACE_OUT; #endif return ret; }
int MwsXmlResponseFormatter::writeData(const GenericAnswer* ans, FILE* output) const { const MwsAnswset& answerSet = *((const MwsAnswset*)ans); xmlOutputBuffer* outPtr; xmlTextWriter* writerPtr; size_t qvarNr; int ret; unsigned int i; LocalContext ctxt; // Initializing values outPtr = nullptr; writerPtr = nullptr; ret = -1; qvarNr = answerSet.qvarNames.size(); ctxt.file = output; ctxt.total_bytes_written = 0; if ((outPtr = xmlOutputBufferCreateIO(fileXmlOutputWriteCallback, nullptr, &ctxt, nullptr)) == nullptr) { PRINT_WARN("Error while creating the OutputBuffer\n"); } else if ((writerPtr = xmlNewTextWriter(outPtr)) == nullptr) { PRINT_WARN("Error while creating the TextWriter\n"); } else if ((ret = xmlTextWriterStartDocument(writerPtr, // xmlTextWriter nullptr, // XML version ("1.0") nullptr, // Encoding ("UTF-8") nullptr)) // Standalone ("yes") == -1) { PRINT_WARN("Error at xmlTextWriterStartDocument\n"); } else if ((ret = xmlTextWriterWriteComment( writerPtr, BAD_CAST "MwsAnswset generated by " MWS_BUILD)) == -1) { PRINT_WARN("Error at xmlTextWriterStartDocument\n"); } else if ((ret = xmlTextWriterStartElement( writerPtr, BAD_CAST MWSANSWSET_MAIN_NAME)) == -1) { PRINT_WARN("Error at xmlTextWriterStartElement\n"); } else if ((ret = xmlTextWriterWriteAttribute( writerPtr, BAD_CAST "xmlns:mws", BAD_CAST "http://www.mathweb.org/mws/ns")) == -1) { PRINT_WARN("Error at xmlTextWriterWriteAttribute\n"); } else if ((ret = xmlTextWriterWriteAttribute( writerPtr, BAD_CAST "size", BAD_CAST std::to_string(answerSet.answers.size()) .c_str())) == -1) { PRINT_WARN("Error at xmlTextWriterWriteAttribute\n"); } else if ((ret = xmlTextWriterWriteAttribute( writerPtr, BAD_CAST "total", BAD_CAST std::to_string(answerSet.total).c_str())) == -1) { PRINT_WARN("Error at xmlTextWriterWriteAttribute\n"); } else { for (auto& answer : answerSet.answers) { if ((ret = xmlTextWriterStartElement( writerPtr, BAD_CAST MWSANSWSET_ANSW_NAME)) == -1) { PRINT_WARN("Error at xmlTextWriterStartElement\n"); break; } else if ((ret = xmlTextWriterWriteAttribute( writerPtr, BAD_CAST MWSANSWSET_URI_NAME, BAD_CAST answer->uri.c_str())) == -1) { PRINT_WARN("Error at xmlTextWriterWriteAttribute\n"); break; } else if ((ret = xmlTextWriterWriteAttribute( writerPtr, BAD_CAST MWSANSWSET_XPATH_NAME, BAD_CAST answer->xpath.c_str())) == -1) { PRINT_WARN("Error at xmlTextWriterWriteAttribute\n"); break; } else { // Writing the substitutions for (i = 0; i < qvarNr; i++) { string qvarXpath = answer->xpath + answerSet.qvarXpaths[i]; if ((ret = xmlTextWriterStartElement( writerPtr, BAD_CAST MWSANSWSET_SUBSTPAIR_NAME)) == -1) { PRINT_WARN("Error at xmlTextWriterStartElement\n"); break; } else if ((ret = xmlTextWriterWriteAttribute( writerPtr, BAD_CAST "qvar", BAD_CAST answerSet.qvarNames[i].c_str())) == -1) { PRINT_WARN("Error at xmlTextWriterWriteAttribute\n"); break; } else if ((ret = xmlTextWriterWriteAttribute( writerPtr, BAD_CAST "xpath", BAD_CAST qvarXpath.c_str())) == -1) { PRINT_WARN("Error at xmlTextWriterWriteAttribute\n"); break; } else if ((ret = xmlTextWriterEndElement(writerPtr)) == -1) { PRINT_WARN("Error at xmlTextWriterEndElement\n"); break; } } // <data> ... </data> xmlTextWriterWriteElement(writerPtr, BAD_CAST "data", BAD_CAST answer->data.c_str()); } if (ret == -1) { PRINT_WARN("Error while writing xml substpairs\n"); break; } else if ((ret = xmlTextWriterEndElement(writerPtr)) == -1) { PRINT_WARN("Error at xmlTextWriterEndElement\n"); break; } } } if (ret == -1) { PRINT_WARN("Error while writing xml answers\n"); } else if ((ret = xmlTextWriterEndElement(writerPtr)) == -1) { PRINT_WARN("Error at xmlTextWriterEndElement\n"); } else if ((ret = xmlTextWriterEndDocument(writerPtr)) == -1) { PRINT_WARN("Error at xmlTextWriterEndDocument\n"); } else if ((ret = xmlTextWriterFlush(writerPtr)) == -1) { PRINT_WARN("Error at xmlTextWriterFlush\n"); } else { ret = 0; } // Cleaning data if (writerPtr) { // This also cleans the outPtr xmlFreeTextWriter(writerPtr); } else if (outPtr) { xmlOutputBufferClose(outPtr); } if (ret == 0) { return ctxt.total_bytes_written; } else { return ret; } }
/** * @brief This function is called when the SAX handler encounters the * beginning of an element. * * @param user_data is a structure which holds the state of the parser. * @param name is the name of the element which triggered the callback. * @param attrs is an array of attributes and values, alternatively * placed. */ static void my_startElement(void* user_data, const xmlChar* name, const xmlChar** attrs) { MwsHarvest_SaxUserData* data = (MwsHarvest_SaxUserData*)user_data; switch (data->state) { case MWSHARVESTSTATE_DEFAULT: if (strcmp(reinterpret_cast<const char*>(name), MWSHARVEST_MAIN_NAME) == 0) { data->state = MWSHARVESTSTATE_IN_MWS_HARVEST; // Parsing the attributes while (nullptr != attrs && nullptr != attrs[0]) { if (strncmp((char*)attrs[0], "xmlns:", 6) == 0) { /* ignore namespaces */ } else { PRINT_WARN("Unexpected attribute \"%s\"\n", attrs[0]); } attrs = &attrs[2]; } } else { // Saving the state data->prevState = data->state; // Going to an unkown state data->state = MWSHARVESTSTATE_UNKNOWN; data->unknownDepth = 1; } break; case MWSHARVESTSTATE_IN_MWS_HARVEST: if (strcmp(reinterpret_cast<const char*>(name), MWSHARVEST_EXPR_NAME) == 0) { data->state = MWSHARVESTSTATE_IN_MWS_EXPR; // Parsing the attributes data->exprUri = MWSHARVEST_EXPR_URI_DEFAULT; data->localId = ""; while (nullptr != attrs && nullptr != attrs[0]) { if (strcmp(reinterpret_cast<const char*>(attrs[0]), MWSHARVEST_EXPR_ATTR_XMLID_NAME) == 0) { data->exprUri = reinterpret_cast<const char*>(attrs[1]); } else if (strcmp(reinterpret_cast<const char*>(attrs[0]), MWSHARVEST_EXPR_ATTR_LOCALID_NAME) == 0) { data->localId = reinterpret_cast<const char*>(attrs[1]); } else { // Invalid attribute PRINT_WARN("Unexpected attribute \"%s\"\n", attrs[0]); } attrs = &attrs[2]; } if (data->shouldProcessData && data->localId != "" && (data->localIdToCrawlIds.find(data->localId) == data->localIdToCrawlIds.end())) { PRINT_WARN("%s \"%s\" does not point to any %s element\n", MWSHARVEST_DATA_ATTR_LOCALID_NAME, data->localId.c_str(), MWSHARVEST_DATA_NAME); data->localId = ""; } } else if (strcmp(reinterpret_cast<const char*>(name), MWSHARVEST_DATA_NAME) == 0) { // Parsing the attributes data->localId = ""; while (nullptr != attrs && nullptr != attrs[0]) { if (strcmp(reinterpret_cast<const char*>(attrs[0]), MWSHARVEST_DATA_ATTR_LOCALID_NAME) == 0) { data->localId = reinterpret_cast<const char*>(attrs[1]); } else { // Invalid attribute PRINT_WARN("Unexpected attribute \"%s\"\n", attrs[0]); } attrs = &attrs[2]; } // Check if localId exists if (data->localId == "") { PRINT_WARN("Ignoring %s element without %s attribute.\n", MWSHARVEST_DATA_NAME, MWSHARVEST_DATA_ATTR_LOCALID_NAME); // Saving the state data->prevState = data->state; // Going to an unkown state data->state = MWSHARVESTSTATE_UNKNOWN; data->unknownDepth = 1; } else { setupCopyToStringWriter(data); data->state = MWSHARVESTSTATE_IN_MWS_DATA; data->copyDepth = 1; } } else { PRINT_WARN("Ignoring %s element\n", name); // Saving the state data->prevState = data->state; // Going to an unkown state data->state = MWSHARVESTSTATE_UNKNOWN; data->unknownDepth = 1; } break; case MWSHARVESTSTATE_IN_MWS_EXPR: if (data->currentToken != nullptr) { data->currentToken = data->currentToken->newChildNode(); } else { data->currentTokenRoot = CmmlToken::newRoot(); data->currentToken = data->currentTokenRoot; } data->currentToken->setTag(reinterpret_cast<const char*>(name)); // Adding the attributes while (nullptr != attrs && nullptr != attrs[0]) { string attributeName = reinterpret_cast<const char*>(attrs[0]); string attributeValue = reinterpret_cast<const char*>(attrs[1]); data->currentToken->addAttribute(attributeName, attributeValue); attrs = &attrs[2]; } break; case MWSHARVESTSTATE_IN_MWS_DATA: data->copyDepth++; xmlTextWriterStartElement(data->stringWriter, name); while (nullptr != attrs && nullptr != attrs[0]) { xmlTextWriterWriteAttribute(data->stringWriter, attrs[0], attrs[1]); attrs = &attrs[2]; } break; case MWSHARVESTSTATE_UNKNOWN: data->unknownDepth++; break; } }
int write_dsig_template(opendcp_t *opendcp, xmlTextWriterPtr xml) { BIO *bio[3]; X509 *x[3]; X509_NAME *issuer_xn[3]; X509_NAME *subject_xn[3]; char *cert[3]; int i; dcp_log(LOG_DEBUG, "xml_sign: write_dsig_template"); if (opendcp->xml_signature.use_external) { /* read certificates from file */ FILE *cp; cp = fopen(opendcp->xml_signature.signer,"rb"); if (cp) { x[0] = PEM_read_X509(cp,NULL,NULL,NULL); fclose(cp); } cp = fopen(opendcp->xml_signature.ca,"rb"); if (cp) { x[1] = PEM_read_X509(cp,NULL,NULL,NULL); fclose(cp); } cp = fopen(opendcp->xml_signature.root,"rb"); if (cp) { x[2] = PEM_read_X509(cp,NULL,NULL,NULL); fclose(cp); } cert[0] = strip_cert_file(opendcp->xml_signature.signer); cert[1] = strip_cert_file(opendcp->xml_signature.ca); cert[2] = strip_cert_file(opendcp->xml_signature.root); } else { /* read certificate from memory */ bio[0] = BIO_new_mem_buf((void *)opendcp_signer_cert, -1); bio[1] = BIO_new_mem_buf((void *)opendcp_ca_cert, -1); bio[2] = BIO_new_mem_buf((void *)opendcp_root_cert, -1); /* save a copy with the BEGIN/END stripped */ cert[0] = strip_cert(opendcp_signer_cert); cert[1] = strip_cert(opendcp_ca_cert); cert[2] = strip_cert(opendcp_root_cert); for (i=0;i<3;i++) { if (bio[i] == NULL) { dcp_log(LOG_ERROR,"Could allocate certificate from memory"); return OPENDCP_ERROR; } x[i] = PEM_read_bio_X509(bio[i], NULL, NULL, NULL); if (!BIO_set_close(bio[i], BIO_NOCLOSE)) { dcp_log(LOG_ERROR,"Could set BIO close flag"); return OPENDCP_ERROR; } if (x[i] == NULL) { dcp_log(LOG_ERROR,"Could not read certificate"); return OPENDCP_ERROR; } } } /* get issuer, subject */ for (i=0;i<3;i++) { issuer_xn[i] = X509_get_issuer_name(x[i]); subject_xn[i] = X509_get_subject_name(x[i]); if (issuer_xn[i] == NULL || subject_xn[i] == NULL) { dcp_log(LOG_ERROR,"Could not parse certificate data"); return OPENDCP_ERROR; } } dcp_log(LOG_DEBUG, "xml_sign: write_dsig_template: start signer"); /* signer */ xmlTextWriterStartElement(xml, BAD_CAST "Signer"); xmlTextWriterStartElementNS(xml, BAD_CAST "dsig", BAD_CAST "X509Data", NULL); xmlTextWriterStartElementNS(xml, BAD_CAST "dsig", BAD_CAST "X509IssuerSerial", NULL); xmlTextWriterWriteFormatElementNS(xml, BAD_CAST "dsig", BAD_CAST "X509IssuerName", NULL, "%s", dn_oneline(issuer_xn[0])); xmlTextWriterWriteFormatElementNS(xml, BAD_CAST "dsig", BAD_CAST "X509SerialNumber", NULL, "%ld", ASN1_INTEGER_get(X509_get_serialNumber(x[0]))); xmlTextWriterEndElement(xml); xmlTextWriterWriteFormatElementNS(xml, BAD_CAST "dsig", BAD_CAST "X509SubjectName", NULL, "%s", dn_oneline(subject_xn[0])); xmlTextWriterEndElement(xml); xmlTextWriterEndElement(xml); /* template */ xmlTextWriterStartElementNS(xml, BAD_CAST "dsig", BAD_CAST "Signature", NULL); xmlTextWriterStartElementNS(xml, BAD_CAST "dsig", BAD_CAST "SignedInfo", NULL); xmlTextWriterStartElementNS(xml, BAD_CAST "dsig", BAD_CAST "CanonicalizationMethod", NULL); xmlTextWriterWriteAttribute(xml, BAD_CAST "Algorithm", BAD_CAST DS_CMA); xmlTextWriterEndElement(xml); xmlTextWriterStartElementNS(xml, BAD_CAST "dsig", BAD_CAST "SignatureMethod", NULL); xmlTextWriterWriteAttribute(xml, BAD_CAST "Algorithm", BAD_CAST DS_SMA[opendcp->ns]); xmlTextWriterEndElement(xml); xmlTextWriterStartElementNS(xml, BAD_CAST "dsig", BAD_CAST "Reference", NULL); xmlTextWriterWriteAttribute(xml, BAD_CAST "URI", BAD_CAST NULL); xmlTextWriterStartElementNS(xml, BAD_CAST "dsig", BAD_CAST"Transforms", NULL); xmlTextWriterStartElementNS(xml, BAD_CAST "dsig", BAD_CAST "Transform", NULL); xmlTextWriterWriteAttribute(xml, BAD_CAST "Algorithm", BAD_CAST DS_TMA); xmlTextWriterEndElement(xml); xmlTextWriterEndElement(xml); xmlTextWriterStartElementNS(xml, BAD_CAST "dsig", BAD_CAST "DigestMethod", NULL); xmlTextWriterWriteAttribute(xml, BAD_CAST "Algorithm", BAD_CAST DS_DMA); xmlTextWriterEndElement(xml); xmlTextWriterWriteElementNS(xml, BAD_CAST "dsig", BAD_CAST "DigestValue", NULL, BAD_CAST ""); xmlTextWriterEndElement(xml); xmlTextWriterEndElement(xml); xmlTextWriterWriteElementNS(xml, BAD_CAST "dsig", BAD_CAST "SignatureValue", NULL, BAD_CAST ""); xmlTextWriterStartElementNS(xml, BAD_CAST "dsig", BAD_CAST "KeyInfo", NULL); for (i=0;i<3;i++) { xmlTextWriterStartElementNS(xml, BAD_CAST "dsig", BAD_CAST "X509Data", NULL); xmlTextWriterStartElementNS(xml, BAD_CAST "dsig", BAD_CAST "X509IssuerSerial", NULL); xmlTextWriterWriteFormatElementNS(xml, BAD_CAST "dsig", BAD_CAST "X509IssuerName", NULL, "%s", dn_oneline(issuer_xn[i])); xmlTextWriterWriteFormatElementNS(xml, BAD_CAST "dsig", BAD_CAST "X509SerialNumber", NULL, "%ld", ASN1_INTEGER_get(X509_get_serialNumber(x[i]))); xmlTextWriterEndElement(xml); xmlTextWriterWriteFormatElementNS(xml, BAD_CAST "dsig", BAD_CAST "X509Certificate", NULL, "%s", cert[i]); xmlTextWriterEndElement(xml); } xmlTextWriterEndElement(xml); /* KeyInfo */ xmlTextWriterEndElement(xml); /* Signature */ if (subject_xn[0]) { free(subject_xn[0]); } for (i=0;i<3;i++) { if (issuer_xn[i]) { free(issuer_xn[i]); } } return OPENDCP_NO_ERROR; }
/** * Takes a metadata linked list and generates XML data. * This should be called automatically. * * @param p_metadata a pointer to the structure as input. * @param data a pointer to the array to output. * @param len a pointer to the length of the output. * @return zero on success. * @see VitaMTP_SendObjectMetadata() */ int metadata_to_xml(metadata_t *p_metadata, char** data, int *len){ xmlTextWriterPtr writer; xmlBufferPtr buf; buf = xmlBufferCreate(); if (buf == NULL) { if(IS_LOGGING(ERROR_LOG)){ fprintf(stderr, "metadata_to_xml: Error creating the xml buffer\n"); return 1; } } writer = xmlNewTextWriterMemory(buf, 0); if (writer == NULL) { if(IS_LOGGING(ERROR_LOG)){ fprintf(stderr, "metadata_to_xml: Error creating the xml writer\n"); return 1; } } if(xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL) < 0){ if(IS_LOGGING(ERROR_LOG)){ fprintf(stderr, "metadata_to_xml: Error at xmlTextWriterStartDocument\n"); return 1; } } xmlTextWriterStartElement(writer, BAD_CAST "objectMetadata"); for(metadata_t *current = p_metadata; current != NULL; current = current->next_metadata){ char *timestamp; switch(current->dataType){ case Folder: xmlTextWriterStartElement(writer, BAD_CAST "folder"); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "type", "%d", current->data.folder.type); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "name", "%s", current->data.folder.name); break; case File: xmlTextWriterStartElement(writer, BAD_CAST "file"); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "name", "%s", current->data.file.name); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "statusType", "%d", current->data.file.statusType); break; case SaveData: xmlTextWriterStartElement(writer, BAD_CAST "saveData"); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "detail", "%s", current->data.saveData.detail); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "dirName", "%s", current->data.saveData.dirName); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "savedataTitle", "%s", current->data.saveData.savedataTitle); timestamp = vita_make_time(current->data.saveData.dateTimeUpdated); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "dateTimeUpdated", "%s", timestamp); free(timestamp); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "statusType", "%d", current->data.saveData.statusType); break; case Thumbnail: xmlTextWriterStartElement(writer, BAD_CAST "thumbnail"); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "codecType", "%d", current->data.thumbnail.codecType); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "width", "%d", current->data.thumbnail.width); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "height", "%d", current->data.thumbnail.height); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "type", "%d", current->data.thumbnail.type); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "orientationType", "%d", current->data.thumbnail.orientationType); char *aspectRatio; asprintf(&aspectRatio, "%.6f", current->data.thumbnail.aspectRatio); char *period = strchr(aspectRatio, '.'); *period = ','; // All this to make period a comma, maybe there is an easier way? xmlTextWriterWriteAttribute(writer, BAD_CAST "aspectRatio", BAD_CAST aspectRatio); free(aspectRatio); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fromType", "%d", current->data.thumbnail.fromType); break; default: continue; } xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "index", "%d", current->index); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "ohfiParent", "%d", current->ohfiParent); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "ohfi", "%d", current->ohfi); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "title", "%s", current->title); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "size", "%lu", current->size); timestamp = vita_make_time(current->dateTimeCreated); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "dateTimeCreated", "%s", timestamp); free(timestamp); xmlTextWriterEndElement(writer); } xmlTextWriterEndElement(writer); if (xmlTextWriterEndDocument(writer) < 0) { if(IS_LOGGING(ERROR_LOG)){ fprintf(stderr, "metadata_to_xml: Error at xmlTextWriterEndDocument\n"); return 1; } } xmlFreeTextWriter(writer); *data = add_size_header((char*)buf->content, (uint32_t)buf->use + 1); *len = buf->use + sizeof(uint32_t) + 1; xmlBufferFree(buf); return 0; }
int rsstool_write_xml (st_rsstool_t *rt) { #define XMLPRINTF(s) xmlTextWriterWriteString(writer,BAD_CAST s) st_rss_t rss; int i = 0; xmlTextWriterPtr writer; xmlBufferPtr buffer; st_hash_t *dl_url_h = NULL; st_hash_t *url_h = NULL; st_hash_t *title_h = NULL; int items = rsstool_get_item_count (rt); #define ENCODE(s) s //#define ENCODE(s) base64_enc(s,0) //#define ENCODE(s) str_escape_xml(s) memset (&rss, 0, sizeof (st_rss_t)); if (!(buffer = xmlBufferCreate ())) return -1; if (!(writer = xmlNewTextWriterMemory (buffer, 0))) return -1; xmlTextWriterStartDocument (writer, NULL, "UTF-8", NULL); xmlTextWriterWriteComment (writer, BAD_CAST " RSStool - read, parse, merge and write RSS and Atom feeds\n" "http://rsstool.berlios.de "); XMLPRINTF("\n"); xmlTextWriterWriteComment (writer, BAD_CAST "\n" "format:\n" "item[]\n" " dl_url \n" " dl_url_md5\n" " dl_url_crc32\n" " dl_date\n" " user author\n" " site\n" " url \n" " url_md5\n" " url_crc32\n" " date default: current time\n" " title used by searches for related items\n" " title_md5\n" " title_crc32\n" " desc description\n" " media_keywords default: keywords from title and description\n" " media_duration event length\n" " media_image thumbnail\n" " event_start default: date\n" " event_end default: event_start + media_duration\n" ); XMLPRINTF("\n"); xmlTextWriterStartElement (writer, BAD_CAST "rsstool"); // <rsstool> xmlTextWriterWriteAttribute (writer, BAD_CAST "version", BAD_CAST RSSTOOL_VERSION_S); for (i = 0; i < items && i < RSSMAXITEM; i++) // for (i = 0; i < items; i++) { dl_url_h = hash_open (HASH_MD5|HASH_CRC32); url_h = hash_open (HASH_MD5|HASH_CRC32); title_h = hash_open (HASH_MD5|HASH_CRC32); dl_url_h = hash_update (dl_url_h, (const unsigned char *) rt->item[i]->feed_url, strlen (rt->item[i]->feed_url)); url_h = hash_update (url_h, (const unsigned char *) rt->item[i]->url, strlen (rt->item[i]->url)); title_h = hash_update (title_h, (const unsigned char *) rt->item[i]->title, strlen (rt->item[i]->title)); XMLPRINTF("\n "); xmlTextWriterStartElement (writer, BAD_CAST "item"); // <item> XMLPRINTF("\n "); // xmlTextWriterWriteElement (writer, BAD_CAST "dl_url", BAD_CAST rt->item[i]->feed_url); xmlTextWriterWriteFormatElement (writer, BAD_CAST "dl_url", "%s", rt->item[i]->feed_url); XMLPRINTF("\n "); xmlTextWriterWriteFormatElement (writer, BAD_CAST "dl_url_md5", "%s", hash_get_s (dl_url_h, HASH_MD5)); XMLPRINTF("\n "); xmlTextWriterWriteFormatElement (writer, BAD_CAST "dl_url_crc32", "%u", hash_get_crc32 (dl_url_h)); XMLPRINTF("\n "); xmlTextWriterWriteFormatElement (writer, BAD_CAST "dl_date", "%ld", rsstool.start_time); XMLPRINTF("\n "); xmlTextWriterWriteFormatElement (writer, BAD_CAST "user", "%s", ENCODE (rt->item[i]->user)); XMLPRINTF("\n "); xmlTextWriterWriteFormatElement (writer, BAD_CAST "site", "%s", ENCODE (rt->item[i]->site)); XMLPRINTF("\n "); xmlTextWriterWriteFormatElement (writer, BAD_CAST "url", "%s", rt->item[i]->url); XMLPRINTF("\n "); xmlTextWriterWriteFormatElement (writer, BAD_CAST "url_md5", "%s", hash_get_s (url_h, HASH_MD5)); XMLPRINTF("\n "); xmlTextWriterWriteFormatElement (writer, BAD_CAST "url_crc32", "%u", hash_get_crc32 (url_h)); XMLPRINTF("\n "); xmlTextWriterWriteFormatElement (writer, BAD_CAST "date", "%ld", rt->item[i]->date); XMLPRINTF("\n "); xmlTextWriterWriteFormatElement (writer, BAD_CAST "title", "%s", ENCODE (rt->item[i]->title)); XMLPRINTF("\n "); xmlTextWriterWriteFormatElement (writer, BAD_CAST "title_md5", "%s", hash_get_s (title_h, HASH_MD5)); XMLPRINTF("\n "); xmlTextWriterWriteFormatElement (writer, BAD_CAST "title_crc32", "%u", hash_get_crc32 (title_h)); XMLPRINTF("\n "); xmlTextWriterWriteFormatElement (writer, BAD_CAST "desc", "%s", ENCODE (rt->item[i]->desc)); XMLPRINTF("\n "); xmlTextWriterWriteFormatElement (writer, BAD_CAST "media_keywords", "%s", ENCODE (rt->item[i]->media_keywords)); XMLPRINTF("\n "); xmlTextWriterWriteFormatElement (writer, BAD_CAST "media_duration", "%ld", rt->item[i]->media_duration); XMLPRINTF("\n "); xmlTextWriterWriteFormatElement (writer, BAD_CAST "media_image", "%s", rt->item[i]->media_image); XMLPRINTF("\n "); xmlTextWriterWriteFormatElement (writer, BAD_CAST "event_start", "%ld", rt->item[i]->event_start); XMLPRINTF("\n "); xmlTextWriterWriteFormatElement (writer, BAD_CAST "event_end", "%ld", rt->item[i]->event_end); XMLPRINTF("\n "); xmlTextWriterEndElement (writer); // </item> hash_close (dl_url_h); hash_close (url_h); hash_close (title_h); } XMLPRINTF("\n"); xmlTextWriterEndDocument (writer); // </rsstool> xmlFreeTextWriter (writer); fputs ((const char *) buffer->content, rt->output_file); xmlBufferFree (buffer); if (items >= RSSMAXITEM) { char buf[MAXBUFSIZE]; sprintf (buf, "can write only RSS feeds with up to %d items (was %d items)\n", RSSMAXITEM, items); rsstool_log (rt, buf); } return 0; }
static void Save(const SObject *object, const char *path, s_erc *error) { int rc; SUtterance *utt = S_UTTERANCE(object); SDatasource *ds; xmlTextWriterPtr writer; xmlOutputBufferPtr out; const char * xsi = "http://www.w3.org/2001/XMLSchema-instance"; S_CLR_ERR(error); ds = SFilesourceOpenFile(path, "wt", error); if (S_CHK_ERR(error, S_CONTERR, "Save", "Call to \"SFilesourceOpenFile\" failed")) return; out = xmlOutputBufferCreateIO(_ds_write, _ds_close, ds, NULL); if (out == NULL) { S_CTX_ERR(error, S_CONTERR, "Save", "Call to \"xmlOutputBufferCreateIO\" failed"); return; } writer = xmlNewTextWriter(out); if (writer == NULL) { xmlOutputBufferClose(out); S_CTX_ERR(error, S_CONTERR, "Save", "Call to \"xmlNewTextWriter\" failed"); return; } /* Start Document */ rc = xmlTextWriterStartDocument(writer, NULL, ENCODING, NULL); if (rc < 0) { S_CTX_ERR(error, S_CONTERR, "Save", "Call to \"xmlTextWriterStartDocument\" failed"); goto s_write_utt_exit; } /* Write the maryxml namespace */ rc = xmlTextWriterStartElement(writer, BAD_CAST "xml"); if (rc < 0) { S_CTX_ERR(error, S_CONTERR, "Save", "Call to \"xmlTextWriterStartElement\" failed"); goto s_write_utt_exit; } rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:xsi", BAD_CAST xsi); if (rc < 0) { S_CTX_ERR(error, S_CONTERR, "Save", "Call to \"xmlTextWriterWriteAttribute\" failed"); goto s_write_utt_exit; } rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "version", BAD_CAST "0.5"); if (rc < 0) { S_CTX_ERR(error, S_CONTERR, "Save", "Call to \"xmlTextWriterWriteAttribute\" failed"); goto s_write_utt_exit; } // print labels /* get to the first syllable of the current word */ const SItem* itrSegments = SRelationHead(SUtteranceGetRelation(utt, "Segment", error), error); if (S_CHK_ERR(error, S_CONTERR, "Save", "Call to \"SItemPathToItem\" failed")) goto s_write_utt_exit; while (itrSegments != NULL) { /* get segment content */ const char* label = SItemGetString(itrSegments, "hts_label", error); if (S_CHK_ERR(error, S_CONTERR, "Save", "Call to \"SItemGetName\" failed")) goto s_write_utt_exit; /* get next segment */ itrSegments = SItemNext(itrSegments, error); if (S_CHK_ERR(error, S_CONTERR, "Save", "Call to \"SItemNext\" failed")) goto s_write_utt_exit; xmlTextWriterWriteElement(writer, BAD_CAST "label", BAD_CAST label); } /* Close the tag xml */ rc = xmlTextWriterEndElement(writer); if (rc < 0) { S_CTX_ERR(error, S_CONTERR, "Save", "Call to \"xmlTextWriterEndDocument\" failed"); goto s_write_utt_exit; } /* Close the document */ rc = xmlTextWriterEndDocument(writer); if (rc < 0) { S_CTX_ERR(error, S_CONTERR, "Save", "Call to \"xmlTextWriterEndDocument\" failed"); goto s_write_utt_exit; } s_write_utt_exit: xmlFreeTextWriter(writer); }
xmlChar *get_uri(fsp_link *link, fs_rid rid) { if (cache[rid & CACHE_MASK].rid == rid) { return (xmlChar *) cache[rid & CACHE_MASK].lex; } fs_rid_vector onerid = { .length = 1, .size = 1, .data = &rid }; fs_resource resource; fsp_resolve(link, FS_RID_SEGMENT(rid, segments), &onerid, &resource); return (xmlChar *) resource.lex; } xmlChar *get_attr(fsp_link *link, fs_rid rid) { if (attr_cache[rid & CACHE_MASK].rid == rid) { return (xmlChar *) attr_cache[rid & CACHE_MASK].lex; } fs_rid_vector onerid = { .length = 1, .size = 1, .data = &rid }; fs_resource resource; fsp_resolve(link, FS_RID_SEGMENT(rid, segments), &onerid, &resource); memcpy(&attr_cache[rid & ATTR_CACHE_MASK], &resource, sizeof(fs_resource)); return (xmlChar *) resource.lex; } xmlChar *get_literal(fsp_link *link, fs_rid rid, fs_rid *attr) { if (cache[rid & CACHE_MASK].rid == rid) { *attr = cache[rid & CACHE_MASK].attr; return (xmlChar *) cache[rid & CACHE_MASK].lex; } fs_rid_vector onerid = { .length = 1, .size = 1, .data = &rid }; fs_resource resource; fsp_resolve(link, FS_RID_SEGMENT(rid, segments), &onerid, &resource); *attr = resource.attr; return (xmlChar *) resource.lex; } void resolve_triples(fsp_link *link, fs_rid_vector **rids) { int quads = rids[0]->length; fs_rid_vector *todo[segments]; fs_segment segment; for (segment = 0; segment < segments; ++segment) { todo[segment] = fs_rid_vector_new(0); } for (int c = 0; c < 3; ++c) { for (int k = 0; k < quads; ++k) { const fs_rid rid = rids[c]->data[k]; if (FS_IS_BNODE(rid) || cache[rid & CACHE_MASK].rid == rid) continue; fs_rid_vector_append(todo[FS_RID_SEGMENT(rid, segments)], rid); cache[rid & CACHE_MASK].rid = rid; /* well, it will be soon */ } } int length[segments]; fs_resource *resources[segments]; for (segment = 0; segment < segments; ++segment) { length[segment] = todo[segment]->length; resources[segment] = calloc(length[segment], sizeof(fs_resource)); } fsp_resolve_all(link, todo, resources); for (segment = 0; segment < segments; ++segment) { fs_resource *res = resources[segment]; for (int k = 0; k < length[segment]; ++k) { free(cache[res[k].rid & CACHE_MASK].lex); memcpy(&cache[res[k].rid & CACHE_MASK], &res[k], sizeof(fs_resource)); } fs_rid_vector_free(todo[segment]); free(resources[segment]); } } void dump_model(fsp_link *link, fs_rid model, xmlTextWriterPtr xml) { fs_rid_vector none = { .length = 0, .size = 0, .data = 0 }; fs_rid_vector one = { .length = 1, .size = 1, .data = &model }; fs_rid_vector **results; double then; /* for time keeping */ then = fs_time(); fsp_bind_first_all(link, BIND_SPO, &one, &none, &none, &none, &results, QUAD_LIMIT); time_bind_first += (fs_time() - then); while (results != NULL) { long length = results[0]->length; if (length == 0) break; then = fs_time(); resolve_triples(link, results); time_resolving += (fs_time() - then); then = fs_time(); for (int k = 0; k < length; ++k) { xmlTextWriterStartElement(xml, (xmlChar *) "triple"); for (int r = 0; r < 3; ++r) { fs_rid rid = results[r]->data[k]; if (FS_IS_BNODE(rid)) { unsigned long long node = FS_BNODE_NUM(rid); xmlTextWriterWriteFormatElement(xml, (xmlChar *) "id", "%llu", node); } else if (FS_IS_URI(rid)) { xmlChar *uri = get_uri(link, rid); xmlTextWriterWriteElement(xml, (xmlChar *) "uri", uri); } else if (FS_IS_LITERAL(rid)) { fs_rid attr; xmlChar *lex = get_literal(link, rid, &attr); if (attr == fs_c.empty) { xmlTextWriterWriteElement(xml, (xmlChar *) "plainLiteral", lex); } else if (FS_IS_URI(attr)) { xmlChar *type = get_uri(link, attr); xmlTextWriterStartElement(xml, (xmlChar *) "typedLiteral"); xmlTextWriterWriteString(xml, (xmlChar *) lex); xmlTextWriterWriteAttribute(xml, (xmlChar *) "datatype", type); xmlTextWriterEndElement(xml); } else if (FS_IS_LITERAL(attr)) { xmlChar *lang = get_attr(link, attr); xmlTextWriterStartElement(xml, (xmlChar *) "plainLiteral"); xmlTextWriterWriteAttribute(xml, (xmlChar *) "xml:lang", lang); xmlTextWriterWriteString(xml, (xmlChar *) lex); xmlTextWriterEndElement(xml); } } } xmlTextWriterEndElement(xml); xmlTextWriterWriteString(xml, (xmlChar *) "\n"); } time_write_out += (fs_time() - then); fs_rid_vector_free(results[0]); fs_rid_vector_free(results[1]); fs_rid_vector_free(results[2]); free(results); then = fs_time(); fsp_bind_next_all(link, BIND_SPO, &results, QUAD_LIMIT); time_bind_next += (fs_time() - then); } fsp_bind_done_all(link); } void dump_trix(fsp_link *link, xmlTextWriterPtr xml) { fs_rid_vector **models; fs_rid_vector none = { .length = 0, .size = 0, .data = 0 }; fsp_bind_all(link, FS_BIND_DISTINCT | FS_BIND_MODEL | FS_BIND_BY_SUBJECT, &none, &none, &none, &none, &models); fs_rid_vector_sort(models[0]); fs_rid_vector_uniq(models[0], 1); long length = models[0]->length; for (int k = 0; k < length; ++k) { fs_rid model = models[0]->data[k]; xmlChar *model_uri = get_uri(link, model); xmlTextWriterStartElement(xml, (xmlChar *) "graph"); if (FS_IS_URI(model)) { xmlTextWriterWriteElement(xml, (xmlChar *) "uri", model_uri); } else { fs_error(LOG_WARNING, "model %lld is not a URI", model); } dump_model(link, model, xml); xmlTextWriterEndElement(xml); xmlTextWriterWriteString(xml, (xmlChar *) "\n"); printf("%5d/%ld: %4.5f %4.5f %4.5f %4.5f\n", k + 1, length, time_resolving, time_bind_first, time_bind_next, time_write_out); } } void dump_file(fsp_link *link, char *filename) { xmlTextWriterPtr xml = xmlNewTextWriterFilename(filename, TRUE); if (!xml) { fs_error(LOG_ERR, "Couldn't write output file, giving up"); exit(4); } xmlTextWriterStartDocument(xml, NULL, NULL, NULL); xmlTextWriterStartElement(xml, (xmlChar *) "TriX"); dump_trix(link, xml); xmlTextWriterEndDocument(xml); /* also closes TriX */ xmlFreeTextWriter(xml); } int main(int argc, char *argv[]) { char *password = fsp_argv_password(&argc, argv); if (argc != 3) { fprintf(stderr, "%s revision %s\n", argv[0], FS_FRONTEND_VER); fprintf(stderr, "Usage: %s <kbname> <uri>\n", argv[0]); exit(1); } fsp_link *link = fsp_open_link(argv[1], password, FS_OPEN_HINT_RO); if (!link) { fs_error (LOG_ERR, "couldn't connect to “%s”", argv[1]); exit(2); } fs_hash_init(fsp_hash_type(link)); segments = fsp_link_segments(link); dump_file(link, argv[2]); fsp_close_link(link); }
/** * testXmlwriterTree: * @file: the output file * * test the xmlWriter interface when writing to a subtree */ void testXmlwriterTree(const char *file) { int rc; xmlTextWriterPtr writer; xmlDocPtr doc; xmlNodePtr node; xmlChar *tmp; /* Create a new XML DOM tree, to which the XML document will be * written */ doc = xmlNewDoc(BAD_CAST XML_DEFAULT_VERSION); if (doc == NULL) { printf ("testXmlwriterTree: Error creating the xml document tree\n"); return; } /* Create a new XML node, to which the XML document will be * appended */ node = xmlNewDocNode(doc, NULL, BAD_CAST "EXAMPLE", NULL); if (node == NULL) { printf("testXmlwriterTree: Error creating the xml node\n"); return; } /* Make ELEMENT the root node of the tree */ xmlDocSetRootElement(doc, node); /* Create a new XmlWriter for DOM tree, with no compression. */ writer = xmlNewTextWriterTree(doc, node, 0); if (writer == NULL) { printf("testXmlwriterTree: Error creating the xml writer\n"); return; } /* Start the document with the xml default for the version, * encoding ISO 8859-1 and the default for the standalone * declaration. */ rc = xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterStartDocument\n"); return; } /* Write a comment as child of EXAMPLE. * Please observe, that the input to the xmlTextWriter functions * HAS to be in UTF-8, even if the output XML is encoded * in iso-8859-1 */ tmp = ConvertInput("This is a comment with special chars: <äöü>", MY_ENCODING); rc = xmlTextWriterWriteComment(writer, tmp); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterWriteComment\n"); return; } if (tmp != NULL) xmlFree(tmp); /* Start an element named "ORDER" as child of EXAMPLE. */ rc = xmlTextWriterStartElement(writer, BAD_CAST "ORDER"); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterStartElement\n"); return; } /* Add an attribute with name "version" and value "1.0" to ORDER. */ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "version", BAD_CAST "1.0"); if (rc < 0) { printf ("testXmlwriterTree: Error at xmlTextWriterWriteAttribute\n"); return; } /* Add an attribute with name "xml:lang" and value "de" to ORDER. */ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang", BAD_CAST "de"); if (rc < 0) { printf ("testXmlwriterTree: Error at xmlTextWriterWriteAttribute\n"); return; } /* Write a comment as child of ORDER */ tmp = ConvertInput("<äöü>", MY_ENCODING); rc = xmlTextWriterWriteFormatComment(writer, "This is another comment with special chars: %s", tmp); if (rc < 0) { printf ("testXmlwriterTree: Error at xmlTextWriterWriteFormatComment\n"); return; } if (tmp != NULL) xmlFree(tmp); /* Start an element named "HEADER" as child of ORDER. */ rc = xmlTextWriterStartElement(writer, BAD_CAST "HEADER"); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterStartElement\n"); return; } /* Write an element named "X_ORDER_ID" as child of HEADER. */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "X_ORDER_ID", "%010d", 53535L); if (rc < 0) { printf ("testXmlwriterTree: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Write an element named "CUSTOMER_ID" as child of HEADER. */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "CUSTOMER_ID", "%d", 1010); if (rc < 0) { printf ("testXmlwriterTree: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Write an element named "NAME_1" as child of HEADER. */ tmp = ConvertInput("Müller", MY_ENCODING); rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1", tmp); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterWriteElement\n"); return; } if (tmp != NULL) xmlFree(tmp); /* Write an element named "NAME_2" as child of HEADER. */ tmp = ConvertInput("Jörg", MY_ENCODING); rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2", tmp); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriter
void XmlWriter::StartImage(const String& aImageName) { xmlTextWriterStartElement(iXmlTextWriter, BAD_CAST KXmlImageName.c_str()); xmlTextWriterWriteAttribute(iXmlTextWriter, BAD_CAST KXmlImageAtt1.c_str() , BAD_CAST aImageName.c_str()); }
void OpenDocument::span_style(xmlTextWriterPtr writer, const ustring & marker, const ustring & name, const ustring & fontname, double fontpercentage, ustring italic, ustring bold, ustring underline, ustring smallcaps, bool superscript, unsigned int color) { // Open the style. xmlTextWriterStartElement(writer, BAD_CAST "style:style"); { // Style properties. xmlTextWriterWriteAttribute(writer, BAD_CAST "style:name", BAD_CAST marker.c_str()); ustring marker_name = marker + " " + name; xmlTextWriterWriteAttribute(writer, BAD_CAST "style:display-name", BAD_CAST marker_name.c_str()); xmlTextWriterWriteAttribute(writer, BAD_CAST "style:family", BAD_CAST "text"); // Text properties. xmlTextWriterStartElement(writer, BAD_CAST "style:text-properties"); { if (!fontname.empty()) { xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "style:font-name", "%s", fontname.c_str()); } if (fontpercentage != 100) { xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:font-size", "%.1f%%", fontpercentage); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:font-size-asian", "%.1f%%", fontpercentage); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:font-size-complex", "%.1f%%", fontpercentage); } if ((italic == ON) || (italic == TOGGLE)) italic = "italic"; else italic = "normal"; // Note that ON and TOGGlE both switch italic on // and OFF and INHERIT switch italic off. // Improvements could be made here. // Bold, underline, etc., work the same. xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:font-style", BAD_CAST italic.c_str()); xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:font-style-asian", BAD_CAST italic.c_str()); xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:font-style-complex", BAD_CAST italic.c_str()); if ((bold == ON) || (bold == TOGGLE)) bold = "bold"; else bold = "normal"; xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:font-weight", BAD_CAST bold.c_str()); xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:font-weight-asian", BAD_CAST bold.c_str()); xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:font-weight-complex", BAD_CAST bold.c_str()); if ((underline == ON) || (underline == TOGGLE)) underline = "solid"; else underline = "none"; xmlTextWriterWriteAttribute(writer, BAD_CAST "style:text-underline-style", BAD_CAST underline.c_str()); xmlTextWriterWriteAttribute(writer, BAD_CAST "style:text-underline-width", BAD_CAST "auto"); xmlTextWriterWriteAttribute(writer, BAD_CAST "style:text-underline-color", BAD_CAST "font-color"); if ((smallcaps == ON) || (smallcaps == TOGGLE)) smallcaps = "small-caps"; else smallcaps = "normal"; xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:font-variant", BAD_CAST smallcaps.c_str()); if (superscript) { xmlTextWriterWriteAttribute(writer, BAD_CAST "style:text-position", BAD_CAST "super 58%"); } if (color != 0) { xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:color", "#%s", color_decimal_to_hex(color).c_str()); } } xmlTextWriterEndElement(writer); } // Close style. xmlTextWriterEndElement(writer); }
void OpenDocument::paragraph_style(xmlTextWriterPtr writer, const ustring & marker, const ustring & name, const ustring & fontname, double fontsize, int lineheight, const ustring & italic, const ustring & bold, const ustring & underline, const ustring & smallcaps, ustring justification, double spacebefore, double spaceafter, double leftmargin, double rightmargin, double firstlineindent, bool spancolumns, bool startpage) { // Style properties. xmlTextWriterStartElement(writer, BAD_CAST "style:style"); { xmlTextWriterWriteAttribute(writer, BAD_CAST "style:name", BAD_CAST marker.c_str()); ustring marker_name = marker + " " + name; xmlTextWriterWriteAttribute(writer, BAD_CAST "style:display-name", BAD_CAST marker_name.c_str()); xmlTextWriterWriteAttribute(writer, BAD_CAST "style:family", BAD_CAST "paragraph"); xmlTextWriterWriteAttribute(writer, BAD_CAST "style:parent-style-name", BAD_CAST "Standard"); // Paragraph properties. xmlTextWriterStartElement(writer, BAD_CAST "style:paragraph-properties"); { if (lineheight != 100) { xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:line-height", "%d%%", lineheight); } if (!justification.empty()) { if (justification == LEFT) { justification = "start"; } else if (justification == RIGHT) { justification = "end"; } xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:text-align", BAD_CAST justification.c_str()); xmlTextWriterWriteAttribute(writer, BAD_CAST "style:justify-single-word", BAD_CAST "false"); } if (spacebefore != 0) { xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:margin-top", "%.1fmm", spacebefore); } if (spaceafter != 0) { xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:margin-bottom", "%.1fmm", spaceafter); } if (leftmargin != 0) { xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:margin-left", "%.1fmm", leftmargin); } if (rightmargin != 0) { xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:margin-right", "%.1fmm", rightmargin); } if (firstlineindent != 0) { xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:text-indent", "%.1fmm", firstlineindent); } // Starting odd pages is not supported in OpenDocument 1.0. if (startpage) { xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:break-before", BAD_CAST "page"); } // Spanning of columns is not implemented because that interferes with how // easily the text can be edited. } xmlTextWriterEndElement(writer); // Text properties. xmlTextWriterStartElement(writer, BAD_CAST "style:text-properties"); { xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:font-size", "%.1fpt", fontsize); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:font-size-asian", "%.1fpt", fontsize); xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:font-size-complex", "%.1fpt", fontsize); if (!fontname.empty()) { xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "style:font-name", "%s", fontname.c_str()); } if (italic == ON) { xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:font-style", BAD_CAST "italic"); xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:font-style-asian", BAD_CAST "italic"); xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:font-style-complex", BAD_CAST "italic"); } if (bold == ON) { xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:font-weight", BAD_CAST "bold"); xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:font-weight-asian", BAD_CAST "bold"); xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:font-weight-complex", BAD_CAST "bold"); } if (underline == ON) { xmlTextWriterWriteAttribute(writer, BAD_CAST "style:text-underline-style", BAD_CAST "solid"); xmlTextWriterWriteAttribute(writer, BAD_CAST "style:text-underline-width", BAD_CAST "auto"); xmlTextWriterWriteAttribute(writer, BAD_CAST "style:text-underline-color", BAD_CAST "font-color"); } if (smallcaps == ON) { xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:font-variant", BAD_CAST "small-caps"); } } xmlTextWriterEndElement(writer); } // Close style xmlTextWriterEndElement(writer); }
/* ========================================================================= */ static int writeState(xmlTextWriterPtr writer, ghmm_xmlfile* f, int moNo, int sNo) { #define CUR_PROC "writeState" int rc; double w_pi; char *w_desc=NULL; /* start state */ if (0 > xmlTextWriterStartElement(writer, BAD_CAST "state")) { GHMM_LOG(LERROR, "Error at xmlTextWriterStartElement (state)"); goto STOP; } /* write id attribute */ if (0 > xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "id", "%d", sNo)) GHMM_LOG(LERROR, "failed to write statte id attribute"); /* read state attribute from different model types */ switch (f->modelType & PTR_TYPE_MASK) { case GHMM_kDiscreteHMM: w_pi = f->model.d[moNo]->s[sNo].pi; w_desc = f->model.d[moNo]->s[sNo].desc; break; case (GHMM_kDiscreteHMM+GHMM_kTransitionClasses): w_pi = f->model.ds[moNo]->s[sNo].pi; w_desc = f->model.ds[moNo]->s[sNo].desc; break; case (GHMM_kDiscreteHMM+GHMM_kPairHMM): case (GHMM_kDiscreteHMM+GHMM_kPairHMM+GHMM_kTransitionClasses): /* w_pi = f->model.d[moNo]->s[sNo].pi; w_desc = f->model.d[moNo]->s[sNo]; */ break; case GHMM_kContinuousHMM: case (GHMM_kContinuousHMM+GHMM_kTransitionClasses): case (GHMM_kContinuousHMM+GHMM_kMultivariate): case (GHMM_kContinuousHMM+GHMM_kMultivariate+GHMM_kTransitionClasses): w_pi = f->model.c[moNo]->s[sNo].pi; w_desc = f->model.c[moNo]->s[sNo].desc; break; default: GHMM_LOG(LCRITIC, "invalid modelType");} /* write initial probability as attribute */ WRITE_DOUBLE_ATTRIBUTE(writer, "initial", w_pi); /* write state description */ if (w_desc) { if (xmlTextWriterWriteAttribute(writer, BAD_CAST "desc", BAD_CAST replaceXMLEntity(w_desc))) GHMM_LOG(LERROR, "writing state description failed"); } /* write state contents for different model types */ switch (f->modelType & PTR_TYPE_MASK) { case GHMM_kDiscreteHMM: rc = writeDiscreteStateContents(writer, f, moNo, sNo); break; case (GHMM_kDiscreteHMM+GHMM_kTransitionClasses): rc = writeDiscreteSwitchingStateContents(writer, f, moNo, sNo); break; case (GHMM_kDiscreteHMM+GHMM_kPairHMM): case (GHMM_kDiscreteHMM+GHMM_kPairHMM+GHMM_kTransitionClasses): /* rc = writeDiscretePairStateContents(writer, f, moNo, sNo); */ break; case GHMM_kContinuousHMM: case (GHMM_kContinuousHMM+GHMM_kTransitionClasses): case (GHMM_kContinuousHMM+GHMM_kMultivariate): case (GHMM_kContinuousHMM+GHMM_kMultivariate+GHMM_kTransitionClasses): rc = writeContinuousStateContents(writer, f, moNo, sNo); break; default: GHMM_LOG(LCRITIC, "invalid modelType"); goto STOP; } if (rc) { GHMM_LOG_PRINTF(LERROR, LOC, "writing state contents failed. model_type = %s", strModeltype(f->modelType & PTR_TYPE_MASK)); goto STOP; } /* end state*/ if (0 > xmlTextWriterEndElement(writer)) { GHMM_LOG(LERROR, "Error at xmlTextWriterEndElement (state)"); goto STOP; } return 0; STOP: return -1; #undef CUR_PROC }
/* ========================================================================= */ static int writeHMM(xmlTextWriterPtr writer, ghmm_xmlfile* f, int number) { #define CUR_PROC "writeHMM" int rc=0, i, N; int w_cos; double w_prior; char *w_name; char * w_type; /* start HMM */ if (0 > xmlTextWriterStartElement(writer, BAD_CAST "HMM")) { GHMM_LOG(LERROR, "Error at xmlTextWriterStartElement (HMM)"); goto STOP;; } /* write HMM attributes applicable */ switch (f->modelType & PTR_TYPE_MASK) { case GHMM_kDiscreteHMM: w_name = f->model.d[number]->name; w_type = strModeltype(f->model.d[number]->model_type); w_prior = f->model.d[number]->prior; N = f->model.d[number]->N; w_cos = 1; break; case (GHMM_kDiscreteHMM+GHMM_kTransitionClasses): w_name = f->model.ds[number]->name; w_type = strModeltype(f->model.ds[number]->model_type); w_prior = f->model.ds[number]->prior; N = f->model.ds[number]->N; w_cos = 0; break; case (GHMM_kDiscreteHMM+GHMM_kPairHMM): case (GHMM_kDiscreteHMM+GHMM_kPairHMM+GHMM_kTransitionClasses): /* w_name = f->model.dp[number]->name; w_type = strModeltype(f->model.dp[number]->model_type); w_prior = f->model.dp[number]->prior; N = f->model.dp[number]->N; w_cos = 0; */ break; case GHMM_kContinuousHMM: case (GHMM_kContinuousHMM+GHMM_kMultivariate): case (GHMM_kContinuousHMM+GHMM_kTransitionClasses): case (GHMM_kContinuousHMM+GHMM_kMultivariate+GHMM_kTransitionClasses): w_name = f->model.c[number]->name; if (f->model.c[number]->model_type) w_type = strModeltype(f->model.c[number]->model_type); else w_type = strModeltype(f->modelType); w_prior = f->model.c[number]->prior; N = f->model.c[number]->N; w_cos = f->model.c[number]->cos; break; default: GHMM_LOG(LERROR, "invalid modelType"); goto STOP;} if (w_name) { if (xmlTextWriterWriteAttribute(writer, BAD_CAST "name", w_name)) GHMM_LOG(LERROR, "writing HMM name failed"); } if (xmlTextWriterWriteAttribute(writer, BAD_CAST "type", BAD_CAST w_type)) GHMM_LOG(LERROR, "writing HMM type failed"); if (w_prior >= 0.0) { WRITE_DOUBLE_ATTRIBUTE(writer, "prior", w_prior); } if (w_cos > 1) if (0 > xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "transitionClasses", "%d", w_cos)) GHMM_LOG(LERROR, "failed to write no of transitionClasses"); /* write alphabet if applicable */ switch (f->modelType & (GHMM_kDiscreteHMM + GHMM_kTransitionClasses + GHMM_kPairHMM)) { case GHMM_kDiscreteHMM: rc = writeAlphabet(writer, f->model.d[number]->alphabet, kAlphabet); break; case (GHMM_kDiscreteHMM+GHMM_kTransitionClasses): /*rc = writeAlphabet(writer, f->model.ds[number]->alphabet, kAlphabet);*/ break; case (GHMM_kDiscreteHMM+GHMM_kPairHMM): case (GHMM_kDiscreteHMM+GHMM_kPairHMM+GHMM_kTransitionClasses): /*rc = writeAlphabet(writer, f->model.dp[number]->alphabets[0], kAlphabet); if (rc) { GHMM_LOG(LERROR, "writing first alphabet of discrete pair HMM failed"); goto STOP; } rc = writeAlphabet(writer, f->model.dp[number]->alphabets[1], kAlphabet);*/ break; } if (rc) { GHMM_LOG_PRINTF(LERROR, LOC, "writing alphabet for HMM %d (type %s) failed", number, strModeltype(f->modelType)); goto STOP; } /* write label alphabet if applicable */ if ((f->modelType & PTR_TYPE_MASK) == GHMM_kDiscreteHMM && f->modelType & GHMM_kLabeledStates) { if (writeAlphabet(writer, f->model.d[number]->label_alphabet, kLabelAlphabet)) GHMM_LOG(LERROR, "writing of label alphabet failed"); } /* write background distributions if applicable */ if ((f->modelType & PTR_TYPE_MASK) == GHMM_kDiscreteHMM && f->modelType & GHMM_kBackgroundDistributions) { if (writeBackground(writer, f->model.d[number]->bp)) GHMM_LOG(LERROR, "writing of background distributions failed"); } /* write all states */ for (i=0; i<N; i++) if (writeState(writer, f, number, i)) { GHMM_LOG_PRINTF(LERROR, LOC, "writing of state %d in HMM %d failed", i, number); goto STOP; } /* write all outgoing transitions */ for (i=0; i<N; i++) if (writeTransition(writer, f, number, i)) { GHMM_LOG_PRINTF(LERROR, LOC, "writing transitions of state %d in HMM %d failed", i, number); goto STOP; } /*end HMM*/ if (0 > xmlTextWriterEndElement(writer)) { GHMM_LOG(LERROR, "Error at xmlTextWriterEndElement (HMM)"); goto STOP; } return 0; STOP: return -1; #undef CUR_PROC }
static isc_result_t generatexml(ns_server_t *server, int *buflen, xmlChar **buf) { char boottime[sizeof "yyyy-mm-ddThh:mm:ssZ"]; char nowstr[sizeof "yyyy-mm-ddThh:mm:ssZ"]; isc_time_t now; xmlTextWriterPtr writer = NULL; xmlDocPtr doc = NULL; int xmlrc; dns_view_t *view; stats_dumparg_t dumparg; dns_stats_t *cachestats; isc_uint64_t nsstat_values[dns_nsstatscounter_max]; isc_uint64_t resstat_values[dns_resstatscounter_max]; isc_uint64_t zonestat_values[dns_zonestatscounter_max]; isc_uint64_t sockstat_values[isc_sockstatscounter_max]; isc_result_t result; isc_time_now(&now); isc_time_formatISO8601(&ns_g_boottime, boottime, sizeof boottime); isc_time_formatISO8601(&now, nowstr, sizeof nowstr); writer = xmlNewTextWriterDoc(&doc, 0); if (writer == NULL) goto error; TRY0(xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL)); TRY0(xmlTextWriterWritePI(writer, ISC_XMLCHAR "xml-stylesheet", ISC_XMLCHAR "type=\"text/xsl\" href=\"/bind9.xsl\"")); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "isc")); TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "version", ISC_XMLCHAR "1.0")); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "bind")); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "statistics")); TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "version", ISC_XMLCHAR "2.2")); /* Set common fields for statistics dump */ dumparg.type = statsformat_xml; dumparg.arg = writer; /* * Start by rendering the views we know of here. For each view we * know of, call its rendering function. */ view = ISC_LIST_HEAD(server->viewlist); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "views")); while (view != NULL) { TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "view")); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "name")); TRY0(xmlTextWriterWriteString(writer, ISC_XMLCHAR view->name)); TRY0(xmlTextWriterEndElement(writer)); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "zones")); result = dns_zt_apply(view->zonetable, ISC_TRUE, zone_xmlrender, writer); if (result != ISC_R_SUCCESS) goto error; TRY0(xmlTextWriterEndElement(writer)); if (view->resquerystats != NULL) { dumparg.result = ISC_R_SUCCESS; dns_rdatatypestats_dump(view->resquerystats, rdtypestat_dump, &dumparg, 0); if (dumparg.result != ISC_R_SUCCESS) goto error; } if (view->resstats != NULL) { result = dump_counters(view->resstats, statsformat_xml, writer, "resstat", resstats_xmldesc, dns_resstatscounter_max, resstats_index, resstat_values, ISC_STATSDUMP_VERBOSE); if (result != ISC_R_SUCCESS) goto error; } cachestats = dns_db_getrrsetstats(view->cachedb); if (cachestats != NULL) { TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "cache")); TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "name", ISC_XMLCHAR dns_cache_getname(view->cache))); dumparg.result = ISC_R_SUCCESS; dns_rdatasetstats_dump(cachestats, rdatasetstats_dump, &dumparg, 0); if (dumparg.result != ISC_R_SUCCESS) goto error; TRY0(xmlTextWriterEndElement(writer)); /* cache */ } TRY0(xmlTextWriterEndElement(writer)); /* view */ view = ISC_LIST_NEXT(view, link); } TRY0(xmlTextWriterEndElement(writer)); /* views */ TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "socketmgr")); isc_socketmgr_renderxml(ns_g_socketmgr, writer); TRY0(xmlTextWriterEndElement(writer)); /* socketmgr */ TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "taskmgr")); isc_taskmgr_renderxml(ns_g_taskmgr, writer); TRY0(xmlTextWriterEndElement(writer)); /* taskmgr */ TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "server")); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "boot-time")); TRY0(xmlTextWriterWriteString(writer, ISC_XMLCHAR boottime)); TRY0(xmlTextWriterEndElement(writer)); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "current-time")); TRY0(xmlTextWriterWriteString(writer, ISC_XMLCHAR nowstr)); TRY0(xmlTextWriterEndElement(writer)); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "requests")); dumparg.result = ISC_R_SUCCESS; dns_opcodestats_dump(server->opcodestats, opcodestat_dump, &dumparg, 0); if (dumparg.result != ISC_R_SUCCESS) goto error; TRY0(xmlTextWriterEndElement(writer)); /* requests */ TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "queries-in")); dumparg.result = ISC_R_SUCCESS; dns_rdatatypestats_dump(server->rcvquerystats, rdtypestat_dump, &dumparg, 0); if (dumparg.result != ISC_R_SUCCESS) goto error; TRY0(xmlTextWriterEndElement(writer)); /* queries-in */ result = dump_counters(server->nsstats, statsformat_xml, writer, "nsstat", nsstats_xmldesc, dns_nsstatscounter_max, nsstats_index, nsstat_values, ISC_STATSDUMP_VERBOSE); if (result != ISC_R_SUCCESS) goto error; result = dump_counters(server->zonestats, statsformat_xml, writer, "zonestat", zonestats_xmldesc, dns_zonestatscounter_max, zonestats_index, zonestat_values, ISC_STATSDUMP_VERBOSE); if (result != ISC_R_SUCCESS) goto error; /* * Most of the common resolver statistics entries are 0, so we don't * use the verbose dump here. */ result = dump_counters(server->resolverstats, statsformat_xml, writer, "resstat", resstats_xmldesc, dns_resstatscounter_max, resstats_index, resstat_values, 0); if (result != ISC_R_SUCCESS) goto error; result = dump_counters(server->sockstats, statsformat_xml, writer, "sockstat", sockstats_xmldesc, isc_sockstatscounter_max, sockstats_index, sockstat_values, ISC_STATSDUMP_VERBOSE); if (result != ISC_R_SUCCESS) goto error; TRY0(xmlTextWriterEndElement(writer)); /* server */ TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "memory")); isc_mem_renderxml(writer); TRY0(xmlTextWriterEndElement(writer)); /* memory */ TRY0(xmlTextWriterEndElement(writer)); /* statistics */ TRY0(xmlTextWriterEndElement(writer)); /* bind */ TRY0(xmlTextWriterEndElement(writer)); /* isc */ TRY0(xmlTextWriterEndDocument(writer)); xmlFreeTextWriter(writer); xmlDocDumpFormatMemoryEnc(doc, buf, buflen, "UTF-8", 1); xmlFreeDoc(doc); return (ISC_R_SUCCESS); error: if (writer != NULL) xmlFreeTextWriter(writer); if (doc != NULL) xmlFreeDoc(doc); return (ISC_R_FAILURE); }
static char * create_resource_list_xml(const LinphoneFriendList *list) { char *xml_content = NULL; MSList *elem; xmlBufferPtr buf; xmlTextWriterPtr writer; int err; if (ms_list_size(list->friends) <= 0) return NULL; buf = xmlBufferCreate(); if (buf == NULL) { ms_error("%s: Error creating the XML buffer", __FUNCTION__); return NULL; } writer = xmlNewTextWriterMemory(buf, 0); if (writer == NULL) { ms_error("%s: Error creating the XML writer", __FUNCTION__); return NULL; } xmlTextWriterSetIndent(writer,1); err = xmlTextWriterStartDocument(writer, "1.0", "UTF-8", NULL); if (err >= 0) { err = xmlTextWriterStartElementNS(writer, NULL, (const xmlChar *)"resource-lists", (const xmlChar *)"urn:ietf:params:xml:ns:resource-lists"); } if (err >= 0) { err = xmlTextWriterWriteAttributeNS(writer, (const xmlChar *)"xmlns", (const xmlChar *)"xsi", NULL, (const xmlChar *)"http://www.w3.org/2001/XMLSchema-instance"); } if (err>= 0) { err = xmlTextWriterStartElement(writer, (const xmlChar *)"list"); } for (elem = list->friends; elem != NULL; elem = elem->next) { LinphoneFriend *friend = (LinphoneFriend *)elem->data; char *uri = linphone_address_as_string_uri_only(friend->uri); if (err >= 0) { err = xmlTextWriterStartElement(writer, (const xmlChar *)"entry"); } if (err >= 0) { err = xmlTextWriterWriteAttribute(writer, (const xmlChar *)"uri", (const xmlChar *)uri); } if (err >= 0) { /* Close the "entry" element. */ err = xmlTextWriterEndElement(writer); } if (uri) ms_free(uri); } if (err >= 0) { /* Close the "list" element. */ err = xmlTextWriterEndElement(writer); } if (err >= 0) { /* Close the "resource-lists" element. */ err = xmlTextWriterEndElement(writer); } if (err >= 0) { err = xmlTextWriterEndDocument(writer); } if (err > 0) { /* xmlTextWriterEndDocument returns the size of the content. */ xml_content = ms_strdup((char *)buf->content); } xmlFreeTextWriter(writer); xmlBufferFree(buf); return xml_content; }
/** * testXmlwriterFilename: * @uri: the output URI * * test the xmlWriter interface when writing to a new file */ void testXmlwriterFilename(const char *uri) { int rc; xmlTextWriterPtr writer; xmlChar *tmp; /* Create a new XmlWriter for uri, with no compression. */ writer = xmlNewTextWriterFilename(uri, 0); if (writer == NULL) { printf("testXmlwriterFilename: Error creating the xml writer\n"); return; } /* Start the document with the xml default for the version, * encoding ISO 8859-1 and the default for the standalone * declaration. */ rc = xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL); if (rc < 0) { printf ("testXmlwriterFilename: Error at xmlTextWriterStartDocument\n"); return; } /* Start an element named "EXAMPLE". Since thist is the first * element, this will be the root element of the document. */ rc = xmlTextWriterStartElement(writer, BAD_CAST "EXAMPLE"); if (rc < 0) { printf ("testXmlwriterFilename: Error at xmlTextWriterStartElement\n"); return; } /* Write a comment as child of EXAMPLE. * Please observe, that the input to the xmlTextWriter functions * HAS to be in UTF-8, even if the output XML is encoded * in iso-8859-1 */ tmp = ConvertInput("This is a comment with special chars: <äöü>", MY_ENCODING); rc = xmlTextWriterWriteComment(writer, tmp); if (rc < 0) { printf ("testXmlwriterFilename: Error at xmlTextWriterWriteComment\n"); return; } if (tmp != NULL) xmlFree(tmp); /* Start an element named "ORDER" as child of EXAMPLE. */ rc = xmlTextWriterStartElement(writer, BAD_CAST "ORDER"); if (rc < 0) { printf ("testXmlwriterFilename: Error at xmlTextWriterStartElement\n"); return; } /* Add an attribute with name "version" and value "1.0" to ORDER. */ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "version", BAD_CAST "1.0"); if (rc < 0) { printf ("testXmlwriterFilename: Error at xmlTextWriterWriteAttribute\n"); return; } /* Add an attribute with name "xml:lang" and value "de" to ORDER. */ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang", BAD_CAST "de"); if (rc < 0) { printf ("testXmlwriterFilename: Error at xmlTextWriterWriteAttribute\n"); return; } /* Write a comment as child of ORDER */ tmp = ConvertInput("<äöü>", MY_ENCODING); rc = xmlTextWriterWriteFormatComment(writer, "This is another comment with special chars: %s", tmp); if (rc < 0) { printf ("testXmlwriterFilename: Error at xmlTextWriterWriteFormatComment\n"); return; } if (tmp != NULL) xmlFree(tmp); /* Start an element named "HEADER" as child of ORDER. */ rc = xmlTextWriterStartElement(writer, BAD_CAST "HEADER"); if (rc < 0) { printf ("testXmlwriterFilename: Error at xmlTextWriterStartElement\n"); return; } /* Write an element named "X_ORDER_ID" as child of HEADER. */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "X_ORDER_ID", "%010d", 53535); if (rc < 0) { printf ("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Write an element named "CUSTOMER_ID" as child of HEADER. */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "CUSTOMER_ID", "%d", 1010); if (rc < 0) { printf ("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Write an element named "NAME_1" as child of HEADER. */ tmp = ConvertInput("Müller", MY_ENCODING); rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1", tmp); if (rc < 0) { printf ("testXmlwriterFilename: Error at xmlTextWriterWriteElement\n"); return; } if (tmp != NULL) xmlFree(tmp); /* Write an element named "NAME_2" as child of HEADER. */ tmp = ConvertInput("Jörg", MY_ENCODING); rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2", tmp); if (rc < 0) { printf ("testXmlwriterFilename: Error at xmlTextWriterWriteElement\n"); return; } if (tmp != NULL) xmlFree(tmp); /* Close the element named HEADER. */ rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf ("testXmlwriterFilename: Error at xmlTextWriterEndElement\n"); return; } /* Start an element named "ENTRIES" as child of ORDER. */ rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRIES"); if (rc < 0) { printf ("testXmlwriterFilename: Error at xmlTextWriterStartElement\n"); return; } /* Start an element named "ENTRY" as child of ENTRIES. */ rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRY"); if (rc < 0) { printf ("testXmlwriterFilename: Error at xmlTextWriterStartElement\n"); return; } /* Write an element named "ARTICLE" as child of ENTRY. */ rc = xmlTextWriterWriteElement(writer, BAD_CAST "ARTICLE", BAD_CAST "<Test>"); if (rc < 0) { printf ("testXmlwriterFilename: Error at xmlTextWriterWriteElement\n"); return; } /* Write an element named "ENTRY_NO" as child of ENTRY. */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ENTRY_NO", "%d", 10); if (rc < 0) { printf ("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Close the element named ENTRY. */ rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf ("testXmlwriterFilename: Error at xmlTextWriterEndElement\n"); return; } /* Start an element named "ENTRY" as child of ENTRIES. */ rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRY"); if (rc < 0) { printf ("testXmlwriterFilename: Error at xmlTextWriterStartElement\n"); return; } /* Write an element named "ARTICLE" as child of ENTRY. */ rc = xmlTextWriterWriteElement(writer, BAD_CAST "ARTICLE", BAD_CAST "<Test 2>"); if (rc < 0) { printf ("testXmlwriterFilename: Error at xmlTextWriterWriteElement\n"); return; } /* Write an element named "ENTRY_NO" as child of ENTRY. */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ENTRY_NO", "%d", 20); if (rc < 0) { printf ("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Close the element named ENTRY. */ rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf ("testXmlwriterFilename: Error at xmlTextWriterEndElement\n"); return; } /* Close the element named ENTRIES. */ rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf ("testXmlwriterFilename: Error at xmlTextWriterEndElement\n"); return; } /* Start an element named "FOOTER" as child of ORDER. */ rc = xmlTextWriterStartElement(writer, BAD_CAST "FOOTER"); if (rc < 0) { printf ("testXmlwriterFilename: Error at xmlTextWriterStartElement\n"); return; } /* Write an element named "TEXT" as child of FOOTER. */ rc = xmlTextWriterWriteElement(writer, BAD_CAST "TEXT", BAD_CAST "This is a text."); if (rc < 0) { printf ("testXmlwriterFilename: Error at xmlTextWriterWriteElement\n"); return; } /* Close the element named FOOTER. */ rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf ("testXmlwriterFilename: Error at xmlTextWriterEndElement\n"); return; } /* Here we could close the elements ORDER and EXAMPLE using the * function xmlTextWriterEndElement, but since we do not want to * write any other elements, we simply call xmlTextWriterEndDocument, * which will do all the work. */ rc = xmlTextWriterEndDocument(writer); if (rc < 0) { printf ("testXmlwriterFilename: Error at xmlTextWriterEndDocument\n"); return; } xmlFreeTextWriter(writer); }
void XMLExporter::writeSlotAttributes(const std::string &_name, const std::string &_var) { xmlTextWriterWriteAttribute(m_writer, BAD_CAST "name", BAD_CAST _name.c_str()); xmlTextWriterWriteAttribute(m_writer, BAD_CAST "var", BAD_CAST _var.c_str()); }
/** * testXmlwriterTree: * @file: the output file * * test the xmlWriter interface when writing to a subtree */ void testXmlwriterTree(const char *file) { int rc; xmlTextWriterPtr writer; xmlDocPtr doc; xmlNodePtr node; xmlChar *tmp; /* Create a new XML DOM tree, to which the XML document will be * written */ doc = xmlNewDoc(BAD_CAST XML_DEFAULT_VERSION); if (doc == NULL) { printf ("testXmlwriterTree: Error creating the xml document tree\n"); return; } /* Create a new XML node, to which the XML document will be * appended */ node = xmlNewDocNode(doc, NULL, BAD_CAST "EXAMPLE", NULL); if (node == NULL) { printf("testXmlwriterTree: Error creating the xml node\n"); return; } /* Make ELEMENT the root node of the tree */ xmlDocSetRootElement(doc, node); /* Create a new XmlWriter for DOM tree, with no compression. */ writer = xmlNewTextWriterTree(doc, node, 0); if (writer == NULL) { printf("testXmlwriterTree: Error creating the xml writer\n"); return; } /* Start the document with the xml default for the version, * encoding ISO 8859-1 and the default for the standalone * declaration. */ rc = xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterStartDocument\n"); return; } /* Write a comment as child of EXAMPLE. * Please observe, that the input to the xmlTextWriter functions * HAS to be in UTF-8, even if the output XML is encoded * in iso-8859-1 */ tmp = ConvertInput("This is a comment with special chars: <äöü>", MY_ENCODING); rc = xmlTextWriterWriteComment(writer, tmp); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterWriteComment\n"); return; } if (tmp != NULL) xmlFree(tmp); /* Start an element named "ORDER" as child of EXAMPLE. */ rc = xmlTextWriterStartElement(writer, BAD_CAST "ORDER"); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterStartElement\n"); return; } /* Add an attribute with name "version" and value "1.0" to ORDER. */ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "version", BAD_CAST "1.0"); if (rc < 0) { printf ("testXmlwriterTree: Error at xmlTextWriterWriteAttribute\n"); return; } /* Add an attribute with name "xml:lang" and value "de" to ORDER. */ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang", BAD_CAST "de"); if (rc < 0) { printf ("testXmlwriterTree: Error at xmlTextWriterWriteAttribute\n"); return; } /* Write a comment as child of ORDER */ tmp = ConvertInput("<äöü>", MY_ENCODING); rc = xmlTextWriterWriteFormatComment(writer, "This is another comment with special chars: %s", tmp); if (rc < 0) { printf ("testXmlwriterTree: Error at xmlTextWriterWriteFormatComment\n"); return; } if (tmp != NULL) xmlFree(tmp); /* Start an element named "HEADER" as child of ORDER. */ rc = xmlTextWriterStartElement(writer, BAD_CAST "HEADER"); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterStartElement\n"); return; } /* Write an element named "X_ORDER_ID" as child of HEADER. */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "X_ORDER_ID", "%010d", 53535); if (rc < 0) { printf ("testXmlwriterTree: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Write an element named "CUSTOMER_ID" as child of HEADER. */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "CUSTOMER_ID", "%d", 1010); if (rc < 0) { printf ("testXmlwriterTree: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Write an element named "NAME_1" as child of HEADER. */ tmp = ConvertInput("Müller", MY_ENCODING); rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1", tmp); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterWriteElement\n"); return; } if (tmp != NULL) xmlFree(tmp); /* Write an element named "NAME_2" as child of HEADER. */ tmp = ConvertInput("Jörg", MY_ENCODING); rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2", tmp); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterWriteElement\n"); return; } if (tmp != NULL) xmlFree(tmp); /* Close the element named HEADER. */ rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterEndElement\n"); return; } /* Start an element named "ENTRIES" as child of ORDER. */ rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRIES"); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterStartElement\n"); return; } /* Start an element named "ENTRY" as child of ENTRIES. */ rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRY"); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterStartElement\n"); return; } /* Write an element named "ARTICLE" as child of ENTRY. */ rc = xmlTextWriterWriteElement(writer, BAD_CAST "ARTICLE", BAD_CAST "<Test>"); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterWriteElement\n"); return; } /* Write an element named "ENTRY_NO" as child of ENTRY. */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ENTRY_NO", "%d", 10); if (rc < 0) { printf ("testXmlwriterTree: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Close the element named ENTRY. */ rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterEndElement\n"); return; } /* Start an element named "ENTRY" as child of ENTRIES. */ rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRY"); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterStartElement\n"); return; } /* Write an element named "ARTICLE" as child of ENTRY. */ rc = xmlTextWriterWriteElement(writer, BAD_CAST "ARTICLE", BAD_CAST "<Test 2>"); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterWriteElement\n"); return; } /* Write an element named "ENTRY_NO" as child of ENTRY. */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ENTRY_NO", "%d", 20); if (rc < 0) { printf ("testXmlwriterTree: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Close the element named ENTRY. */ rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterEndElement\n"); return; } /* Close the element named ENTRIES. */ rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterEndElement\n"); return; } /* Start an element named "FOOTER" as child of ORDER. */ rc = xmlTextWriterStartElement(writer, BAD_CAST "FOOTER"); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterStartElement\n"); return; } /* Write an element named "TEXT" as child of FOOTER. */ rc = xmlTextWriterWriteElement(writer, BAD_CAST "TEXT", BAD_CAST "This is a text."); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterWriteElement\n"); return; } /* Close the element named FOOTER. */ rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterEndElement\n"); return; } /* Here we could close the elements ORDER and EXAMPLE using the * function xmlTextWriterEndElement, but since we do not want to * write any other elements, we simply call xmlTextWriterEndDocument, * which will do all the work. */ rc = xmlTextWriterEndDocument(writer); if (rc < 0) { printf("testXmlwriterTree: Error at xmlTextWriterEndDocument\n"); return; } xmlFreeTextWriter(writer); xmlSaveFileEnc(file, doc, MY_ENCODING); xmlFreeDoc(doc); }
int output_log_xml_process(struct event *evt, void *obj) { struct output_log_xml_priv *priv = obj; struct event_reg_info *evt_info = event_get_info(evt); xmlBufferPtr buff = xmlBufferCreate(); if (!buff) { pomlog(POMLOG_ERR "Error while creating the xml buffer"); return POM_ERR; } xmlTextWriterPtr writer = xmlNewTextWriterMemory(buff, 0); if (!writer) { pomlog(POMLOG_ERR "Error while creating the xmlTextWriter"); xmlBufferFree(buff); return POM_ERR; } // <event name="event_name"> char timestamp[21] = { 0 }; snprintf(timestamp, 20, "%"PRIu64, (uint64_t) event_get_timestamp(evt)); if (xmlTextWriterWriteString(writer, BAD_CAST "\n") < 0 || xmlTextWriterStartElement(writer, BAD_CAST "event") < 0 || xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST evt_info->name) < 0 || xmlTextWriterWriteAttribute(writer, BAD_CAST "timestamp", BAD_CAST timestamp) < 0) goto err; struct data *evt_data = event_get_data(evt); int i; for (i = 0; i < evt_info->data_reg->data_count; i++) { if (evt_info->data_reg->items[i].flags & DATA_REG_FLAG_LIST) { // Got a data_list if (!evt_data[i].items) continue; // <data_list name="data_name"> if (xmlTextWriterWriteString(writer, BAD_CAST "\n\t") < 0 || xmlTextWriterStartElement(writer, BAD_CAST "data_list") < 0 || xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST evt_info->data_reg->items[i].name) < 0) goto err; // <value key="key1"> struct data_item *itm = evt_data[i].items; for (; itm; itm = itm->next) { if (xmlTextWriterWriteString(writer, BAD_CAST "\n\t\t") < 0 || xmlTextWriterStartElement(writer, BAD_CAST "value") < 0 || xmlTextWriterWriteAttribute(writer, BAD_CAST "key", BAD_CAST itm->key) < 0) goto err; char *value = ptype_print_val_alloc(itm->value, NULL); if (!value) goto err; if (xmlTextWriterWriteString(writer, BAD_CAST value) < 0) { free(value); goto err; } free(value); // </value> if (xmlTextWriterEndElement(writer) < 0) goto err; } // </data_list> if (xmlTextWriterWriteString(writer, BAD_CAST "\n\t") < 0 || xmlTextWriterEndElement(writer) < 0) goto err; } else { // Got a single data if (!data_is_set(evt_data[i])) continue; // <data name="data_name"> if (xmlTextWriterWriteString(writer, BAD_CAST "\n\t") < 0 || xmlTextWriterStartElement(writer, BAD_CAST "data") < 0 || xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST evt_info->data_reg->items[i].name) < 0) goto err; if (evt_data[i].value) { char *value = ptype_print_val_alloc(evt_data[i].value, NULL); if (!value) goto err; if (xmlTextWriterWriteString(writer, BAD_CAST value) < 0) { free(value); goto err; } free(value); } // </data> if (xmlTextWriterEndElement(writer) < 0) goto err; } } // </event> if (xmlTextWriterWriteString(writer, BAD_CAST "\n") < 0 || xmlTextWriterEndElement(writer) < 0 || xmlTextWriterWriteString(writer, BAD_CAST "\n") < 0) goto err; xmlFreeTextWriter(writer); if (pom_write(priv->fd, buff->content, buff->use) != POM_OK) { pomlog(POMLOG_ERR "Error while writing to the log file"); xmlBufferFree(buff); return POM_ERR; } xmlBufferFree(buff); if (priv->perf_events) registry_perf_inc(priv->perf_events, 1); return POM_OK; err: pomlog(POMLOG_ERR "An error occured while processing the event"); xmlFreeTextWriter(writer); xmlBufferFree(buff); return POM_ERR; }
void CSaveSceneView::SceneNodeExplore(Ogre::SceneNode *SceneNode) { Ogre::Entity *Entity = NULL; Ogre::Camera *Camera = NULL; Ogre::Light *Light = NULL; Ogre::ParticleSystem *ParticleSystem = NULL; Ogre::ManualObject *ManualObject = NULL; Ogre::BillboardSet *BillboardSet = NULL; xmlTextWriterStartElement(m_XmlWriter, BAD_CAST "SceneNode"); Ogre::String SceneNodeName = SceneNode->getName(); xmlTextWriterWriteAttribute(m_XmlWriter, BAD_CAST "SceneNodeName", BAD_CAST SceneNodeName.c_str()); Ogre::SceneNode::ObjectIterator obji = SceneNode->getAttachedObjectIterator(); while (obji.hasMoreElements()) { Ogre::MovableObject* mobj = obji.getNext(); Ogre::String Type = mobj->getMovableType(); if (Type == "Entity") { Entity = (Ogre::Entity *)(mobj); Ogre::String EntityName = Entity->getName(); xmlTextWriterStartElement(m_XmlWriter, BAD_CAST "Entity"); xmlTextWriterWriteAttribute(m_XmlWriter, BAD_CAST "EntityName", BAD_CAST EntityName.c_str()); Ogre::MeshPtr Mesh = Entity->getMesh(); Ogre::String MeshName = Mesh->getName(); xmlTextWriterWriteAttribute(m_XmlWriter, BAD_CAST "MeshName", BAD_CAST MeshName.c_str()); xmlTextWriterEndElement(m_XmlWriter); } if (Type == "Camera") { Camera = (Ogre::Camera *)(mobj); Ogre::String CameraName = Camera->getName(); xmlTextWriterStartElement(m_XmlWriter, BAD_CAST "Camera"); xmlTextWriterWriteAttribute(m_XmlWriter, BAD_CAST "CameraName", BAD_CAST CameraName.c_str()); Ogre::Vector3 CameraPosition = Camera->getPosition(); xmlTextWriterWriteFormatAttribute(m_XmlWriter, BAD_CAST "XPosition", "%f",CameraPosition.x); xmlTextWriterWriteFormatAttribute(m_XmlWriter, BAD_CAST "YPosition", "%f",CameraPosition.y); xmlTextWriterWriteFormatAttribute(m_XmlWriter, BAD_CAST "ZPosition", "%f",CameraPosition.z); Ogre::Vector3 CameraDirection = Camera->getDirection(); xmlTextWriterWriteFormatAttribute(m_XmlWriter, BAD_CAST "XDirection", "%f",CameraDirection.x); xmlTextWriterWriteFormatAttribute(m_XmlWriter, BAD_CAST "YDirection", "%f",CameraDirection.y); xmlTextWriterWriteFormatAttribute(m_XmlWriter, BAD_CAST "ZDirection", "%f",CameraDirection.z); xmlTextWriterEndElement(m_XmlWriter); } if (Type == "Light") { Light = (Ogre::Light *)(mobj); } if (Type == "ParticleSystem") { ParticleSystem = (Ogre::ParticleSystem *)(mobj); } if (Type == "ManualObject") { ManualObject = (Ogre::ManualObject *)(mobj); } if (Type == "BillboardSet") { BillboardSet = (Ogre::BillboardSet *)(mobj); } } Ogre::Node::ChildNodeIterator nodei = SceneNode->getChildIterator(); while (nodei.hasMoreElements()) { Ogre::SceneNode* node = (Ogre::SceneNode*)(nodei.getNext()); // Add this subnode and its children... SceneNodeExplore(node); } xmlTextWriterEndElement(m_XmlWriter); //end SceneNode }
static void clock_component_def_real_save_properties (ComponentDef* base, xmlTextWriter* xmlWriter, PropertySet* configurationProperty) { ClockComponentDef * self; gint onFor = 0; gint offFor = 0; xmlTextWriter* _tmp6_; gint _tmp7_; gchar* _tmp8_ = NULL; gchar* _tmp9_; xmlTextWriter* _tmp10_; gint _tmp11_; gchar* _tmp12_ = NULL; gchar* _tmp13_; GError * _inner_error_ = NULL; self = (ClockComponentDef*) base; g_return_if_fail (xmlWriter != NULL); g_return_if_fail (configurationProperty != NULL); { PropertySet* _tmp0_; gint _tmp1_ = 0; gint _tmp2_; _tmp0_ = configurationProperty; _tmp1_ = property_item_int_get_data_throw (_tmp0_, "On For", &_inner_error_); _tmp2_ = _tmp1_; if (_inner_error_ != NULL) { goto __catch16_g_error; } onFor = _tmp2_; } goto __finally16; __catch16_g_error: { g_clear_error (&_inner_error_); _inner_error_ = NULL; onFor = 25; } __finally16: if (_inner_error_ != NULL) { g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return; } { PropertySet* _tmp3_; gint _tmp4_ = 0; gint _tmp5_; _tmp3_ = configurationProperty; _tmp4_ = property_item_int_get_data_throw (_tmp3_, "Off For", &_inner_error_); _tmp5_ = _tmp4_; if (_inner_error_ != NULL) { goto __catch17_g_error; } offFor = _tmp5_; } goto __finally17; __catch17_g_error: { g_clear_error (&_inner_error_); _inner_error_ = NULL; offFor = 25; } __finally17: if (_inner_error_ != NULL) { g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return; } _tmp6_ = xmlWriter; _tmp7_ = onFor; _tmp8_ = g_strdup_printf ("%i", _tmp7_); _tmp9_ = _tmp8_; xmlTextWriterWriteAttribute (_tmp6_, "on", _tmp9_); _g_free0 (_tmp9_); _tmp10_ = xmlWriter; _tmp11_ = offFor; _tmp12_ = g_strdup_printf ("%i", _tmp11_); _tmp13_ = _tmp12_; xmlTextWriterWriteAttribute (_tmp10_, "off", _tmp13_); _g_free0 (_tmp13_); }
/* ========================================================================= */ void ghmm_xmlfile_write(ghmm_xmlfile* f, const char *file) { #define CUR_PROC "ghmm_xmlfile_write" int rc, i; xmlTextWriterPtr writer; xmlDocPtr doc; /* * this initialize the library and check potential ABI mismatches * between the version it was compiled for and the actual shared * library used. */ LIBXML_TEST_VERSION xmlSubstituteEntitiesDefault(1); /* Create a new XmlWriter for DOM, with no compression. */ writer = xmlNewTextWriterDoc(&doc, 0); if (writer == NULL) { GHMM_LOG(LERROR, "can not create the xml writer"); goto STOP; } /* indenting writer to circumvent no space between SYSTEM and PUBLIC identifier */ xmlTextWriterSetIndent(writer, 1); /* Start the document with the xml default for the version, * encoding ISO 8859-1 and the default for the standalone * declaration. */ rc = xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL); if (rc < 0) { GHMM_LOG(LERROR, "Error at xmlTextWriterStartDocument\n"); goto STOP; } /* Set the Document type declaration at the beginning of the document */ rc = xmlTextWriterWriteDTD(writer, BAD_CAST "mixture", BAD_CAST "-//ghmm.org//DOCUMENT ghmm V"DTD_VERSION"//EN", BAD_CAST "http://ghmm.sourceforge.net/xml/"DTD_VERSION"/ghmm.dtd", NULL); if (rc < 0) { GHMM_LOG(LERROR, "failed to write the DocType"); goto STOP;} /* start real contents */ if (0 > xmlTextWriterStartElement(writer, BAD_CAST "mixture")) { GHMM_LOG(LERROR, "Error at xmlTextWriterStartElement (mixture)"); goto STOP;; } if (xmlTextWriterWriteAttribute(writer, BAD_CAST "version", BAD_CAST DTD_VERSION) < 0) { GHMM_LOG(LERROR, "failed to write version 1.0"); goto STOP;} if (0 > xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "noComponents", "%d", f->noModels)) { GHMM_LOG(LERROR, "failed to write the number of components"); goto STOP;} /* write all models */ for (i=0; i<f->noModels; i++) writeHMM(writer, f, i); /* end mixture */ if (0 > xmlTextWriterEndDocument(writer)) { GHMM_LOG(LERROR, "Error at xmlTextWriterEndDocument (mixture)"); goto STOP; } xmlFreeTextWriter(writer); xmlSaveFormatFileEnc(file, doc, MY_ENCODING, 1); STOP: xmlFreeDoc(doc); /* * Cleanup function for the XML library. */ xmlCleanupParser(); /* * this is to debug memory for regression tests */ xmlMemoryDump(); #undef CUR_PROC }
void daeLIBXMLPlugin::writeAttribute( daeMetaAttribute* attr, daeElement* element ) { static daeChar atomicTypeBuf[TYPE_BUFFER_SIZE]; if (element == NULL) return; if ( attr->getCount(element) == 0 ) { //we don't have a value if its required print it empty else just skip if ( attr->getIsRequired() ) { xmlTextWriterStartAttribute( writer, (xmlChar*)(daeString)attr->getName() ); xmlTextWriterEndAttribute( writer ); } return; } else if ( attr->getCount(element) == 1 ) { //single value or an array of a single value char* elemMem = attr->get(element, 0); // !!!GAC recoded the suppression logic so you could enable suppressions individually if(!attr->getIsRequired()) { // This attribute was not required and might get suppressed int typeSize = attr->getType()->getSize(); if(attr->getDefault() != NULL) { #if 1 // The attribute has a default, convert the default to binary and suppress // output of the attribute if the value matches the default. // DISABLE THIS CODE IF YOU WANT DEFAULT VALUES TO ALWAYS EXPORT if(typeSize >= TYPE_BUFFER_SIZE) { fprintf(stderr, "daeMetaAttribute::print() - buffer too small for default value of %s in %s\n", (daeString)attr->getName(),(daeString)attr->getContainer()->getName()); fflush(stderr); return; } attr->getType()->stringToMemory((daeChar*)attr->getDefault(),atomicTypeBuf); if(memcmp(atomicTypeBuf,elemMem,typeSize) == 0) return; #endif } else { #if 1 // The attribute does not have a default, suppress it if its value is all zeros (binary) // DISABLE THIS CODE IF YOU WANT OPTIONAL ATTRIBUTES THAT HAVE A VALUE OF ZERO TO EXPORT // Disabling this code may cause some unused attributes to be exported if _isValid is not // enabled and properly used. int i; for(i=0; i<typeSize;i++) { if(elemMem[i] != 0) break; } if(i == typeSize && attr->getContainer()->getValueAttribute() != attr && attr->getType()->getTypeEnum() != daeAtomicType::BoolType && attr->getType()->getTypeEnum() != daeAtomicType::EnumType ) return; #endif } } // Convert the attribute to a string if (attr->getType()->memoryToString(elemMem, atomicTypeBuf, TYPE_BUFFER_SIZE)== false) { fprintf(stderr, "daeMetaAttribute::print() - buffer too small for %s in %s\n", (daeString)attr->getName(),(daeString)attr->getContainer()->getName()); fflush(stderr); } // Suppress attributes that convert to an empty string. if (strlen(atomicTypeBuf) == 0) return; // Is this a value attribute or something else? if (attr->getContainer()->getValueAttribute() == attr) { // Always export value attributes xmlTextWriterWriteString( writer, (xmlChar*)atomicTypeBuf); } else { // Suppress attributes not marked as containing valid values // DO NOT TURN THIS ON TILL ALL USER CODE HAS BEEN CHANGED TO SET _isValid OR // ATTRIBUTES THAT WERE CREATED/SET BY USER CODE MAY NOT EXPORT. #if 0 // NOTE: even if a value is marked REQUIRED by the schema, if _isValid isn't true it means // the value in this parameter was never set and may be garbage, so we suppress it even though it is required. // To change this add && !_isRequired to the expression below. if(!attr->getIsValid() ) return; #endif // Export the attribute name and value xmlTextWriterWriteAttribute( writer, (xmlChar*)(daeString)attr->getName(), (xmlChar*)atomicTypeBuf); } } else { if (attr->getContainer()->getValueAttribute() != attr) { xmlTextWriterStartAttribute( writer, (xmlChar*)(daeString)attr->getName() ); } for( int i = 0; i < attr->getCount(element); i++ ) { char* elemMem = attr->get(element, i); if (attr->getType()->memoryToString(elemMem, atomicTypeBuf, TYPE_BUFFER_SIZE)== false) { fprintf(stderr, "daeMetaArrayAttribute::print() - buffer too small for %s in %s\n", (daeString)attr->getName(),(daeString)attr->getContainer()->getName()); fflush(stderr); } xmlTextWriterWriteFormatString( writer, "%s ", (xmlChar*)atomicTypeBuf ); } if (attr->getContainer()->getValueAttribute() != attr) { xmlTextWriterEndAttribute( writer ); } } }
/* ========================================================================= */ static int writeDiscreteSwitchingStateContents(xmlTextWriterPtr writer, ghmm_xmlfile* f, int moNo, int sNo) { #define CUR_PROC "writeDiscreteSwitchingStateContents" int bgId, cLabel, rc, order, tied; char * tmp=NULL; /* writing discrete distribution */ if (0 > xmlTextWriterStartElement(writer, BAD_CAST "discrete")) { GHMM_LOG(LERROR, "Error at xmlTextWriterStartElement (discrete)"); goto STOP; } if (0 > xmlTextWriterWriteAttribute(writer, BAD_CAST "id", BAD_CAST "0")) { GHMM_LOG(LERROR, "failed to write alphabet id"); goto STOP; } if (f->model.ds[moNo]->s[sNo].fix) if (0 > xmlTextWriterWriteAttribute(writer, BAD_CAST "fixed", BAD_CAST "1")) { GHMM_LOG(LERROR, "failed to write fixed attriute"); goto STOP; } if ((f->model.ds[moNo]->model_type & GHMM_kHigherOrderEmissions) && f->model.ds[moNo]->order[sNo]) { order = f->model.ds[moNo]->order[sNo]; if (0 > xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "order", "%d", order)) { GHMM_LOG(LERROR, "failed to write order attribute for discrete distribution"); goto STOP; } } else order = 0; tmp = doubleArrayToCSV(f->model.ds[moNo]->s[sNo].b, pow(f->model.ds[moNo]->M, order+1)); if (tmp) { if (0 > xmlTextWriterWriteRaw(writer, BAD_CAST tmp)) { GHMM_LOG(LERROR, "Error at xmlTextWriterWriteRaw while writing" "discrete distribution CSV"); m_free(tmp); goto STOP; } m_free(tmp); } else { GHMM_LOG(LERROR, "converting array to CSV failed for discrete distribution"); goto STOP; } /* end discrete distribution */ if (0 > xmlTextWriterEndElement(writer)) { GHMM_LOG(LERROR, "Error at xmlTextWriterEndElement (discrete)"); goto STOP; } /* writing backgroung key */ if (f->model.ds[moNo]->model_type & GHMM_kBackgroundDistributions) { bgId = f->model.ds[moNo]->background_id[sNo]; if (bgId != GHMM_kNoBackgroundDistribution) { if (f->model.ds[moNo]->bp->name[bgId]) { rc = xmlTextWriterWriteElement(writer, BAD_CAST "backgroundKey", BAD_CAST f->model.ds[moNo]->bp->name[bgId]); if (rc<0) { GHMM_LOG(LERROR, "Error at xmlTextWriterWriteElement (backgroundKey)"); goto STOP; } } else { GHMM_LOG(LERROR, "background name is NULL pointer, invalid model"); goto STOP; } } } /* writing class label */ if (f->model.ds[moNo]->model_type & GHMM_kLabeledStates) { cLabel = f->model.ds[moNo]->label[sNo]; rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "class", "%d", cLabel); if (rc<0) { GHMM_LOG(LERROR, "failed to write class label"); goto STOP; } } /* duration (not implemented yet, maybe never */ #if 0 if (f->model.ds[moNo]->model_type & GHMM_kDurations) { if (f->model.ds[moNo]->duration[sNo] > 0) { rc = xmlTextWriterWriteElement(writer, BAD_CAST "duration", BAD_CAST f->model.ds[moNo]->duration[sNo]); if (rc<0) { GHMM_LOG(LERROR, "Error at xmlTextWriterWriteElement (duration)"); goto STOP; } } } #endif /* writing positions */ if ((f->model.ds[moNo]->s[sNo].xPosition > 0) && (f->model.ds[moNo]->s[sNo].xPosition > 0)) { if (xmlTextWriterStartElement(writer, BAD_CAST "position") < 0) { GHMM_LOG(LERROR, "failed to start position element (position)"); goto STOP;} if (0 > xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "x", "%d", f->model.ds[moNo]->s[sNo].xPosition)) { GHMM_LOG(LERROR, "failed to write x position"); goto STOP;} if (0 > xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "y", "%d", f->model.ds[moNo]->s[sNo].yPosition)) { GHMM_LOG(LERROR, "failed to write y position"); goto STOP;} if (xmlTextWriterEndElement(writer) < 0) { GHMM_LOG(LERROR, "Error at xmlTextWriterEndElement (position)"); goto STOP;} } /* writing tied states */ if (f->model.ds[moNo]->model_type & GHMM_kTiedEmissions) { tied = f->model.ds[moNo]->tied_to[sNo]; if (tied != GHMM_kUntied) { rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "tiedTo", "%d", tied); if (rc<0) { GHMM_LOG(LERROR, "failed to write tiedTo element"); goto STOP; } } } return 0; STOP: return -1; #undef CUR_PROC }
void dt_styles_save_to_file(const char *style_name,const char *filedir,gboolean overwrite) { int rc = 0; char stylename[520]; sqlite3_stmt *stmt; snprintf(stylename,512,"%s/%s.dtstyle",filedir,style_name); // check if file exists if( g_file_test(stylename, G_FILE_TEST_EXISTS) == TRUE ) { if(overwrite) { if(unlink(stylename)) { dt_control_log(_("failed to overwrite style file for %s"),style_name); return; } } else { dt_control_log(_("style file for %s exists"),style_name); return; } } if ( !dt_styles_exists (style_name) ) return; xmlTextWriterPtr writer = xmlNewTextWriterFilename(stylename, 0); if (writer == NULL) { fprintf(stderr,"[dt_styles_save_to_file] Error creating the xml writer\n, path: %s", stylename); return; } rc = xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL); if (rc < 0) { fprintf(stderr,"[dt_styles_save_to_file]: Error on encoding setting"); return; } xmlTextWriterStartElement(writer, BAD_CAST "darktable_style"); xmlTextWriterWriteAttribute(writer, BAD_CAST "version", BAD_CAST "1.0"); xmlTextWriterStartElement(writer, BAD_CAST "info"); xmlTextWriterWriteFormatElement(writer, BAD_CAST "name", "%s", style_name); xmlTextWriterWriteFormatElement(writer, BAD_CAST "description", "%s", dt_styles_get_description(style_name)); xmlTextWriterEndElement(writer); xmlTextWriterStartElement(writer, BAD_CAST "style"); DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select num,module,operation,op_params,enabled,blendop_params,blendop_version,multi_priority,multi_name from style_items where styleid =?1",-1, &stmt,NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt,1,dt_styles_get_id_by_name(style_name)); while (sqlite3_step (stmt) == SQLITE_ROW) { xmlTextWriterStartElement(writer, BAD_CAST "plugin"); xmlTextWriterWriteFormatElement(writer, BAD_CAST "num", "%d", sqlite3_column_int(stmt,0)); xmlTextWriterWriteFormatElement(writer, BAD_CAST "module", "%d", sqlite3_column_int(stmt,1)); xmlTextWriterWriteFormatElement(writer, BAD_CAST "operation", "%s", sqlite3_column_text(stmt,2)); xmlTextWriterWriteFormatElement(writer, BAD_CAST "op_params", "%s", dt_style_encode(stmt,3)); xmlTextWriterWriteFormatElement(writer, BAD_CAST "enabled", "%d", sqlite3_column_int(stmt,4)); xmlTextWriterWriteFormatElement(writer, BAD_CAST "blendop_params", "%s", dt_style_encode(stmt,5)); xmlTextWriterWriteFormatElement(writer, BAD_CAST "blendop_version", "%d", sqlite3_column_int(stmt,6)); xmlTextWriterWriteFormatElement(writer, BAD_CAST "multi_priority", "%d", sqlite3_column_int(stmt,7)); xmlTextWriterWriteFormatElement(writer, BAD_CAST "multi_name", "%s", sqlite3_column_text(stmt,8)); xmlTextWriterEndElement(writer); } sqlite3_finalize(stmt); xmlTextWriterEndDocument(writer); xmlFreeTextWriter(writer); }
/* ========================================================================= */ static int writeContinuousStateContents(xmlTextWriterPtr writer, ghmm_xmlfile* f, int moNo, int sNo) { #define CUR_PROC "writeContinuousStateContents" int i; ghmm_cstate *state = f->model.c[moNo]->s + sNo; int allFixed = state->fix; ghmm_c_emission *emission; /* writing continuous distribution */ if (0 > xmlTextWriterStartElement(writer, BAD_CAST "mixture")) { GHMM_LOG(LERROR, "Error at xmlTextWriterStartElement (mixture)"); goto STOP; } if (f->model.c[moNo]->s[sNo].fix) allFixed = 1; for(i=0; i < f->model.c[moNo]->s[sNo].M; i++){ emission = f->model.c[moNo]->s[sNo].e+i; switch (emission->type) { case normal: if (0 > xmlTextWriterStartElement(writer, BAD_CAST "normal")) { GHMM_LOG(LERROR, "Error at xmlTextWriterStartElement (normal)"); goto STOP; } WRITE_DOUBLE_ATTRIBUTE(writer, "mean", emission->mean.val); WRITE_DOUBLE_ATTRIBUTE(writer, "variance", emission->variance.val); break; case multinormal: if (0 > xmlTextWriterStartElement(writer, BAD_CAST "multinormal")) { GHMM_LOG(LERROR, "Error at xmlTextWriterStartElement (multinormal)"); goto STOP; } if (0 > xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "dimension", "%d", emission->dimension)) { GHMM_LOG(LERROR, "failed to write dimension attribute"); goto STOP; } break; case normal_left: if (0 > xmlTextWriterStartElement(writer, BAD_CAST "normalLeftTail")) { GHMM_LOG(LERROR, "Error at xmlTextWriterStartElement (normalLeftTail)"); goto STOP; } WRITE_DOUBLE_ATTRIBUTE(writer, "mean", emission->mean.val); WRITE_DOUBLE_ATTRIBUTE(writer, "variance", emission->variance.val); WRITE_DOUBLE_ATTRIBUTE(writer, "max", emission->min); break; case normal_right: if (0 > xmlTextWriterStartElement(writer, BAD_CAST "normalRightTail")) { GHMM_LOG(LERROR, "Error at xmlTextWriterStartElement (normalRightTail)"); goto STOP; } WRITE_DOUBLE_ATTRIBUTE(writer, "mean", emission->mean.val); WRITE_DOUBLE_ATTRIBUTE(writer, "variance", emission->variance.val); WRITE_DOUBLE_ATTRIBUTE(writer, "min", emission->max); break; case uniform: if (0 > xmlTextWriterStartElement(writer, BAD_CAST "uniform")) { GHMM_LOG(LERROR, "Error at xmlTextWriterStartElement (uniform)"); goto STOP; } WRITE_DOUBLE_ATTRIBUTE(writer, "min", emission->min); WRITE_DOUBLE_ATTRIBUTE(writer, "max", emission->max); break; default: GHMM_LOG_PRINTF(LERROR, LOC, "invalid density %d at position %d", emission->type, i); goto STOP; } /*optional values */ if (allFixed || emission->fixed) { if (0 > xmlTextWriterWriteAttribute(writer, BAD_CAST "fixed", BAD_CAST "1")) { GHMM_LOG(LERROR, "failed to set fixed attribute"); goto STOP; } } if (state->M > 1) { WRITE_DOUBLE_ATTRIBUTE(writer, "prior", state->c[i]); } /* write mean vector and covariance matrix as childs for multinormal */ if (emission->type == multinormal) { if (0 > writeMultiNormal(writer, emission)) { GHMM_LOG(LERROR, "failed to write mean and covariance childs"); goto STOP; } } if (0 > xmlTextWriterEndElement(writer)) { GHMM_LOG(LERROR, "Error at xmlTextWriterEndElement (all densities)"); goto STOP; } } /* end mixture tag */ if (0 > xmlTextWriterEndElement(writer)) { GHMM_LOG(LERROR, "Error at xmlTextWriterEndElement (mixture)"); goto STOP; } /* writing positions */ if ((state->xPosition > 0) && (state->yPosition > 0)) { if (xmlTextWriterStartElement(writer, BAD_CAST "position") < 0) { GHMM_LOG(LERROR, "failed to start position element (position)"); goto STOP; } if (0 > xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "x", "%d", state->xPosition)) { GHMM_LOG(LERROR, "failed to write x position"); goto STOP; } if (0 > xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "y", "%d", state->yPosition)) { GHMM_LOG(LERROR, "failed to write y position"); goto STOP; } if (xmlTextWriterEndElement(writer) < 0) { GHMM_LOG(LERROR, "Error at xmlTextWriterEndElement (position)"); goto STOP; } } return 0; STOP: return -1; #undef CUR_PROC }