Esempio n. 1
0
/*
   ===========
   QE_SaveProject
   TTimo: whenever QE_SaveProject is called, prefs are updated and saved with the path to the project
   ===========
 */
qboolean QE_SaveProject( const char* filename ){
	Sys_Printf( "Save project file '%s'\n", filename );

	xmlNodePtr node;
	xmlDocPtr doc = xmlNewDoc( (xmlChar *)"1.0" );
	// create DTD node
	xmlCreateIntSubset( doc, (xmlChar *)"project", NULL, (xmlChar *)"project.dtd" );
	// create project node
	doc->children->next = xmlNewDocNode( doc, NULL, (xmlChar *)"project", NULL );

	for ( epair_t* epair = g_qeglobals.d_project_entity->epairs; epair != NULL; epair = epair->next )
	{
		node = xmlNewChild( doc->children->next, NULL, (xmlChar *)"key", NULL );
		xmlSetProp( node, (xmlChar*)"name", (xmlChar*)epair->key );
		xmlSetProp( node, (xmlChar*)"value", (xmlChar*)epair->value );
	}

	CreateDirectoryPath( filename );
	if ( xmlSaveFormatFile( filename, doc, 1 ) != -1 ) {
		xmlFreeDoc( doc );
		Sys_Printf( "Setting current project in prefs to \"%s\"\n", filename );
		g_PrefsDlg.m_strLastProject = filename;
		g_PrefsDlg.SavePrefs();
		return TRUE;
	}
	else
	{
		xmlFreeDoc( doc );
		Sys_FPrintf( SYS_ERR, "failed to save project file: \"%s\"\n", filename );
		return FALSE;
	}
}
Esempio n. 2
0
static xmlDocPtr
hwloc__libxml2_prepare_export(hwloc_topology_t topology)
{
  struct hwloc__xml_export_state_s state;
  hwloc__libxml_export_state_data_t data = (void *) state.data;
  xmlDocPtr doc = NULL;       /* document pointer */
  xmlNodePtr root_node = NULL; /* root pointer */

  assert(sizeof(*data) <= sizeof(state.data));

  LIBXML_TEST_VERSION;
  hwloc_libxml2_disable_stderrwarnings();

  /* Creates a new document, a node and set it as a root node. */
  doc = xmlNewDoc(BAD_CAST "1.0");
  root_node = xmlNewNode(NULL, BAD_CAST "topology");
  xmlDocSetRootElement(doc, root_node);

  /* Creates a DTD declaration. Isn't mandatory. */
  (void) xmlCreateIntSubset(doc, BAD_CAST "topology", NULL, BAD_CAST "hwloc.dtd");

  state.new_child = hwloc__libxml_export_new_child;
  state.new_prop = hwloc__libxml_export_new_prop;
  state.add_content = hwloc__libxml_export_add_content;
  state.end_object = hwloc__libxml_export_end_object;

  data->current_node = root_node;

  hwloc__xml_export_object (&state, topology, hwloc_get_root_obj(topology));

  return doc;
}
Esempio n. 3
0
static xmlDocPtr
hwloc__libxml2_prepare_export_diff(hwloc_topology_diff_t diff, const char *refname)
{
  struct hwloc__xml_export_state_s state;
  hwloc__libxml_export_state_data_t data = (void *) state.data;
  xmlDocPtr doc = NULL;       /* document pointer */
  xmlNodePtr root_node = NULL; /* root pointer */

  assert(sizeof(*data) <= sizeof(state.data));

  LIBXML_TEST_VERSION;
  hwloc_libxml2_init_once();

  /* Creates a new document, a node and set it as a root node. */
  doc = xmlNewDoc(BAD_CAST "1.0");
  root_node = xmlNewNode(NULL, BAD_CAST "topologydiff");
  if (refname)
    xmlNewProp(root_node, BAD_CAST "refname", BAD_CAST refname);
  xmlDocSetRootElement(doc, root_node);

  /* Creates a DTD declaration. Isn't mandatory. */
  (void) xmlCreateIntSubset(doc, BAD_CAST "topologydiff", NULL, BAD_CAST "hwloc.dtd");

  state.new_child = hwloc__libxml_export_new_child;
  state.new_prop = hwloc__libxml_export_new_prop;
  state.add_content = hwloc__libxml_export_add_content;
  state.end_object = hwloc__libxml_export_end_object;

  data->current_node = root_node;

  hwloc__xml_export_diff (&state, diff);

  return doc;
}
Esempio n. 4
0
/*
 * call-seq:
 *  create_internal_subset(name, external_id, system_id)
 *
 * Create the internal subset of a document.
 *
 *   doc.create_internal_subset("chapter", "-//OASIS//DTD DocBook XML//EN", "chapter.dtd")
 *   # => <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML//EN" "chapter.dtd">
 *
 *   doc.create_internal_subset("chapter", nil, "chapter.dtd")
 *   # => <!DOCTYPE chapter SYSTEM "chapter.dtd">
 */
static VALUE create_internal_subset(VALUE self, VALUE name, VALUE external_id, VALUE system_id)
{
  xmlNodePtr node;
  xmlDocPtr doc;
  xmlDtdPtr dtd;

  Data_Get_Struct(self, xmlNode, node);

  doc = node->doc;

  if(xmlGetIntSubset(doc)) {
    rb_raise(rb_eRuntimeError, "Document already has an internal subset");
  }

  dtd = xmlCreateIntSubset(
          doc,
          NIL_P(name)        ? NULL : (const xmlChar *)StringValueCStr(name),
          NIL_P(external_id) ? NULL : (const xmlChar *)StringValueCStr(external_id),
          NIL_P(system_id)   ? NULL : (const xmlChar *)StringValueCStr(system_id)
        );

  if(!dtd) { return Qnil; }

  return Nokogiri_wrap_xml_node(Qnil, (xmlNodePtr)dtd);
}
Esempio n. 5
0
/* {{{ proto DOMDocumentType dom_domimplementation_create_document_type(string qualifiedName, string publicId, string systemId);
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Level-2-Core-DOM-createDocType
Since: DOM Level 2
*/
PHP_METHOD(domimplementation, createDocumentType)
{
	xmlDtd *doctype;
	int ret;
	size_t name_len = 0, publicid_len = 0, systemid_len = 0;
	char *name = NULL, *publicid = NULL, *systemid = NULL;
	xmlChar *pch1 = NULL, *pch2 = NULL, *localname = NULL;
	xmlURIPtr uri;

	if (zend_parse_parameters(ZEND_NUM_ARGS(), "|sss", &name, &name_len, &publicid, &publicid_len, &systemid, &systemid_len) == FAILURE) {
		return;
	}

	if (name_len == 0) {
		php_error_docref(NULL, E_WARNING, "qualifiedName is required");
		RETURN_FALSE;
	}

	if (publicid_len > 0) {
		pch1 = (xmlChar *) publicid;
	}
	if (systemid_len > 0) {
		pch2 = (xmlChar *) systemid;
	}

	uri = xmlParseURI(name);
	if (uri != NULL && uri->opaque != NULL) {
		localname = xmlStrdup((xmlChar *) uri->opaque);
		if (xmlStrchr(localname, (xmlChar) ':') != NULL) {
			php_dom_throw_error(NAMESPACE_ERR, 1);
			xmlFreeURI(uri);
			xmlFree(localname);
			RETURN_FALSE;
		}
	} else {
		localname = xmlStrdup((xmlChar *) name);
	}

	/* TODO: Test that localname has no invalid chars
	php_dom_throw_error(INVALID_CHARACTER_ERR,);
	*/

	if (uri) {
		xmlFreeURI(uri);
	}

	doctype = xmlCreateIntSubset(NULL, localname, pch1, pch2);
	xmlFree(localname);

	if (doctype == NULL) {
		php_error_docref(NULL, E_WARNING, "Unable to create DocumentType");
		RETURN_FALSE;
	}

	DOM_RET_OBJ((xmlNodePtr) doctype, &ret, NULL);
}
Esempio n. 6
0
char *
epg_to_xmltv(const struct epg *epg)
{
    xmlDocPtr  doc  = NULL;
    xmlDtdPtr  dtd  = NULL;
    xmlNodePtr root = NULL;
    xmlChar   *s    = NULL;

    error_if(epg == NULL, error, "Param Error");

    LIBXML_TEST_VERSION;

    doc = xmlNewDoc((const xmlChar *)"1.0");
    error_if(doc == NULL, error, "Error Creating xmlDoc");

    root = xmlNewDocNode(doc, NULL, BAD_CAST "tv", NULL);
    error_if(root == NULL, error, "Error creating root node");

    dtd = xmlCreateIntSubset(doc, BAD_CAST "tv", NULL, BAD_CAST "epg.dtd");
    error_if(dtd == NULL, error, "Error adding DTD to xmlDoc");

    xmlDocSetRootElement(doc, root);
    xmlNewProp(root,
           BAD_CAST "generator-info-name",
           BAD_CAST "tvz_epg - https://github.com/virgiliosanz/movistar_sv");

    trace("%s", "Adding programmes");
    _programmes_to_xml(root, epg->programmes);

    trace("%s", "Adding channels");
    _channels_to_xml(root, epg->channels);

    trace("calling xmlDocDumpMemory chan: %zu prog: %zu",
        list_count(epg->channels), list_count(epg->programmes));

    int size;
    xmlDocDumpMemoryEnc(doc, &s, &size, "UTF-8");
    xmlCleanupParser();

    return (char *)s;

 error:
    xmlCleanupParser();
    if (s) free(s);

    return NULL;
}
Esempio n. 7
0
void Map_Write( CPtrArray *map, IDataStream *out ){
	xmlChar* buf;
	int len;

	xmlDocPtr doc = xmlNewDoc( (xmlChar *)"1.0" );
	xmlCreateIntSubset( doc, (xmlChar *)"mapq3", NULL, (xmlChar *)"mapq3.dtd" );
	doc->children->next = xmlNewDocNode( doc, NULL, (xmlChar *)"mapq3", NULL );

	Map_XMLWrite( map, doc->children->next );

	// xmlDocDumpMemory(doc, &buf, &len);
	xmlDocDumpFormatMemory( doc, &buf, &len, 1 );
	xmlFreeDoc( doc );

	out->Write( buf, len );

	xmlFree( buf );
}
Esempio n. 8
0
bool CSpmXml::New(const QString& strRootNode, const QString& strDTDFile)
{
	Destroy();

	m_pXMLDoc = xmlNewDoc(BAD_CAST "1.0");
	if (0 == m_pXMLDoc)
		return false;

	m_pCurNode = xmlNewNode(0, BAD_CAST strRootNode.toUtf8().data());
	if (0 == m_pCurNode)
		return false;

	xmlDocSetRootElement(m_pXMLDoc, m_pCurNode);
	
	if (strDTDFile.size())
		xmlCreateIntSubset(m_pXMLDoc, BAD_CAST strRootNode.toUtf8().data(), NULL, BAD_CAST strDTDFile.toUtf8().data());

	SetModified();
	return true;
}
Esempio n. 9
0
static xmlEntityPtr
xml_process_entities (void *ctxt, const xmlChar *name)
{
	gchar *path;
	xmlEntityPtr entity;
	xmlEntityPtr found;
	xmlChar *tmp;
	static xmlDocPtr entities = NULL;

	entity = xmlGetPredefinedEntity (name);

	if (!entity) {
		if (!entities) {
			/* loading HTML entities from external DTD file */
			entities = xmlNewDoc (BAD_CAST "1.0");
			path = g_build_filename (g_get_user_data_dir (), PACKAGE, "/dtd/html.ent", NULL);
			xmlCreateIntSubset (entities, BAD_CAST "HTML entities", NULL, BAD_CAST path);
			g_free (path);
			entities->extSubset = xmlParseDTD (entities->intSubset->ExternalID, entities->intSubset->SystemID);
		}

		if (NULL != (found = xmlGetDocEntity (entities, name))) {
			/* returning as faked predefined entity... */
			tmp = xmlStrdup (found->content);
			tmp = BAD_CAST unhtmlize ((gchar*) tmp);	/* arghh ... slow... */
			entity = (xmlEntityPtr) g_new0 (xmlEntity, 1);
			entity->type = XML_ENTITY_DECL;
			entity->name = name;
			entity->orig = NULL;
			entity->content = tmp;
			entity->length = g_utf8_strlen ((gchar*) tmp, -1);
			entity->etype = XML_INTERNAL_PREDEFINED_ENTITY;
		}
	}

	return entity;
}
Esempio n. 10
0
void SC_ASIYA::save_xml(string report_xml, string TGT, string REF, string METRIC, const MetricScore &m) {
    vector<vector<string> > idx = TESTBED::IDX[TGT];

    /*    cout << "-----------------idx-------------------" << endl;
        for (int i = 0; i < idx.size(); ++i) {
                //cout << "\tidx[" << i << "]" << endl;
                for(int j = 0; j < idx[i].size(); ++j) {
                        cout << "\t\tidx[" << i << "][" << j << "]: " << idx[i][j] << endl;
                }
                cout << endl;
        }
        cout << "---------------------------------------" << endl;

        for(int i = 0; i < doc_scores.size(); ++i) cout << "doc_scores[" << i  << "]: " << doc_scores[i] << endl;
        for(int i = 0; i < seg_scores.size(); ++i) cout << "seg_scores[" << i  << "]: " << seg_scores[i] << endl;*/



    int i = 1;
    int n_docs, n_doc_segs;
    n_docs = n_doc_segs = 0;

    string DOC = "-1";
    string document_id = "";

    // -> STORE IQREPORT
    xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
    xmlNodePtr root_node = xmlNewNode(NULL, BAD_CAST "REPORT");
    xmlDocSetRootElement(doc, root_node);

    string app_name = Common::appNAME;
    boost::to_lower(app_name);
    string doc_type = app_name + ".dtd []"; //"!DOCTYPE " + SC_ASIYA::ROOT_ELEMENT + " \"" + app_name +".dtd\" []";
    xmlDtdPtr dtd = xmlCreateIntSubset(doc, BAD_CAST SC_FORMAT::ROOT_ELEMENT.c_str(), NULL, BAD_CAST doc_type.c_str());

/*
    xmlNewProp(root_node, BAD_CAST "hyp",       BAD_CAST    TGT.c_str());
    xmlNewProp(root_node, BAD_CAST "metric",    BAD_CAST    METRIC.c_str());

    char buffer[50];
    sprintf(buffer, "%d", n_docs);
    xmlNewProp(root_node, BAD_CAST "n_docs",    (const xmlChar *) buffer);

    sprintf(buffer, "%d", seg_scores.size());
    xmlNewProp(root_node, BAD_CAST "n_segments",(const xmlChar *) buffer);
    xmlNewProp(root_node, BAD_CAST "ref",       BAD_CAST    REF.c_str());

    //double x = Common::trunk_and_trim_number(sys_score, SC_ASIYA::FLOAT_LENGTH, SC_ASIYA::FLOAT_PRECISION);
    double x = sys_score;
    sprintf(buffer, "%f", x);
    xmlNewProp(root_node, BAD_CAST "score",     (const xmlChar *) buffer);
*/

    //double x;
    char buffer[256];
    xmlNodePtr doc_node = xmlNewChild(root_node, NULL, BAD_CAST "DOC", NULL);

    while (i < idx.size()) {
        if (idx[i][0] != document_id) { // NEW DOCUMENT

            if (DOC != "-1") {
                //x = Common::trunk_and_trim_number(doc_scores[n_docs - 1], SC_ASIYA::FLOAT_LENGTH, SC_ASIYA::FLOAT_PRECISION);
                //x = m.doc_scores[n_docs-1];
                xmlNewProp(doc_node, BAD_CAST "id",         BAD_CAST document_id.c_str());

                sprintf(buffer, "%d", n_docs);
                xmlNewProp(doc_node, BAD_CAST "n",          (const xmlChar *) buffer);

                sprintf(buffer, "%d", n_doc_segs);
                xmlNewProp(doc_node, BAD_CAST "n_segments", (const xmlChar *) buffer);

                //sprintf(buffer, "%.%df", x);
                //trunk_and_trim_number(m.doc_scores[n_docs-1]);
                xmlNewProp(doc_node, BAD_CAST "score",      (const xmlChar *) trunk_and_trim_number(m.doc_scores[n_docs-1]).c_str());

                doc_node = xmlNewChild(root_node, NULL, BAD_CAST "DOC", NULL);
            }
            DOC = document_id = idx[i][0];
            n_docs++;
            n_doc_segs = 0;
        }

        // CREATE A SEGMENT
        //x = Common::trunk_and_trim_number(seg_scores[i - 1], SC_ASIYA::FLOAT_LENGTH, SC_ASIYA::FLOAT_PRECISION);
        //x = m.seg_scores[i-1];
        //sprintf(buffer, "%f", x);
        xmlNodePtr seg_node = xmlNewChild(doc_node, NULL, BAD_CAST "S", (const xmlChar *) trunk_and_trim_number(m.seg_scores[i-1]).c_str());
        sprintf(buffer, "%d", i);
        xmlNewProp(seg_node, BAD_CAST "n", (const xmlChar *) buffer);
        n_doc_segs++;
        i++;
    }

    // PASTE LAST DOC (if any)
    if (DOC != "-1") {
        //x = Common::trunk_and_trim_number(doc_scores[n_docs - 1], SC_ASIYA::FLOAT_LENGTH, SC_ASIYA::FLOAT_PRECISION);
        //x = m.doc_scores[n_docs-1];
        //doc_node = xmlNewChild(root_node, NULL, BAD_CAST "DOC", NULL);
        xmlNewProp(doc_node, BAD_CAST "id",         BAD_CAST document_id.c_str());

        sprintf(buffer, "%d", n_docs);
        xmlNewProp(doc_node, BAD_CAST "n",          (const xmlChar *) buffer);

        sprintf(buffer, "%d", n_doc_segs);
        xmlNewProp(doc_node, BAD_CAST "n_segments", (const xmlChar *) buffer);

        //sprintf(buffer, "%f", x);
        xmlNewProp(doc_node, BAD_CAST "score",      (const xmlChar *) trunk_and_trim_number(m.doc_scores[n_docs-1]).c_str());
    }

    xmlNewProp(root_node, BAD_CAST "hyp",       BAD_CAST    TGT.c_str());
    xmlNewProp(root_node, BAD_CAST "metric",    BAD_CAST    METRIC.c_str());

    //char buffer[50];
    sprintf(buffer, "%d", n_docs);
    xmlNewProp(root_node, BAD_CAST "n_docs",    (const xmlChar *) buffer);

    sprintf(buffer, "%d", (int)m.seg_scores.size());
    xmlNewProp(root_node, BAD_CAST "n_segments",(const xmlChar *) buffer);
    xmlNewProp(root_node, BAD_CAST "ref",       BAD_CAST    REF.c_str());

    //double x = Common::trunk_and_trim_number(sys_score, SC_ASIYA::FLOAT_LENGTH, SC_ASIYA::FLOAT_PRECISION);
    //x = m.sys_score;
    //sprintf(buffer, "%f", x);
    xmlNewProp(root_node, BAD_CAST "score",     (const xmlChar *) trunk_and_trim_number(m.sys_score).c_str());

    xmlSaveFormatFileEnc(report_xml.c_str(), doc, "UTF-8", 1);
    xmlFreeDoc(doc);
    xmlCleanupParser();
}
Esempio n. 11
0
/*
 * call-seq:
 *    XML::Dtd.new("DTD string") -> dtd
 *    XML::Dtd.new("public", "system") -> dtd
 *    XML::Dtd.new("name", "public", "system", document) -> external subset dtd
 *    XML::Dtd.new("name", "public", "system", document, false) -> internal subset dtd
 *    XML::Dtd.new("name", "public", "system", document, true) -> internal subset dtd
 *
 * Create a new Dtd from the specified public and system
 * identifiers.
 */
static VALUE rxml_dtd_initialize(int argc, VALUE *argv, VALUE self)
{
  VALUE external, system, dtd_string;
  xmlParserInputBufferPtr buffer;
  xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
  xmlChar *new_string;
  xmlDtdPtr xdtd;

  // 1 argument -- string                            --> parsujeme jako dtd
  // 2 arguments -- public, system                   --> bude se hledat
  // 3 arguments -- public, system, name             --> creates an external subset (any parameter may be nil)
  // 4 arguments -- public, system, name, doc        --> creates an external subset (any parameter may be nil)
  // 5 arguments -- public, system, name, doc, true  --> creates an internal subset (all but last parameter may be nil)
  switch (argc)
  {
  case 3:
  case 4:
  case 5: {
      VALUE name, doc, internal;
      const xmlChar *xname = NULL, *xpublic = NULL, *xsystem = NULL;
      xmlDocPtr xdoc = NULL;

      rb_scan_args(argc, argv, "32", &external, &system, &name, &doc, &internal);

      if (external != Qnil) {
        Check_Type(external, T_STRING);
        xpublic = (const xmlChar*) StringValuePtr(external);
      }
      if (system != Qnil) {
        Check_Type(system, T_STRING);
        xsystem = (const xmlChar*) StringValuePtr(system);
      }
      if (name != Qnil) {
        Check_Type(name, T_STRING);
        xname = (const xmlChar*) StringValuePtr(name);
      }
      if (doc != Qnil) {
        if (rb_obj_is_kind_of(doc, cXMLDocument) == Qfalse)
          rb_raise(rb_eTypeError, "Must pass an XML::Document object");
        Data_Get_Struct(doc, xmlDoc, xdoc);
      }

      if (internal == Qnil || internal == Qfalse)
        xdtd = xmlNewDtd(xdoc, xname, xpublic, xsystem);
      else
        xdtd = xmlCreateIntSubset(xdoc, xname, xpublic, xsystem);

      if (xdtd == NULL)
        rxml_raise(&xmlLastError);

      /* Document will free this dtd now. */
      RDATA(self)->dfree = NULL;
      DATA_PTR(self) = xdtd;

      xmlSetTreeDoc((xmlNodePtr) xdtd, xdoc);
    }
    break;

  case 2:
    rb_scan_args(argc, argv, "20", &external, &system);

    Check_Type(external, T_STRING);
    Check_Type(system, T_STRING);

    xdtd = xmlParseDTD((xmlChar*) StringValuePtr(external),
        (xmlChar*) StringValuePtr(system));

    if (xdtd == NULL)
      rxml_raise(&xmlLastError);

    DATA_PTR(self) = xdtd;

    xmlSetTreeDoc((xmlNodePtr) xdtd, NULL);
    break;

  case 1:
    rb_scan_args(argc, argv, "10", &dtd_string);
    Check_Type(dtd_string, T_STRING);

    /* Note that buffer is freed by xmlParserInputBufferPush*/
    buffer = xmlAllocParserInputBuffer(enc);
    new_string = xmlStrdup((xmlChar*) StringValuePtr(dtd_string));
    xmlParserInputBufferPush(buffer, xmlStrlen(new_string),
        (const char*) new_string);

    xdtd = xmlIOParseDTD(NULL, buffer, enc);

    if (xdtd == NULL)
      rxml_raise(&xmlLastError);

    xmlFree(new_string);

    DATA_PTR(self) = xdtd;
    break;

  default:
    rb_raise(rb_eArgError, "wrong number of arguments");
  }

  return self;
}
Esempio n. 12
0
File: tree2.cpp Progetto: dtg3/aroma
/* A simple example how to create DOM. Libxml2 automagically 
 * allocates the necessary amount of memory to it.
*/
int
main(int argc, char **argv)
{
    xmlDocPtr doc = NULL;       /* document pointer */
    xmlNodePtr root_node = NULL, node = NULL, node1 = NULL;/* node pointers */
    xmlDtdPtr dtd = NULL;       /* DTD pointer */
    char buff[256];
    int i, j;

    LIBXML_TEST_VERSION;

    /* 
     * Creates a new document, a node and set it as a root node
     */
    doc = xmlNewDoc(BAD_CAST "1.0");
    root_node = xmlNewNode(NULL, BAD_CAST "root");
    xmlDocSetRootElement(doc, root_node);

    /*
     * Creates a DTD declaration. Isn't mandatory. 
     */
    dtd = xmlCreateIntSubset(doc, BAD_CAST "root", NULL, BAD_CAST "tree2.dtd");

    /* 
     * xmlNewChild() creates a new node, which is "attached" as child node
     * of root_node node. 
     */
    xmlNewChild(root_node, NULL, BAD_CAST "node1",
                BAD_CAST "content of node 1");
    /* 
     * The same as above, but the new child node doesn't have a content 
     */
    xmlNewChild(root_node, NULL, BAD_CAST "node2", NULL);

    /* 
     * xmlNewProp() creates attributes, which is "attached" to an node.
     * It returns xmlAttrPtr, which isn't used here.
     */
    node =
        xmlNewChild(root_node, NULL, BAD_CAST "node3",
                    BAD_CAST "this node has attributes");
    xmlNewProp(node, BAD_CAST "attribute", BAD_CAST "yes");
    xmlNewProp(node, BAD_CAST "foo", BAD_CAST "bar");

    /*
     * Here goes another way to create nodes. xmlNewNode() and xmlNewText
     * creates a node and a text node separately. They are "attached"
     * by xmlAddChild() 
     */
    node = xmlNewNode(NULL, BAD_CAST "node4");
    node1 = xmlNewText(BAD_CAST
                   "other way to create content (which is also a node)");
    xmlAddChild(node, node1);
    xmlAddChild(root_node, node);

    /* 
     * A simple loop that "automates" nodes creation 
     */
    for (i = 5; i < 7; i++) {
        sprintf(buff, "node%d", i);
        node = xmlNewChild(root_node, NULL, BAD_CAST buff, NULL);
        for (j = 1; j < 4; j++) {
            sprintf(buff, "node%d%d", i, j);
            node1 = xmlNewChild(node, NULL, BAD_CAST buff, NULL);
            xmlNewProp(node1, BAD_CAST "odd", BAD_CAST((j % 2) ? "no" : "yes"));
        }
    }

    /* 
     * Dumping document to stdio or file
     */
    xmlSaveFormatFileEnc(argc > 1 ? argv[1] : "-", doc, "UTF-8", 1);

    /*free the document */
    xmlFreeDoc(doc);

    /*
     *Free the global variables that may
     *have been allocated by the parser.
     */
    xmlCleanupParser();

    /*
     * this is to debug memory for regression tests
     */
    xmlMemoryDump();
    return(0);
}
Esempio n. 13
0
static DiaSvgRenderer *
new_svg_renderer(DiagramData *data, const char *filename)
{
  DiaSvgRenderer *renderer;
  SvgRenderer *svg_renderer;
  FILE *file;
  gchar buf[512];
  time_t time_now;
  Rectangle *extent;
  const char *name;
  xmlDtdPtr dtd;
 
  file = g_fopen(filename, "w");

  if (file==NULL) {
    message_error(_("Can't open output file %s: %s\n"), 
		  dia_message_filename(filename), strerror(errno));
    return NULL;
  }
  fclose(file);

  /* we need access to our base object */
  renderer = DIA_SVG_RENDERER (g_object_new(SVG_TYPE_RENDERER, NULL));

  renderer->filename = g_strdup(filename);

  renderer->dash_length = 1.0;
  renderer->dot_length = 0.2;
  renderer->saved_line_style = LINESTYLE_SOLID;
  /* apparently most svg readers don't like small values, especially not in the viewBox attribute */
  renderer->scale = 20.0;

  /* set up the root node */
  renderer->doc = xmlNewDoc((const xmlChar *)"1.0");
  renderer->doc->encoding = xmlStrdup((const xmlChar *)"UTF-8");
  renderer->doc->standalone = FALSE;
  dtd = xmlCreateIntSubset(renderer->doc, (const xmlChar *)"svg",
		     (const xmlChar *)"-//W3C//DTD SVG 1.0//EN",
		     (const xmlChar *)"http://www.w3.org/TR/2001/PR-SVG-20010719/DTD/svg10.dtd");
  xmlAddChild((xmlNodePtr) renderer->doc, (xmlNodePtr) dtd);
  renderer->root = xmlNewDocNode(renderer->doc, NULL, (const xmlChar *)"svg", NULL);
  xmlAddSibling(renderer->doc->children, (xmlNodePtr) renderer->root);

  /* add namespaces to make strict parsers happy, e.g. Firefox */
  svg_renderer = SVG_RENDERER (renderer);

  /* set the extents of the SVG document */
  extent = &data->extents;
  g_snprintf(buf, sizeof(buf), "%dcm",
	     (int)ceil((extent->right - extent->left)));
  xmlSetProp(renderer->root, (const xmlChar *)"width", (xmlChar *) buf);
  g_snprintf(buf, sizeof(buf), "%dcm",
	     (int)ceil((extent->bottom - extent->top)));
  xmlSetProp(renderer->root, (const xmlChar *)"height", (xmlChar *) buf);
  g_snprintf(buf, sizeof(buf), "%d %d %d %d",
	     (int)floor(extent->left  * renderer->scale), (int)floor(extent->top * renderer->scale),
	     (int)ceil((extent->right - extent->left) * renderer->scale),
	     (int)ceil((extent->bottom - extent->top) * renderer->scale));
  xmlSetProp(renderer->root, (const xmlChar *)"viewBox", (xmlChar *) buf);
  xmlSetProp(renderer->root,(const xmlChar *)"xmlns", (const xmlChar *)"http://www.w3.org/2000/svg");
  xmlSetProp(renderer->root,(const xmlChar *)"xmlns", (const xmlChar *)"http://www.w3.org/2000/svg");
  xmlSetProp(renderer->root,(const xmlChar *)"xmlns:xlink", (const xmlChar *)"http://www.w3.org/1999/xlink");

  time_now = time(NULL);
  name = g_get_user_name();

#if 0
  /* some comments at the top of the file ... */
  xmlAddChild(renderer->root, xmlNewText("\n"));
  xmlAddChild(renderer->root, xmlNewComment("Dia-Version: "VERSION));
  xmlAddChild(renderer->root, xmlNewText("\n"));
  g_snprintf(buf, sizeof(buf), "File: %s", dia->filename);
  xmlAddChild(renderer->root, xmlNewComment(buf));
  xmlAddChild(renderer->root, xmlNewText("\n"));
  g_snprintf(buf, sizeof(buf), "Date: %s", ctime(&time_now));
  buf[strlen(buf)-1] = '\0'; /* remove the trailing new line */
  xmlAddChild(renderer->root, xmlNewComment(buf));
  xmlAddChild(renderer->root, xmlNewText("\n"));
  g_snprintf(buf, sizeof(buf), "For: %s", name);
  xmlAddChild(renderer->root, xmlNewComment(buf));
  xmlAddChild(renderer->root, xmlNewText("\n\n"));

  xmlNewChild(renderer->root, NULL, "title", dia->filename);
#endif
  
  return renderer;
}
Esempio n. 14
0
void mtx_gauge_face_export_xml(MtxGaugeFace * gauge, const gchar * filename)
{
	guint i = 0;
	xmlDocPtr doc = NULL;       /* document pointer */

	xmlNodePtr root_node = NULL;/* node pointers */

	xmlDtdPtr dtd = NULL;       /* DTD pointer */

	MtxDispatchHelper *helper = NULL;
	MtxXMLFuncs * xml_funcs = NULL;
	MtxGaugeFacePrivate *priv = NULL;

	g_return_if_fail(gauge);
	g_return_if_fail(filename);
	priv = MTX_GAUGE_FACE_GET_PRIVATE(gauge);
	g_return_if_fail(priv);

	LIBXML_TEST_VERSION;

	/* 
	 * Creates a new document, a node and set it as a root node
	 */

	doc = xmlNewDoc(BAD_CAST "1.0");
	root_node = xmlNewNode(NULL, BAD_CAST "gauge");
	xmlDocSetRootElement(doc, root_node);

	/*
	 * Creates a DTD declaration. Isn't mandatory. 
	 */

	dtd = xmlCreateIntSubset(doc, BAD_CAST "gauge", NULL, BAD_CAST "mtxgauge.dtd");

	/* Create a helper struct o bind data to for to 
	 * trim up the XML export functions.
	 */

	helper = g_new0(MtxDispatchHelper, 1);
	helper->gauge = gauge;
	helper->root_node = root_node;
	/** For each element,  get the varname, the pointer to the memory 
	 * where the data is stored in the current gauge structure, and call
	 * the export function defined in the xml_funcs struct passing in the
	 * helper struct so that the generic export functions can get the 
	 * key names right and the memory addresses right.  It looks confusing
	 * but it works great.  See gauge-xml.h for the static struct binding
	 * keynames to import/export generic handler functions */

	for (i=0;i<priv->xmlfunc_array->len;i++)
	{
		xml_funcs = g_array_index(priv->xmlfunc_array,MtxXMLFuncs *, i);
		if (!xml_funcs)
			continue;
		helper->element_name = xml_funcs->varname;
		helper->src = (gpointer)g_object_get_data(G_OBJECT(gauge),xml_funcs->varname);
		if (xml_funcs->export_func)
			xml_funcs->export_func(helper);
	}
	
	g_free(helper);
	/*
	*/



	xmlSaveFormatFileEnc(filename, doc, "utf-8", 1);

	/*free the document */

	xmlFreeDoc(doc);

	/*
	 *Free the global variables that may
	 *have been allocated by the parser.
	 */

	xmlCleanupParser();

	/*
	 * this is to debug memory for regression tests
	 */

	xmlMemoryDump();
	if (priv->xml_filename)
		g_free(priv->xml_filename);

	priv->xml_filename = g_strdup(filename);
}
void mate_wp_xml_save_list (AppearanceData *data) {
    xmlDoc * wplist;
    xmlNode * root, * wallpaper, * item;
    GSList * list = NULL;
    gchar * wpfile;

    g_hash_table_foreach (data->wp_hash,
                          (GHFunc) mate_wp_list_flatten, &list);
    g_hash_table_destroy (data->wp_hash);
    list = g_slist_reverse (list);

    wpfile = g_build_filename (g_get_home_dir (),
                               "/.mate2",
                               "backgrounds.xml",
                               NULL);

    xmlKeepBlanksDefault (0);

    wplist = xmlNewDoc ((xmlChar *)"1.0");
    xmlCreateIntSubset (wplist, (xmlChar *)"wallpapers", NULL, (xmlChar *)"mate-wp-list.dtd");
    root = xmlNewNode (NULL, (xmlChar *)"wallpapers");
    xmlDocSetRootElement (wplist, root);

    while (list != NULL) {
        MateWPItem * wpitem = list->data;
        const char * none = "(none)";
        gchar * filename;
        const gchar * scale, * shade;
        gchar * pcolor, * scolor;

        if (!strcmp (wpitem->filename, none) ||
                (g_utf8_validate (wpitem->filename, -1, NULL) &&
                 g_file_test (wpitem->filename, G_FILE_TEST_EXISTS)))
            filename = g_strdup (wpitem->filename);
        else
            filename = g_filename_to_utf8 (wpitem->filename, -1, NULL, NULL, NULL);

        pcolor = gdk_color_to_string (wpitem->pcolor);
        scolor = gdk_color_to_string (wpitem->scolor);
        scale = wp_item_option_to_string (wpitem->options);
        shade = wp_item_shading_to_string (wpitem->shade_type);

        wallpaper = xmlNewChild (root, NULL, (xmlChar *)"wallpaper", NULL);
        mate_wp_xml_set_bool (wallpaper, (xmlChar *)"deleted", wpitem->deleted);
        item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"name", (xmlChar *)wpitem->name);
        item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"filename", (xmlChar *)filename);
        item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"options", (xmlChar *)scale);
        item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"shade_type", (xmlChar *)shade);
        item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"pcolor", (xmlChar *)pcolor);
        item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"scolor", (xmlChar *)scolor);
        g_free (pcolor);
        g_free (scolor);
        g_free (filename);

        list = g_slist_delete_link (list, list);
        mate_wp_item_free (wpitem);
    }
    xmlSaveFormatFile (wpfile, wplist, 1);
    xmlFreeDoc (wplist);
    g_free (wpfile);
}
Esempio n. 16
0
void export_dash_xml(gchar * filename)
{
	GtkWidget *dash = NULL;
	GList *children = NULL;
	GtkFixedChild *child = NULL;
	gchar * tmpbuf = NULL;
	guint i = 0;
	xmlDocPtr doc = NULL;       /* document pointer */


	xmlNodePtr root_node = NULL;/* node pointers */


	xmlNodePtr node = NULL;/* node pointers */


	xmlDtdPtr dtd = NULL;       /* DTD pointer */


	GtkTreeIter parent;
	GtkTreeIter iter;
	GtkTreeModel *model = NULL;
	gboolean state = FALSE;
	gchar * iname = NULL;
	gchar ** vector = NULL;
	GtkAllocation allocation;

	g_return_if_fail(filename);

	doc = xmlNewDoc(BAD_CAST "1.0");
	root_node = xmlNewNode(NULL,BAD_CAST "dashboard");
	xmlDocSetRootElement(doc,root_node);
	/*
	 * Creates a DTD declaration. Isn't mandatory. 
	 */


	dtd = xmlCreateIntSubset(doc, BAD_CAST "dashboard", NULL, BAD_CAST "mtxdashboard.dtd");

	dash = GTK_WIDGET(gtk_builder_get_object(toplevel,"dashboard"));

	gtk_widget_get_allocation(dash, &allocation);
	node = xmlNewChild(root_node,NULL,BAD_CAST "dash_geometry", NULL);
	generic_xml_gint_export(node,"width",&allocation.width);
	generic_xml_gint_export(node,"height",&allocation.height);

	children = GTK_FIXED(dash)->children;
	for(i=0;i<g_list_length(GTK_FIXED(dash)->children);i++)
	{
		child = g_list_nth_data(GTK_FIXED(dash)->children,i);
		node = xmlNewChild(root_node,NULL,BAD_CAST "gauge", NULL);
		gtk_widget_get_allocation(child->widget, &allocation);

		generic_xml_gint_export(node,"width",&allocation.width);
		generic_xml_gint_export(node,"height",&allocation.height);
		generic_xml_gint_export(node,"x_offset",&child->x);
		generic_xml_gint_export(node,"y_offset",&child->y);
		tmpbuf = g_strrstr(mtx_gauge_face_get_xml_filename(MTX_GAUGE_FACE(child->widget)),"Gauges");
		vector = g_strsplit(tmpbuf,PSEP,2);
		
		generic_xml_gchar_export(node,"gauge_xml_name",&vector[1]);
		g_strfreev(vector);
		state = gtk_combo_box_get_active_iter(GTK_COMBO_BOX(OBJ_GET((child->widget),"combo")),&iter);
		model = gtk_combo_box_get_model(GTK_COMBO_BOX(OBJ_GET((child->widget),"combo")));
		gtk_tree_model_get(model,&iter,DATASOURCE_COL,&iname,-1);
		generic_xml_gchar_export(node,"datasource",&iname);
	}
	xmlSaveFormatFileEnc(filename, doc, "utf-8", 1);

	/*free the document */


	xmlFreeDoc(doc);

	/*
	 *Free the global variables that may
	 *have been allocated by the parser.
	 */


	xmlCleanupParser();

	/*
	 * this is to debug memory for regression tests
	 */


	xmlMemoryDump();

	return ;
}
Esempio n. 17
0
int main(int argc, const char **argv) 
{
	struct ptbf *ret;
	int debugging = 0;
	xmlNodePtr root_node;
	xmlDocPtr doc;
	xmlNodePtr comment;
	xmlNodePtr fonts;
	xmlDtdPtr dtd;
	int c, i, musicxml = 0;
	int version = 0;
	const char *input = NULL;
	char *output = NULL;
	poptContext pc;
	int quiet = 0;
	int format_output = 1;
	struct poptOption options[] = {
		POPT_AUTOHELP
		{"debug", 'd', POPT_ARG_NONE, &debugging, 0, "Turn on debugging output" },
		{"outputfile", 'o', POPT_ARG_STRING, &output, 0, "Write to specified file", "FILE" },
		{"musicxml", 'm', POPT_ARG_NONE, &musicxml, 'm', "Output MusicXML" },
		{"no-format", 'f', POPT_ARG_NONE, &format_output, 0, "Don't format output" },
		{"quiet", 'q', POPT_ARG_NONE, &quiet, 1, "Be quiet (no output to stderr)" },
		{"version", 'v', POPT_ARG_NONE, &version, 'v', "Show version information" },
		POPT_TABLEEND
	};

	pc = poptGetContext(argv[0], argc, argv, options, 0);
	poptSetOtherOptionHelp(pc, "file.ptb");
	while((c = poptGetNextOpt(pc)) >= 0) {
		switch(c) {
		case 'v':
			printf("ptb2xml Version "PACKAGE_VERSION"\n");
			printf("(C) 2004-2006 Jelmer Vernooij <*****@*****.**>\n");
			exit(0);
			break;
		}
	}
			
	ptb_set_debug(debugging);
	
	if(!poptPeekArg(pc)) {
		poptPrintUsage(pc, stderr, 0);
		return -1;
	}
	
	input = poptGetArg(pc);
	if (!quiet) fprintf(stderr, "Parsing %s...\n", input);
	ret = ptb_read_file(input);
	
	if(!ret) {
		perror("Read error: ");
		return -1;
	} 

	if(!output) {
		int baselength = strlen(input);
		if (!strcmp(input + strlen(input) - 4, ".ptb")) {
			baselength -= 4;
		}
		output = malloc(baselength + 6);
		strncpy(output, input, baselength);
		strcpy(output + baselength, ".xml");
	}

	if (!quiet) fprintf(stderr, "Building DOM tree...\n");

	doc = xmlNewDoc(BAD_CAST "1.0");
	root_node = xmlNewNode(NULL, BAD_CAST "powertab");
	dtd = xmlCreateIntSubset(doc, "powertab", NULL, DTD_URL);
	xmlDocSetRootElement(doc, root_node);

	comment = xmlNewComment("\nGenerated by ptb2xml, part of ptabtools. \n"
							"(C) 2004-2006 by Jelmer Vernooij <*****@*****.**>\n"
							"See http://jelmer.vernstok.nl/oss/ptabtools/ for details\n");
	xmlAddChild(root_node, comment);

	xmlAddChild(root_node, xml_write_header(&ret->hdr));

	for(i = 0; i < 2; i++) {
		xmlAddChild(root_node, xml_write_instrument(ret, i));
	}

	fonts = xmlNewNode( NULL, "fonts"); xmlAddChild(root_node, fonts);

	xmlAddChild(fonts, xml_write_font("default_font", &ret->default_font));
	xmlAddChild(fonts, xml_write_font("chord_name_font", &ret->chord_name_font));
	xmlAddChild(fonts, xml_write_font("tablature_font", &ret->tablature_font));

	if (musicxml)
	{
		if (!quiet) fprintf(stderr, "Converting to MusicXML...\n");
#ifdef HAVE_XSLT
		xsltStylesheetPtr stylesheet = xsltParseStylesheetFile(MUSICXMLSTYLESHEET);
		doc = xsltApplyStylesheet(stylesheet, doc, NULL);
		xsltFreeStylesheet(stylesheet);
#else
		fprintf(stderr, "Conversion to MusicXML not possible in this version: libxslt not compiled in\n");
		return -1;
#endif
	}

	if (!quiet) fprintf(stderr, "Writing output to %s...\n", output);

	if (xmlSaveFormatFile(output, doc, format_output) < 0) {
		return -1;
	}

	xmlFreeDoc(doc);

	xmlCleanupParser();

	return 0;
}
Esempio n. 18
0
void Document::SetInternalSubset(const string &name, const string &externalID, const string &systemID)
{
    xmlDtd * dtd = xmlCreateIntSubset(xml(), name.utf8(), externalID.utf8(), systemID.utf8());
    if ( dtd != nullptr && dtd->_private == nullptr )
        (void) Wrapped<DTD, _xmlDtd>(dtd);
}