struct writer * xml_init(FILE * fh) { struct writer * result; struct xml_writer_private * priv; priv = malloc( sizeof( *priv ) ); if ( ! priv ) { fatalx("out of memory\n"); return NULL; } priv->xw = xmlNewTextWriterDoc(&(priv->doc), 0); if ( ! priv->xw ) { fatalx("cannot create xml writer\n"); return NULL; } xmlTextWriterSetIndent(priv->xw, 4); if (xmlTextWriterStartDocument(priv->xw, NULL, MY_ENCODING, NULL) < 0 ) { fatalx("cannot start xml document\n"); return NULL; } result = malloc( sizeof( struct writer ) ); if ( ! result ) { fatalx("out of memory\n"); return NULL; } result->priv = priv; result->start = xml_start; result->attr = xml_attr; result->data = xml_data; result->end = xml_end; result->finish= xml_finish; return result; }
void XMLExporter::open(const std::string &_filename, const std::string &_element) { m_doc = xmlNewDoc(BAD_CAST XML_DEFAULT_VERSION); m_node = xmlNewDocNode(m_doc, NULL, BAD_CAST "root", NULL); xmlDocSetRootElement(m_doc, m_node); m_writer = xmlNewTextWriterTree(m_doc,m_node, 0); xmlTextWriterStartDocument(m_writer, NULL, MY_ENCODING, NULL); // xmlTextWriterStartElement(m_writer, BAD_CAST _element.c_str()); m_file = _filename; }
void xml_writer::init(bool indent) { // maybe enable indenting if (indent) { xmlTextWriterSetIndent(pimpl->writer, 1); } // start the document if (xmlTextWriterStartDocument(pimpl->writer, NULL, "UTF-8", NULL) < 0) { throw write_error("error creating document element."); } }
bool c_XMLWriter::t_startdocument(const String& version /* = "1.0" */, const String& encoding /* = null_string */, const String& standalone /* = null_string */) { int ret = -1; if (m_ptr) { ret = xmlTextWriterStartDocument(m_ptr, (const char *)xmls(version), (const char *)xmls(encoding), (const char *)xmls(standalone)); } return ret != -1; }
XMLBBoxWriter::XMLBBoxWriter(const char* filename):frameCount(0) { open_success=true; writer = xmlNewTextWriterFilename(filename, 0); if (writer == NULL) { printf("testXmlwriterFilename: Error creating the xml writer\n"); open_success=false; } rc=xmlTextWriterStartDocument(writer,NULL,ENCODING,NULL); rc=xmlTextWriterStartElement(writer, BAD_CAST "dataset"); }
void xml_new_writer(struct xml_writer_private *priv) { priv->xw = xmlNewTextWriterDoc(&(priv->doc), 0); if (!priv->xw) fatalx("lldpctl", "cannot create xml writer"); xmlTextWriterSetIndent(priv->xw, 4); if (xmlTextWriterStartDocument(priv->xw, NULL, "UTF-8", NULL) < 0 ) fatalx("lldpctl", "cannot start xml document"); }
static void startSBOLDocument() { resetProcessed(); createSBOLWriter(); xmlTextWriterStartDocument(WRITER, NULL, NULL, NULL); xmlTextWriterStartElement(WRITER, xmlCharStrdup(NSPREFIX_RDF ":" NODENAME_RDF)); xmlTextWriterWriteAttribute(WRITER, xmlCharStrdup("xmlns:" NSPREFIX_RDF), xmlCharStrdup(NSURL_RDF)); xmlTextWriterWriteAttribute(WRITER, xmlCharStrdup("xmlns:" NSPREFIX_RDFS), xmlCharStrdup(NSURL_RDFS)); xmlTextWriterWriteAttribute(WRITER, xmlCharStrdup("xmlns:" NSPREFIX_SO), xmlCharStrdup(NSURL_SO)); xmlTextWriterWriteAttribute(WRITER, xmlCharStrdup("xmlns:" NSPREFIX_SBOL), xmlCharStrdup(NSURL_SBOL)); indentMore(); }
bool c_XMLWriter::t_startdocument(CStrRef version /* = "1.0" */, CStrRef encoding /* = null_string */, CStrRef standalone /* = null_string */) { INSTANCE_METHOD_INJECTION_BUILTIN(XMLWriter, XMLWriter::startdocument); int ret = -1; if (m_ptr) { ret = xmlTextWriterStartDocument(m_ptr, (const char *)xmls(version), (const char *)xmls(encoding), (const char *)xmls(standalone)); } return ret != -1; }
// SAX save settings short int settingsXmlSave(const char *filename) { int rc; xmlTextWriterPtr writer; // Create a new XmlWriter with no compression writer = xmlNewTextWriterFilename(filename, 0); if (writer == NULL) return 1; // Start document with xml default encoding ISO 8859-1 rc = xmlTextWriterStartDocument(writer, NULL, XML_ENCODING, NULL); if (rc < 0) return 2; // Start root node "settings" rc = xmlTextWriterStartElement(writer, BAD_CAST "settings"); if (rc < 0) return 2; // Create child node "xap" rc = xmlTextWriterStartElement(writer, BAD_CAST "xap"); if (rc < 0) return 2; // Write <xap> elements rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "iface", "%s", hubConfig->interfacename); if (rc < 0) return 4; rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "instance", "%s", hubConfig->xap_addr.instance); if (rc < 0) return 4; rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "hbeatf", "%d", hubConfig->xap_hbeat); if (rc < 0) return 4; rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "uid", "%s", hubConfig->xap_uid); if (rc < 0) return 4; rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "port", "%d", hubConfig->xap_port); if (rc < 0) return 4; // Close node "xap" rc = xmlTextWriterEndElement(writer); if (rc < 0) return 5; // Close the rest nodes pending to close rc = xmlTextWriterEndDocument(writer); if (rc < 0) return 5; // Free the writer xmlFreeTextWriter(writer); // Cleanup function for the XML library. xmlCleanupParser(); // this is to debug memory for regression tests xmlMemoryDump(); return 0; }
static void writeNode(Serialization *serialization, DFNode *node, int depth) { switch (node->tag) { case DOM_DOCUMENT: { if (!serialization->html) xmlTextWriterStartDocument(serialization->writer,"1.0","UTF-8","yes"); if (serialization->html) xmlTextWriterWriteDTD(serialization->writer,(xmlChar *)"html",NULL,NULL,NULL); // xmlTextWriterWriteDTD(writer, // (xmlChar *)"html", // (xmlChar *)"-//W3C//DTD XHTML 1.0 Strict//EN", // (xmlChar *)"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", // NULL); for (DFNode *child = node->first; child != NULL; child = child->next) writeNode(serialization,child,0); xmlTextWriterEndDocument(serialization->writer); break; } case DOM_TEXT: { if (serialization->indent && ((node->prev != NULL) || (node->next != NULL))) xmlTextWriterWriteRawLen(serialization->writer,INDENT,1+depth); if (serialization->html && (node->parent != NULL) && (node->parent->tag == HTML_STYLE)) { xmlTextWriterWriteRaw(serialization->writer,(const xmlChar *)node->value); } else { xmlTextWriterWriteString(serialization->writer,(const xmlChar *)node->value); } break; } case DOM_COMMENT: { xmlTextWriterWriteComment(serialization->writer,(const xmlChar *)node->value); break; } case DOM_CDATA: { xmlTextWriterWriteCDATA(serialization->writer,(const xmlChar *)node->value); break; } case DOM_PROCESSING_INSTRUCTION: { xmlTextWriterWritePI(serialization->writer, (const xmlChar *)node->target, (const xmlChar *)node->value); break; } default: { if (node->parent == serialization->doc->docNode) writeElement(serialization,node,0); else writeElement(serialization,node,depth); break; } } }
void temporal_convert_parallel_passages() // This was used to convert file NT_order_of_OT_Quotations_in_NT.pps to xml. // Then for converting NT_Parallel_Passages.pps. // Then for converting OT_Parallel_Passages.pps. { bool set_opened = false; xmlBufferPtr buffer = xmlBufferCreate(); xmlTextWriterPtr writer = xmlNewTextWriterMemory(buffer, 0); xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL); xmlTextWriterSetIndent(writer, 1); xmlTextWriterStartElement(writer, BAD_CAST "ot-parallel-passages"); ReadText rt("/home/joe/parallel-passages/OT_Parallel_Passages.pps", true); for (unsigned int i = 0; i < rt.lines.size(); i++) { if (rt.lines[i].find("\\key ") == 0) { rt.lines[i].erase(0, 5); xmlTextWriterStartElement(writer, BAD_CAST "section"); xmlTextWriterWriteAttribute(writer, BAD_CAST "title", BAD_CAST rt.lines[i].c_str()); } if (rt.lines[i].find("\\ref ") == 0) { if (!set_opened) { xmlTextWriterStartElement(writer, BAD_CAST "set"); set_opened = true; } xmlTextWriterStartElement(writer, BAD_CAST "reference"); rt.lines[i].erase(0, 5); ustring book, chapter, verse; decode_reference(rt.lines[i], book, chapter, verse); book = books_id_to_english(books_paratext_to_id(book)); xmlTextWriterWriteAttribute(writer, BAD_CAST "book", BAD_CAST book.c_str()); xmlTextWriterWriteAttribute(writer, BAD_CAST "chapter", BAD_CAST chapter.c_str()); xmlTextWriterWriteAttribute(writer, BAD_CAST "verse", BAD_CAST verse.c_str()); xmlTextWriterEndElement(writer); } if (rt.lines[i].empty() || (rt.lines[i].find("\\com") == 0)) { xmlTextWriterEndElement(writer); set_opened = false; } if (rt.lines[i].empty()) { xmlTextWriterEndElement(writer); } } xmlTextWriterEndDocument(writer); xmlTextWriterFlush(writer); g_file_set_contents("/home/joe/ot-parallel-passages.xml", (const gchar *)buffer->content, -1, NULL); if (writer) xmlFreeTextWriter(writer); if (buffer) xmlBufferFree(buffer); }
/** * @short Prepares the response for propfinds * * @param realpath Shared folder * @param urlpath URL of the requested propfind * @param depth Depth of query, 0 or 1. * @param props Properties of the query * * @returns An onion_block with the XML data. */ onion_block *onion_webdav_write_propfind(const char *basepath, const char *realpath, const char *urlpath, int depth, int props){ onion_block *data=onion_block_new(); xmlTextWriterPtr writer; xmlBufferPtr buf; buf = xmlBufferCreate(); if (buf == NULL) { ONION_ERROR("testXmlwriterMemory: Error creating the xml buffer"); return data; } writer = xmlNewTextWriterMemory(buf, 0); if (writer == NULL) { ONION_ERROR("testXmlwriterMemory: Error creating the xml writer"); return data; } int error; xmlTextWriterStartDocument(writer, NULL, "utf-8", NULL); xmlTextWriterStartElement(writer, BAD_CAST "D:multistatus"); xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:D" ,BAD_CAST "DAV:"); error=onion_webdav_write_props(writer, basepath, realpath, urlpath, NULL, props); if (depth>0){ ONION_DEBUG("Get also all files"); DIR *dir=opendir(realpath); if (!dir){ ONION_ERROR("Error opening dir %s to check files on it", realpath); } else{ struct dirent *de; while ( (de=readdir(dir)) ){ if (de->d_name[0]!='.') onion_webdav_write_props(writer, basepath, realpath, urlpath, de->d_name, props); } closedir(dir); } } xmlTextWriterEndElement(writer); xmlTextWriterEndElement(writer); xmlTextWriterEndDocument(writer); xmlFreeTextWriter(writer); onion_block_add_str(data, (const char*)buf->content); xmlBufferFree(buf); if (error){ onion_block_free(data); return NULL; } return data; }
int save_gpx(const char *fname,GList *save_list) { time_t t=time(NULL); struct tm tm; GList *l; xmlTextWriterPtr writer; writer=xmlNewTextWriterFilename(fname,0); if (!writer) return 0; xmlTextWriterStartDocument(writer,NULL,"UTF-8",NULL); xmlTextWriterStartElement(writer,(xmlChar *)"gpx"); xmlTextWriterWriteAttribute(writer,(xmlChar *)"version",(xmlChar *)"1.0"); xmlTextWriterWriteAttribute(writer,(xmlChar *)"creator",(xmlChar *)PACKAGE " " VERSION); xmlTextWriterWriteAttribute(writer,(xmlChar *)"xmlns:xsi",(xmlChar *)"http://www.w3.org/2001/XMLSchema-instance"); xmlTextWriterWriteAttribute(writer,(xmlChar *)"xmlns", (xmlChar *)"http://www.topografix.com/GPX/1/0"); xmlTextWriterWriteAttribute(writer,(xmlChar *)"xsi:schemaLocation",(xmlChar *)"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd"); tm=*gmtime(&t); xmlTextWriterWriteFormatElement(writer,(xmlChar *)"time","%04d-%02d-%02dT%02d:%02d:%02d", tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday, tm.tm_hour,tm.tm_min,tm.tm_sec); xmlTextWriterStartElement(writer,(xmlChar *)"trk"); xmlTextWriterStartElement(writer,(xmlChar *)"trkseg"); for(l=g_list_first(save_list);l;l=g_list_next(l)) { struct t_punkt32 *p=(struct t_punkt32 *)l->data; xmlTextWriterStartElement(writer,(xmlChar *)"trkpt"); xmlTextWriterWriteFormatAttribute(writer,(xmlChar *)"lat","%f", p->latt); xmlTextWriterWriteFormatAttribute(writer,(xmlChar *)"lon","%f", p->longg); if (p->time) { t=p->time; tm=*gmtime(&t); xmlTextWriterWriteFormatElement(writer,(xmlChar*)"time", "%04d-%02d-%02dT%02d:%02d:%02d", tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday, tm.tm_hour,tm.tm_min,tm.tm_sec); } if (p->speed>0) xmlTextWriterWriteFormatElement(writer,(xmlChar *)"speed","%f",p->speed*1.852/3.6); xmlTextWriterEndElement(writer); /* /trkpt */ } xmlTextWriterEndElement(writer); /*trkseg */ xmlTextWriterEndElement(writer); /* trk */ xmlTextWriterEndElement(writer); /* gpx */ xmlTextWriterEndDocument(writer); xmlFreeTextWriter(writer); return 1; }
bool c_XMLWriter::t_startdocument(const String& version /* = "1.0" */, const String& encoding /* = null_string */, const String& standalone /* = null_string */) { int ret = -1; if (m_ptr) { const auto pencoding = encoding.empty() ? nullptr : xmls(encoding); const auto pstandalone = standalone.empty() ? nullptr : xmls(standalone); ret = xmlTextWriterStartDocument(m_ptr, (const char *)xmls(version), (const char *)pencoding, (const char *)pstandalone); } return ret != -1; }
/** * xml_writer_write_start_document: * @writer: A #XmlWriter * @version: the xml version ("1.0") or NULL for default ("1.0") * @encoding: the encoding or NULL for default * @standalone: yes" or "no" or NULL for default * * Starts a new xml document. You must be at the begging of a * stream for this to be successful. */ void xml_writer_write_start_document (XmlWriter *writer, const gchar *version, const gchar *encoding, const gchar *standalone) { XmlWriterPrivate *priv; g_return_if_fail (XML_IS_WRITER (writer)); priv = writer->priv; if (priv->writer) xmlTextWriterStartDocument (priv->writer, version, encoding, standalone); }
char *gen_lote_xml(LOTE *lote, EVP_PKEY *key, X509 *cert){ int rc; xmlTextWriterPtr writer; xmlDocPtr doc; xmlBufferPtr buf = xmlBufferCreate(); writer = xmlNewTextWriterDoc(&doc, 0); if (writer == NULL) return NULL; xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL); rc = xmlTextWriterStartElement(writer, BAD_CAST "enviNFe"); if (rc < 0) return NULL; rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns", BAD_CAST "http://www.portalfiscal.inf.br/nfe"); if (rc < 0) return NULL; rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "versao", BAD_CAST NFE_VERSAO); if (rc < 0) return NULL; rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "idLote", "%d", lote->id); if (rc < 0) return NULL; int indSinc = lote->qtd == 1? 1 : 0; rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "indSinc", "%d", indSinc); if (rc < 0) return NULL; int i; LOTE_ITEM *it = lote->nfes; for (i = 0; i < lote->qtd; i++){ char *xml; xml = generate_xml(it->nfe, key, cert); printf("%s\n", xml); rc = xmlTextWriterWriteRaw(writer, BAD_CAST xml); if (rc < 0) return NULL; it = it->next; } rc = xmlTextWriterEndElement(writer); if (rc < 0) return NULL; xmlTextWriterEndDocument(writer); xmlNodeDump(buf, NULL, xmlDocGetRootElement(doc), 0, 0); return (char*)buf->content; }
static int _exml_write(EXML *xml, xmlTextWriterPtr writer) { xmlTextWriterSetIndent( writer, 1 ); xmlTextWriterSetIndentString( writer, (xmlChar *) "\t" ); xmlTextWriterStartDocument( writer, NULL, NULL, NULL ); /* as of now, we do not write a DTD. This will be in effect with a new * set of functions designed to manipulate the DTD, as well as added * capability for reading DTDs from orthogonal read sources */ _exml_write_element(xml->top, writer); xmlTextWriterEndDocument( writer ); xmlFreeTextWriter( writer ); return TRUE; }
daeInt daeLIBXMLPlugin::write(daeURI *name, daeDocument *document, daeBool replace) { // Make sure database and document are both set if (!database) return DAE_ERR_INVALID_CALL; if(!document) return DAE_ERR_COLLECTION_DOES_NOT_EXIST; // Extract just the file path from the URI daeFixedName finalname; if (!name->getPath(finalname,sizeof(finalname))) { printf( "can't get path in write\n" ); return DAE_ERR_BACKEND_IO; } // If replace=false, don't replace existing files if(!replace) { // Using "stat" would be better, but it's not available on all platforms FILE *tempfd = fopen(finalname,"r"); if(tempfd != NULL) { // File exists, return error fclose(tempfd); return DAE_ERR_BACKEND_FILE_EXISTS; } } // Open the file we will write to writer = xmlNewTextWriterFilename(name->getURI(), 0); if ( !writer ) { printf( "no libxml2 writer\n" ); return DAE_ERR_BACKEND_IO; } xmlChar indentString[10] = " "; xmlTextWriterSetIndentString( writer, indentString ); xmlTextWriterSetIndent( writer, 1 ); xmlTextWriterStartDocument( writer, NULL, NULL, NULL ); writeElement( document->getDomRoot() ); xmlTextWriterEndDocument( writer ); xmlTextWriterFlush( writer ); xmlFreeTextWriter( writer ); return DAE_OK; }
//----------------------------------------- void LegacyWriter::write() { //----------------------------------------- #ifndef LIBXML_READER_ENABLED throw FileWriterException( "LIBXML NOT FOUND" ); #endif cout << "INFO Start writing the file (gexf v1.0).." << endl; /* * 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 /* Create a new XmlWriter for _filepath, with no compression. */ xmlTextWriterPtr writer = xmlNewTextWriterFilename(_filepath.c_str(), 0); if (writer == NULL) { throw FileWriterException( "Error creating the xml LegacyWriter" ); } /* Start the document with the xml default for the version, * encoding _ENCODING and the default for the standalone * declaration. */ int rc = xmlTextWriterStartDocument(writer, NULL, _ENCODING, NULL); if (rc < 0) { throw FileWriterException( "Error at xmlTextWriterStartDocument" ); } this->writeGexfNode(writer); /* 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) { throw FileWriterException( "Error at xmlTextWriterEndDocument" ); } /* Close file and free memory buffers */ xmlFreeTextWriter(writer); xmlCleanupParser(); cout << "INFO File written." << endl; }
void ZXMLDoc::begin() { /* Create a new XmlWriter for DOM, with no compression. */ writer = xmlNewTextWriterDoc(&doc, 0); if (writer == NULL) { printf("testXmlwriterDoc: 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("testXmlwriterDoc: Error at xmlTextWriterStartDocument\n"); return; } }
axis2_status_t AXIS2_CALL axis2_libxml2_writer_wrapper_write_start_document( axiom_xml_writer_t * writer, const axutil_env_t * env) { axis2_libxml2_writer_wrapper_impl_t *wrapper_impl = NULL; int status = 0; AXIS2_ENV_CHECK(env, AXIS2_FAILURE); wrapper_impl = AXIS2_INTF_TO_IMPL(writer); status = xmlTextWriterStartDocument(wrapper_impl->xml_writer, NULL, NULL, NULL); if(status < 0) { AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_START_DOCUMENT, AXIS2_FAILURE); return AXIS2_FAILURE; } return AXIS2_SUCCESS; }
int createDatabase(){ time_t now; struct tm * timeinfo; int rc; xmlTextWriterPtr writer; writer = xmlNewTextWriterFilename(db_uri, 0); if(writer == NULL){ printf("Error creating the xml writer\n"); return 1; } rc = xmlTextWriterStartDocument(writer, NULL, ENCODING, NULL); if(rc < 0){ printf("Error starting the document\n"); return 1; } rc = xmlTextWriterStartElement(writer, BAD_CAST "remendo_db"); if(rc < 0){ printf("Error creating the root element in the XML file\n"); return 1; } now = time(0); timeinfo = localtime (&now); xmlChar string_date [80]; strftime(string_date,80,"%s",timeinfo); rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "creation", string_date); if(rc < 0){ printf("Error creating attribute of root element\n"); return 1; } rc = xmlTextWriterEndElement(writer); if(rc < 0){ printf("Error ending the XML file\n"); return 1; } xmlFreeTextWriter(writer); xmlCleanupParser(); return 0; }
cpXmlCmdOutput::cpXmlCmdOutput( const char* ResultDocumentFileName ) : encoding( (const xmlChar*) "ISO-8859-1" ) , cpXmlCmdNamespace( (const xmlChar*) "http://www.XmlCommandLine.org/cpXmlCmd/1.0" ) { /* Create a new XmlWriter for uri, with no compression. */ writer = xmlNewTextWriterFilename( ResultDocumentFileName, 0 ); if ( writer == NULL ) throw ::std::runtime_error( "Error creating the xml writer" ); /* Start the document with the xml default for the version, * encoding ISO 8859-1 and the default for the standalone * declaration. */ if ( xmlTextWriterStartDocument( writer, NULL, (const char*)encoding, NULL ) < 0 ) throw ::std::runtime_error( "Error starting the output document" ); // Start root element if ( xmlTextWriterStartElementNS( writer, NULL, (xmlChar *) "cpXmlCmdLog", cpXmlCmdNamespace ) < 0 ) throw ::std::runtime_error( "Error writing to the output document" ); }
char *gen_cons_status(int ambiente, int cuf){ int rc; xmlTextWriterPtr writer; xmlDocPtr doc; xmlBufferPtr buf = xmlBufferCreate(); writer = xmlNewTextWriterDoc(&doc, 0); if (writer == NULL) { printf("Error NewDoc"); return NULL; } xmlTextWriterStartDocument(writer, NULL, "utf-8", NULL); rc = xmlTextWriterStartElement(writer, BAD_CAST "consStatServ"); if (rc < 0) return NULL; rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns", BAD_CAST "http://www.portalfiscal.inf.br/nfe"); if (rc < 0) return NULL; rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "versao", BAD_CAST NFE_VERSAO); if (rc < 0) return NULL; rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "tpAmb", "%d", ambiente); if (rc < 0) return NULL; rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "cUF", "%d", cuf); if (rc < 0) return NULL; rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "xServ", "%s", "STATUS"); if (rc < 0) return NULL; rc = xmlTextWriterEndElement(writer); if (rc < 0) return NULL; xmlTextWriterEndDocument(writer); xmlNodeDump(buf, NULL, xmlDocGetRootElement(doc), 0, 0); return (char*) buf->content; }
void CResource::SerializeToXmlFile(const nstring &file) { xmlTextWriterPtr writer = NULL; /* Create a new XmlWriter for uri, with no compression. */ if((writer = xmlNewTextWriterFilename(file.c_str(), 0)) == NULL) NOVA_EXP("CResource::SerializeToXmlFile: Error creating the xml writer", BAD_OPERATION); // automatic indentation for readability xmlTextWriterSetIndent(writer, 1); if(xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL) < 0) NOVA_EXP("CResource::SerializeToXmlFile: xmlTextWriterStartDocument fail", BAD_OPERATION); if(xmlTextWriterStartElement(writer, BAD_CAST "NovaResource") < 0) NOVA_EXP("CResource::SerializeToXmlFile: xmlTextWriterStartElement fail", BAD_OPERATION); if(xmlTextWriterWriteComment(writer, BAD_CAST "Common resource header") < 0) NOVA_EXP("CResource::SerializeToXmlFile: xmlTextWriterWriteComment fail", BAD_OPERATION); if(xmlTextWriterStartElement(writer, BAD_CAST "ResourceHeader") < 0) NOVA_EXP("CResource::SerializeToXmlFile: xmlTextWriterStartElement fail", BAD_OPERATION); if(xmlTextWriterWriteElement(writer, BAD_CAST "ResourceName", BAD_CAST mName.c_str()) < 0) NOVA_EXP("CResource::SerializeToXmlFile: xmlTextWriterWriteElement fail", BAD_OPERATION); if(xmlTextWriterWriteElement(writer, BAD_CAST "ResourceGroup", BAD_CAST mGroup.c_str()) < 0) NOVA_EXP("CResource::SerializeToXmlFile: xmlTextWriterWriteElement fail", BAD_OPERATION); if(xmlTextWriterStartElement(writer, BAD_CAST "ResourceData") < 0) NOVA_EXP("CResource::SerializeToXmlFile: xmlTextWriterStartElement fail", BAD_OPERATION); // Resource manager attribute if(xmlTextWriterWriteAttribute(writer, BAD_CAST "ResourceFactory", BAD_CAST GetCreator()->GetResourceFactoryName().c_str()) < 0) NOVA_EXP("CImage::SerializeToXmlFileImpl: xmlTextWriterWriteAttribute fail", BAD_OPERATION); SerializeToXmlFileImpl(writer); xmlTextWriterEndDocument(writer); xmlFreeTextWriter(writer); }
static void output (char **roots) { xmlOutputBufferPtr ob = xmlOutputBufferCreateFd (1, NULL); if (ob == NULL) error (EXIT_FAILURE, 0, _("xmlOutputBufferCreateFd: failed to open stdout")); /* 'ob' is freed when 'xo' is freed.. */ CLEANUP_XMLFREETEXTWRITER xmlTextWriterPtr xo = xmlNewTextWriter (ob); if (xo == NULL) error (EXIT_FAILURE, 0, _("xmlNewTextWriter: failed to create libxml2 writer")); /* Pretty-print the output. */ XMLERROR (-1, xmlTextWriterSetIndent (xo, 1)); XMLERROR (-1, xmlTextWriterSetIndentString (xo, BAD_CAST " ")); XMLERROR (-1, xmlTextWriterStartDocument (xo, NULL, NULL, NULL)); output_roots (xo, roots); XMLERROR (-1, xmlTextWriterEndDocument (xo)); }
bool WebArchiveAndroid::saveWebArchive(xmlTextWriterPtr writer) { const char* const defaultXmlVersion = 0; const char* const defaultEncoding = 0; const char* const defaultStandalone = 0; int result = xmlTextWriterStartDocument(writer, defaultXmlVersion, defaultEncoding, defaultStandalone); if (result < 0) { LOGD("saveWebArchive: Failed to start document."); return false; } if (!saveArchive(writer, this)) return false; result = xmlTextWriterEndDocument(writer); if (result< 0) { LOGD("saveWebArchive: Failed to end document."); return false; } return true; }
int generate_report(char dst_dir[DIR_LENGTH_MAX], char filename[FILENAME_LENGTH_MAX]) { // for the xml writer, refer to http://xmlsoft.org/html/libxml-xmlwriter.html char dst_file[FILENAME_LENGTH_MAX + DIR_LENGTH_MAX] = ""; strncat(dst_file, dst_dir, FILENAME_LENGTH_MAX + DIR_LENGTH_MAX - strlen(dst_file) - 1); strncat(dst_file, filename, FILENAME_LENGTH_MAX + DIR_LENGTH_MAX - strlen(dst_file) - 1); xmlTextWriterPtr writer; writer = xmlNewTextWriterFilename(dst_file, 0); // set the output format of the XML file xmlTextWriterSetIndent(writer, 1); xmlTextWriterSetIndentString(writer,(unsigned char*) " "); xmlTextWriterStartDocument(writer, NULL, NULL, NULL); /* Write an element named "X_ORDER_ID" as child of HEADER. */ xmlTextWriterWriteFormatElement(writer,(unsigned char*) "COMMENT ", " in this output file, %d means NOT_PROCESSED; %d means NO_FILE; %d means ERROR; %d means OK ", MODULE_NOT_PROCESSED, NO_FILE, MODULE_ERROR, MODULE_OK); xmlTextWriterWriteFormatElement(writer,(unsigned char*) "OCG_GET_OPT ", " %d ", get_opt_OK); xmlTextWriterWriteFormatElement(writer,(unsigned char*) "OCG_DETECT_FILE ", " %d ", detect_file_OK); xmlTextWriterWriteFormatElement(writer,(unsigned char*) "OCG_PARSE_FILENAME", " %d ", parse_filename_OK); xmlTextWriterWriteFormatElement(writer,(unsigned char*) "OCG_CREATE_DIR ", " %d ", create_dir_OK); xmlTextWriterWriteFormatElement(writer,(unsigned char*) "OCG_PARSE_XML ", " %d ", parse_XML_OK); xmlTextWriterWriteFormatElement(writer,(unsigned char*) "OCG_SAVE_XML ", " %d ", save_XML_OK); // xmlTextWriterWriteFormatElement(writer, "OCG_CALL_EMU ", " %d ", call_emu_OK); xmlTextWriterEndDocument(writer); xmlFreeTextWriter(writer); LOG_I(OCG, "A report of OCG is generated in directory \"%s\"\n\n", dst_dir); return MODULE_OK; }
char *gen_cons_nfe(LOTE *lote, int ambiente){ int rc; xmlTextWriterPtr writer; xmlDocPtr doc; xmlBufferPtr buf = xmlBufferCreate(); writer = xmlNewTextWriterDoc(&doc, 0); if (writer == NULL) return NULL; xmlTextWriterStartDocument(writer, NULL, "utf-8", NULL); rc = xmlTextWriterStartElement(writer, BAD_CAST "consReciNFe"); if (rc < 0) return NULL; rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns", BAD_CAST "http://www.portalfiscal.inf.br/nfe"); if (rc < 0) return NULL; rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "versao", BAD_CAST NFE_VERSAO); if (rc < 0) return NULL; rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "tpAmb", "%d", ambiente); if (rc < 0) return NULL; rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "nRec", "%s", lote->recibo); if (rc < 0) return NULL; rc = xmlTextWriterEndElement(writer); if (rc < 0) return NULL; xmlTextWriterEndDocument(writer); xmlNodeDump(buf, NULL, xmlDocGetRootElement(doc), 0, 0); return (char*)buf->content; }
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); } }