Ejemplo n.º 1
0
celix_status_t endpointDescriptorWriter_writeDocument(endpoint_descriptor_writer_pt writer, array_list_pt endpoints, char **document) {
    celix_status_t status = CELIX_SUCCESS;
    int rc;

    rc = xmlTextWriterStartDocument(writer->writer, NULL, "UTF-8", NULL);
    if (rc < 0) {
        status = CELIX_BUNDLE_EXCEPTION;
    } else {
        rc = xmlTextWriterStartElementNS(writer->writer, NULL, ENDPOINT_DESCRIPTIONS, XMLNS);
        if (rc < 0) {
            status = CELIX_BUNDLE_EXCEPTION;
        } else {
            unsigned int i;
            for (i = 0; i < arrayList_size(endpoints); i++) {
                endpoint_description_pt endpoint = arrayList_get(endpoints, i);
                status = endpointDescriptorWriter_writeEndpoint(writer, endpoint);
            }
            if (status == CELIX_SUCCESS) {
                rc = xmlTextWriterEndElement(writer->writer);
                if (rc < 0) {
                    status = CELIX_BUNDLE_EXCEPTION;
                } else {
                    rc = xmlTextWriterEndDocument(writer->writer);
                    if (rc < 0) {
                        status = CELIX_BUNDLE_EXCEPTION;
                    } else {
                        *document = (char *) writer->buffer->content;
                    }
                }
            }
        }
    }

    return status;
}
Ejemplo n.º 2
0
char *generate_xml(NFE *nfe, 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 = gen_inf_nfe(writer, nfe);
	if (rc < 0)
		return NULL;
	xmlTextWriterEndDocument(writer);
	char *URI = malloc(sizeof(char) * (strlen(nfe->idnfe->chave) +
		strlen(ID_PREFIX) + 2));
	strcpy(URI, "#");
	strcat(URI, ID_PREFIX);
	strcat(URI, nfe->idnfe->chave);
	rc = sign_xml(doc, key, cert, URI);
	if(rc)
		return NULL;
	xmlNodeDump(buf, NULL, xmlDocGetRootElement(doc), 0, 0);
	nfe->xml = strdup((char*)buf->content);
	return (char*)buf->content;
}
Ejemplo n.º 3
0
static void
output (char **roots)
{
  xmlOutputBufferPtr ob = xmlOutputBufferCreateFd (1, NULL);
  if (ob == NULL) {
    fprintf (stderr,
             _("%s: xmlOutputBufferCreateFd: failed to open stdout\n"),
             guestfs_int_program_name);
    exit (EXIT_FAILURE);
  }

  /* 'ob' is freed when 'xo' is freed.. */
  CLEANUP_XMLFREETEXTWRITER xmlTextWriterPtr xo = xmlNewTextWriter (ob);
  if (xo == NULL) {
    fprintf (stderr,
             _("%s: xmlNewTextWriter: failed to create libxml2 writer\n"),
             guestfs_int_program_name);
    exit (EXIT_FAILURE);
  }

  /* 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));
}
Ejemplo n.º 4
0
char *gen_export_nfe_xml(NFE *nfe){
	int rc, buffersize;
	xmlTextWriterPtr writer;
	xmlDocPtr doc;
	xmlChar *xmlbuf;

	writer = xmlNewTextWriterDoc(&doc, 0);
	if (writer == NULL)
		return NULL;
	xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL);
	rc = xmlTextWriterStartElement(writer, BAD_CAST "nfeProc");
	if (rc < 0)
		return NULL;
	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "versao",
			BAD_CAST NFE_VERSAO);
	if (rc < 0)
		return NULL;
	rc = xmlTextWriterWriteRaw(writer, BAD_CAST nfe->xml);
	if (rc < 0)
		return NULL;
	rc = xmlTextWriterWriteRaw(writer, BAD_CAST nfe->protocolo->xml);
	if (rc < 0)
		return NULL;
	rc = xmlTextWriterEndElement(writer);
	if (rc < 0)
		return NULL;
	xmlTextWriterEndDocument(writer);
	xmlDocDumpMemory(doc, &xmlbuf, &buffersize);
	return (char*)xmlbuf;
}
Ejemplo n.º 5
0
static int qgs_write_mem(xmlTextWriter *writer, qgs_t *qgs)
{
  if (qgs->n < 2)
    {
      btrace("not enough stops for a gradient (%zi)", qgs->n);
      return 1;
    }

  if (xmlTextWriterWriteDTD(writer, BAD_CAST "qgis_style", NULL, NULL, NULL) < 0)
    {
      btrace("error writing doctype");
      return 1;
    }

  if (qgs_write_qgis(writer, qgs) != 0)
    {
      btrace("failed to write qgis");
      return 1;
    }

  if (xmlTextWriterEndDocument(writer) < 0)
    {
      btrace("error from end document");
      return 1;
    }

  return 0;
}
Ejemplo n.º 6
0
bool c_XMLWriter::t_enddocument() {
  int ret = -1;
  if (m_ptr) {
    ret = xmlTextWriterEndDocument(m_ptr);
  }
  return ret != -1;
}
Ejemplo n.º 7
0
void queryFavouriteFileProvider::SaveFavourites(queryFavouriteFolder *favourites)
{
	xmlTextWriterPtr writer;

	writer = xmlNewTextWriterFilename((const char *)settings->GetFavouritesFile().mb_str(wxConvUTF8), 0);
	if (!writer)
	{
		wxMessageBox(_("Failed to write to favourites file!"));
		return;
	}
	xmlTextWriterSetIndent(writer, 1);

	if ((xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL) < 0) ||
	        (xmlTextWriterStartElement(writer, XML_STR("favourites")) < 0))
	{
		wxMessageBox(_("Failed to write to favourites file!"));
		xmlFreeTextWriter(writer);
		return;
	}

	((queryFavouriteFolder *)favourites)->saveFolder(writer);

	if (xmlTextWriterEndDocument(writer) < 0)
	{
		wxMessageBox(_("Failed to write to favourites file!"));
	}

	xmlFreeTextWriter(writer);
}
Ejemplo n.º 8
0
AEResult AEXMLWriter::FinalizeXML()
{
	if (!m_IsReady)
	{
		return AEResult::NotReady;
	}

	AEResult ret = AEResult::Ok;

	int rsc = xmlTextWriterEndDocument(m_XMLWriter);
	if (rsc < 0)
	{
		AETODO("Better return code");
		return AEResult::Fail;
	}

	if (m_InMemory)
	{
		std::ofstream xmlFile(m_Filename);
		if (xmlFile.is_open())
		{
			xmlFile << (const char *)m_XMLBuffer->content;
			xmlFile.close();
		}
		else
		{
			ret = AEResult::OpenFileFail;
		}
	}

	CleanUp();

	return ret;
}
Ejemplo n.º 9
0
std::string XMLSchema::xml() const
{
    xmlBuffer *b = xmlBufferCreate();
    xmlTextWriterPtr w = xmlNewTextWriterMemory(b, 0);

    xmlTextWriterSetIndent(w, 1);
    xmlTextWriterStartDocument(w, NULL, "utf-8", NULL);
    xmlTextWriterStartElementNS(w, (const xmlChar*)"pc",
        (const xmlChar*)"PointCloudSchema", NULL);
    xmlTextWriterWriteAttributeNS(w, (const xmlChar*) "xmlns",
        (const xmlChar*)"pc", NULL,
        (const xmlChar*)"http://pointcloud.org/schemas/PC/");
    xmlTextWriterWriteAttributeNS(w, (const xmlChar*)"xmlns",
        (const xmlChar*)"xsi", NULL,
        (const xmlChar*)"http://www.w3.org/2001/XMLSchema-instance");

    writeXml(w);

    xmlTextWriterEndElement(w);
    xmlTextWriterEndDocument(w);

    std::string output((const char *)b->content, b->use);
    xmlFreeTextWriter(w);
    xmlBufferFree(b);

    return output;
}
Ejemplo n.º 10
0
void queryMacroFileProvider::SaveMacros(queryMacroList *macros)
{
	xmlTextWriterPtr writer;

	writer = xmlNewTextWriterFilename((const char *)settings->GetMacrosFile().mb_str(wxConvUTF8), 0);
	if (!writer)
	{
		wxMessageBox(_("Failed to open macros file!"));
		return;
	}
	xmlTextWriterSetIndent(writer, 1);

	if ((xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL) < 0) ||
	        (xmlTextWriterStartElement(writer, XML_STR("macros")) < 0))
	{
		wxMessageBox(_("Failed to write to macros file!"));
		xmlFreeTextWriter(writer);
		return;
	}

	((queryMacroList *)macros)->saveList(writer);

	if (xmlTextWriterEndDocument(writer) < -1)
	{
		wxMessageBox(_("Failed to write to macros file!"));
	}

	xmlFreeTextWriter(writer);
}
Ejemplo n.º 11
0
char* fileinfo_get(char* path) {
    FILE* file;
    xmlBufferPtr buf;
    xmlTextWriterPtr writer;
    char* ret;
    int wordCount;

    file  = fopen(path, "r");
    wordCount = countWords(file);
    fclose(file);

    buf = xmlBufferCreate();
    writer = xmlNewTextWriterMemory(buf, 0);

    xmlTextWriterStartDocument(writer, NULL, XML_E, NULL);


    xmlTextWriterStartElement(writer, BAD_CAST "fileInfo");
    xmlTextWriterWriteFormatElement(writer, BAD_CAST "wordCount", "%d", wordCount);
    xmlTextWriterEndElement(writer);

    xmlTextWriterEndDocument(writer);

    ret = malloc(buf->size);
    strcpy(ret,(char*)buf->content);
    xmlBufferFree(buf);

    return ret;
}
Ejemplo n.º 12
0
int write_volumeindex(opendcp_t *opendcp) {
    xmlIndentTreeOutput = 1;
    xmlDocPtr        doc;
    xmlTextWriterPtr xml;
    int              rc;

    dcp_log(LOG_INFO,"Writing VOLINDEX file %.256s",opendcp->volindex.filename);

    /* create XML document */
    xml = xmlNewTextWriterDoc(&doc,0);

    /* volumeindex XML Start */
    rc = xmlTextWriterStartDocument(xml, NULL, XML_ENCODING, NULL);
    if (rc < 0) {
        dcp_log(LOG_ERROR,"xmlTextWriterStartDocument failed");
        return DCP_FATAL;
    }

    xmlTextWriterStartElement(xml, BAD_CAST "VolumeIndex");
    xmlTextWriterWriteAttribute(xml, BAD_CAST "xmlns", BAD_CAST NS_AM[opendcp->ns]);
    xmlTextWriterWriteFormatElement(xml, BAD_CAST "Index","%d",1);
    xmlTextWriterEndElement(xml); 

    rc = xmlTextWriterEndDocument(xml);
    if (rc < 0) {
        dcp_log(LOG_ERROR,"xmlTextWriterEndDocument failed %s",opendcp->volindex.filename);
        return DCP_FATAL;
    }

    xmlFreeTextWriter(xml);
    xmlSaveFormatFile(opendcp->volindex.filename, doc, 1);
    xmlFreeDoc(doc);

    return DCP_SUCCESS;
}
bool TasksetWriter::write(const std::string& filename, vector<Task*>& taskset) const {
    xmlDocPtr doc;
    tDebug() << "Writing Taskset to XML file: " << filename;

    xmlTextWriterPtr writer;
    writer = xmlNewTextWriterDoc(&doc, 0);
    xmlTextWriterSetIndent(writer, 1);
    if (xmlTextWriterSetIndentString(writer, (const xmlChar*) "  ") != 0) {
        tError() << "Fehler beim Setzen des Einrueckens!";
    }

    xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL);

    xmlTextWriterWriteComment(writer, (xmlChar*) "Hier kommen die Tasks");

    xmlTextWriterStartElement(writer, (xmlChar*) "taskset");
    xmlTextWriterWriteAttributeNS(writer, (xmlChar*) "xsi", (xmlChar*) "schemaLocation", (xmlChar*) "http://www.w3.org/2001/XMLSchema-instance", (xmlChar*) "http://www.tmsxmlns.com taskset.xsd");
    xmlTextWriterWriteAttribute(writer, (xmlChar*) "xmlns", (xmlChar*) "http://www.tmsxmlns.com");

    xmlTextWriterWriteRaw(writer, (xmlChar*) "\n");

    for (size_t i = 0; i < taskset.size(); i++) {
        xmlTextWriterWriteRaw(writer, (xmlChar*) "\n");
        //taskset[i]->write(writer);
        taskset[i]->writeToXML(writer);
        xmlTextWriterWriteRaw(writer, (xmlChar*) "\n");
    }

    xmlTextWriterEndElement(writer); // close TaskSet

    xmlTextWriterEndDocument(writer);
    xmlFreeTextWriter(writer);
    xmlSaveFile(filename.c_str(), doc);

    xmlNodePtr cur = xmlDocGetRootElement(doc);
    if (cur == NULL) {
        tError() << "Empty document.";
        xmlFreeDoc(doc);
        return false;
    }
    if (xmlStrcmp(cur->name, (const xmlChar *) "taskset")) {
        tError() << "Document of the wrong type, root node != taskset";
        xmlFreeDoc(doc);
        return false;
    }

    if (isValid(doc) > 0) {
        tDebug() << "Written document is valid";

    } else {
        tError() << "Written document is invalid";
        xmlFreeDoc(doc);
        return false;
    }

    xmlFreeDoc(doc);

    return true;

}
Ejemplo n.º 14
0
/* Private exporting functions cpe_*<structure>*_export( xmlTextWriterPtr )
 * More info in representive header file.
 * returns the type of <structure>
 */
void cpe_lang_model_export_xml(const struct cpe_lang_model *spec, const char *file)
{

	__attribute__nonnull__(spec);
	__attribute__nonnull__(file);

	// TODO: ad macro to check return value from xmlTextWriter* functions
	xmlTextWriterPtr writer;

	writer = xmlNewTextWriterFilename(file, 0);
	if (writer == NULL) {
		oscap_setxmlerr(xmlGetLastError());
		return;
	}
	// Set properties of writer TODO: make public function to edit this ??
	xmlTextWriterSetIndent(writer, 1);
	xmlTextWriterSetIndentString(writer, BAD_CAST "    ");

	xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL);

	cpe_lang_export(spec, writer);
	xmlTextWriterEndDocument(writer);
	xmlFreeTextWriter(writer);
	if (xmlGetLastError() != NULL)
		oscap_setxmlerr(xmlGetLastError());
}
Ejemplo n.º 15
0
bool XMLInOut::SaveScript(const char* filename)
{
	int rc;
	ofstream out;
	// First check to see that we can open the filename before saving/killing the document.

	assert(filename);
	out.open(filename);

	if (out.fail())
		return false;

	rc = xmlTextWriterEndDocument(writer);
    if (rc < 0) {
        printf("testXmlwriterMemory: Error at xmlTextWriterEndDocument\n");
        return false;
    }

    // Now print it or write it...
    cout << "XML Command being saved:" << endl
    		<< "'" << (const char *) buf->content << "'" << endl;

	out << buf->content;
	out.close();

    // Reset back to zero. New document.
    SetupDoc();
    return true;
}
Ejemplo n.º 16
0
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] = "";
	strcat(dst_file, dst_dir);
	strcat(dst_file, filename);
	
	xmlTextWriterPtr writer;

	writer = xmlNewTextWriterFilename(dst_file, 0);
	
	// set the output format of the XML file 
	xmlTextWriterSetIndent(writer, 1);
	xmlTextWriterSetIndentString(writer, "	");

	xmlTextWriterStartDocument(writer, NULL, NULL, NULL);

    /* Write an element named "X_ORDER_ID" as child of HEADER. */
   xmlTextWriterWriteFormatElement(writer, "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, "OCG_GET_OPT       ", "	%d	", get_opt_OK);
	xmlTextWriterWriteFormatElement(writer, "OCG_DETECT_FILE   ", "	%d	", detect_file_OK);
	xmlTextWriterWriteFormatElement(writer, "OCG_PARSE_FILENAME", "	%d	", parse_filename_OK);
	xmlTextWriterWriteFormatElement(writer, "OCG_CREATE_DIR    ", "	%d	", create_dir_OK);
	xmlTextWriterWriteFormatElement(writer, "OCG_PARSE_XML     ", "	%d	", parse_XML_OK);
	xmlTextWriterWriteFormatElement(writer, "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;
}
Ejemplo n.º 17
0
bool c_XMLWriter::t_enddocument() {
  INSTANCE_METHOD_INJECTION_BUILTIN(XMLWriter, XMLWriter::enddocument);
  int ret = -1;
  if (m_ptr) {
    ret = xmlTextWriterEndDocument(m_ptr);
  }
  return ret != -1;
}
Ejemplo n.º 18
0
void XmlWriter::close()
{
    int written = xmlTextWriterEndDocument(xmlWriter_);
    if (-1 == written)
    {
          BOOST_THROW_EXCEPTION(XmlWriterException(std::string("xmlTextWriterEndDocument returned -1")));
    }
}
Ejemplo n.º 19
0
cpXmlCmdOutput::~cpXmlCmdOutput()
{
    /* Here we could close open elements but since we do not want to
     * write any other elements, we simply call xmlTextWriterEndDocument,
     * which will do all the work */
    if ( xmlTextWriterEndDocument( writer ) < 0 )
       throw ::std::runtime_error( "Error ending to the output document" );

    xmlFreeTextWriter( writer );
}
Ejemplo n.º 20
0
void Free_Writer(CXMLWRITER *test)
{
	if (test->writer)
	{
		xmlTextWriterEndDocument(test->writer);
		xmlFreeTextWriter(test->writer);
		test->writer=NULL;
	}
	if (test->buffer) xmlBufferFree(test->buffer);
	test->buffer=NULL;
}
Ejemplo n.º 21
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;
        }
    }
}
Ejemplo n.º 22
0
// 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;
}
Ejemplo n.º 23
0
/**
 * @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;
}
Ejemplo n.º 24
0
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);
}
Ejemplo n.º 25
0
/**
 * xml_writer_write_end_document:
 * @writer: A #XmlWriter
 *
 * End an xml document. All open elements are closed, and
 * the content is flushed to the output.
 *
 * Return value: the number of bytes written or -1 in case of error
 */
gsize
xml_writer_write_end_document (XmlWriter *writer)
{
  XmlWriterPrivate *priv;
  
  g_return_val_if_fail (XML_IS_WRITER (writer), -1);
  
  priv = writer->priv;
  
  if (priv->writer)
    return xmlTextWriterEndDocument (priv->writer);
  
  return -1;
}
Ejemplo n.º 26
0
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;
}
Ejemplo n.º 27
0
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;
}
Ejemplo n.º 28
0
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;
}
Ejemplo n.º 29
0
/**
Writes the report footer to Xml file..

Write the xml end doc info..
Release the writer pointer from the buffer.
Writes the buffer content to xml file.
Frees the xml buffer.

@internalComponent
@released
*/
void XmlWriter::EndReport(void)
{
	xmlTextWriterEndElement(iXmlTextWriter);
	xmlTextWriterEndElement(iXmlTextWriter);
	xmlTextWriterEndDocument(iXmlTextWriter);
	xmlFreeTextWriter(iXmlTextWriter);
	
	iXmlFile.clear(); 
	iXmlFile.write((const char *)iXmlBufPtr->content,iXmlBufPtr->use);
	 
	if(iXmlFile.fail()){
		xmlBufferFree(iXmlBufPtr);
		throw ExceptionReporter(NODISKSPACE, (char*)iXmlFileName.c_str()); 
	}
	xmlBufferFree(iXmlBufPtr);
}
Ejemplo n.º 30
0
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;
}