Example #1
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;
}
Example #2
0
bool c_XMLWriter::t_writedtd(const String& name,
                             const String& publicid /* = null_string */,
                             const String& systemid /* = null_string */,
                             const String& subset /* = null_string */) {
  int ret = -1;
  if (m_ptr) {
    ret = xmlTextWriterWriteDTD(m_ptr, (xmlChar*)name.data(),
                                xmls(publicid), xmls(systemid), xmls(subset));
  }
  return ret != -1;
}
Example #3
0
bool c_xmlwriter::t_writedtd(CStrRef name,
                             CStrRef publicid /* = null_string */,
                             CStrRef systemid /* = null_string */,
                             CStrRef subset /* = null_string */) {
  int ret = -1;
  if (m_ptr) {
    ret = xmlTextWriterWriteDTD(m_ptr, (xmlChar*)name.data(),
                                xmls(publicid), xmls(systemid), xmls(subset));
  }
  return ret != -1;
}
bool c_XMLWriter::t_writedtd(CStrRef name,
                             CStrRef publicid /* = null_string */,
                             CStrRef systemid /* = null_string */,
                             CStrRef subset /* = null_string */) {
  INSTANCE_METHOD_INJECTION_BUILTIN(XMLWriter, XMLWriter::writedtd);
  int ret = -1;
  if (m_ptr) {
    ret = xmlTextWriterWriteDTD(m_ptr, (xmlChar*)name.data(),
                                xmls(publicid), xmls(systemid), xmls(subset));
  }
  return ret != -1;
}
Example #5
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;
        }
    }
}
Example #6
0
/* ========================================================================= */
void ghmm_xmlfile_write(ghmm_xmlfile* f, const char *file) {
#define CUR_PROC "ghmm_xmlfile_write"
  int rc, i;
  xmlTextWriterPtr writer;
  xmlDocPtr doc;

  /*
   * this initialize the library and check potential ABI mismatches
   * between the version it was compiled for and the actual shared
   * library used.
   */
  LIBXML_TEST_VERSION

    xmlSubstituteEntitiesDefault(1);

  /* Create a new XmlWriter for DOM, with no compression. */
  writer = xmlNewTextWriterDoc(&doc, 0);
  if (writer == NULL) {
    GHMM_LOG(LERROR, "can not create the xml writer");
    goto STOP;
  }

  /* indenting writer to circumvent no space between SYSTEM and PUBLIC identifier */
  xmlTextWriterSetIndent(writer, 1);

  /* Start the document with the xml default for the version,
   * encoding ISO 8859-1 and the default for the standalone
   * declaration. */
  rc = xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL);
  if (rc < 0) {
    GHMM_LOG(LERROR, "Error at xmlTextWriterStartDocument\n");
    goto STOP;
  }

  /* Set the Document type declaration at the beginning of the document */
  rc = xmlTextWriterWriteDTD(writer, BAD_CAST "mixture",
                             BAD_CAST "-//ghmm.org//DOCUMENT ghmm V"DTD_VERSION"//EN",
                             BAD_CAST "http://ghmm.sourceforge.net/xml/"DTD_VERSION"/ghmm.dtd",
                             NULL);
  if (rc < 0) {
    GHMM_LOG(LERROR, "failed to write the DocType"); goto STOP;}

  /* start real contents */
  if (0 > xmlTextWriterStartElement(writer, BAD_CAST "mixture")) {
    GHMM_LOG(LERROR, "Error at xmlTextWriterStartElement (mixture)");
    goto STOP;;
  }

  if (xmlTextWriterWriteAttribute(writer, BAD_CAST "version", BAD_CAST DTD_VERSION) < 0) {
    GHMM_LOG(LERROR, "failed to write version 1.0"); goto STOP;}

  if (0 > xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "noComponents", "%d", f->noModels)) {
    GHMM_LOG(LERROR, "failed to write the number of components"); goto STOP;}

  /* write all models */
  for (i=0; i<f->noModels; i++)
    writeHMM(writer, f, i);

  /* end mixture */
  if (0 > xmlTextWriterEndDocument(writer)) {
    GHMM_LOG(LERROR, "Error at xmlTextWriterEndDocument (mixture)");
    goto STOP;
  }

  xmlFreeTextWriter(writer);

  xmlSaveFormatFileEnc(file, doc, MY_ENCODING, 1);

STOP:
  xmlFreeDoc(doc);

  /*
   * Cleanup function for the XML library.
   */
  xmlCleanupParser();
  /*
   * this is to debug memory for regression tests
   */
  xmlMemoryDump();
#undef CUR_PROC
}
bool ChemDrawXMLFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv)
{
    static const xmlChar C_MOLECULE[]         = "fragment";
    static const xmlChar C_CDXML[]            = "CDXML";
    static const xmlChar C_BONDLENGTH[]       = "BondLength";
    static const xmlChar C_PAGE[]             = "page";
    static const xmlChar C_ATOM[]             = "n";
    static const xmlChar C_BOND[]             = "b";
    static const xmlChar C_ID[]               = "id";

    static const xmlChar C_CHARGE[]           = "Charge";
    static const xmlChar C_COORDS[]           = "p";
    static const xmlChar C_ELEMENT[]          = "Element";
    static const xmlChar C_ORDER[]            = "Order";
    static const xmlChar C_BEGIN[]            = "B";
    static const xmlChar C_END[]              = "E";
    static const xmlChar C_DISPLAY[]          = "Display";

    _pxmlConv = XMLConversion::GetDerived(pConv,false);
    if(!_pxmlConv)
        return false;

    OBMol* pmol = dynamic_cast<OBMol*>(pOb);
    if(pmol==NULL)
        return false;
    OBMol &mol = *pmol;

    OBBond *pbond;
    vector<OBBond*>::iterator j;
    if(_pxmlConv->GetOutputIndex() == 1)
    {
        xmlTextWriterStartDocument(writer(), NULL, NULL, NULL);
        xmlTextWriterWriteDTD(writer(), BAD_CAST "CDXML", NULL, BAD_CAST "http://www.camsoft.com/xml/cdxml.dtd", NULL);
        xmlTextWriterStartElement(writer(), C_CDXML);
        xmlTextWriterWriteFormatAttribute(writer(), C_BONDLENGTH , "30");
        xmlTextWriterStartElement(writer(), C_PAGE); // put everything on one page
        // now guess the average bond size for the first molecule and scale to 30.
        _scale = 0.;
        if (mol.NumBonds())
        {
            for (pbond = mol.BeginBond(j); pbond; pbond = mol.NextBond(j))
                _scale += pbond->GetLength();
            _scale /= mol.NumBonds();
        }
        else
            _scale = 1.; // FIXME: what happens if the molecule has no bond?
        _scale = 30. / _scale;
        _offset = 0;
    }

    xmlTextWriterStartElement(writer(), C_MOLECULE);

    OBAtom *patom;
    vector<OBAtom*>::iterator i;
    int n;
    for (patom = mol.BeginAtom(i); patom; patom = mol.NextAtom(i))
    {
        xmlTextWriterStartElement(writer(), C_ATOM);

        xmlTextWriterWriteFormatAttribute(writer(), C_ID , "%d", patom->GetIdx() + _offset);
        xmlTextWriterWriteFormatAttribute(writer(), C_COORDS , "%f %f", patom->GetX() * _scale, patom->GetY() * _scale);
        n = patom->GetAtomicNum();
        if (n != 6)
        {
            xmlTextWriterWriteFormatAttribute(writer(), C_ELEMENT , "%d", n);
        }
        n = patom->GetFormalCharge();
        if (n != 0)
        {
            xmlTextWriterWriteFormatAttribute(writer(), C_CHARGE , "%d", n);
        }
        xmlTextWriterEndElement(writer());
    }

    for (pbond = mol.BeginBond(j); pbond; pbond = mol.NextBond(j))
    {
        xmlTextWriterStartElement(writer(), C_BOND);
        patom = pbond->GetBeginAtom();
        xmlTextWriterWriteFormatAttribute(writer(), C_BEGIN , "%d", patom->GetIdx() + _offset);
        patom = pbond->GetEndAtom();
        xmlTextWriterWriteFormatAttribute(writer(), C_END , "%d", patom->GetIdx() + _offset);
        n = pbond->GetBO();
        if (n != 1)
        {
            xmlTextWriterWriteFormatAttribute(writer(), C_ORDER , "%d", n);
        }
        if (pbond->IsHash())
            xmlTextWriterWriteFormatAttribute(writer(), C_DISPLAY , "WedgeBegin");
        else if (pbond->IsWedge())
            xmlTextWriterWriteFormatAttribute(writer(), C_DISPLAY , "WedgedHashEnd");
        xmlTextWriterEndElement(writer());
    }
    _offset += mol.NumAtoms ();

    xmlTextWriterEndElement(writer());//molecule

    //TODO: Writing property block

    if(_pxmlConv->IsLast())
    {
        xmlTextWriterEndDocument(writer()); // page
        xmlTextWriterEndDocument(writer()); //document
        OutputToStream();
    }
    return true;
}
Example #8
0
static RejillaBurnResult
rejilla_vcd_imager_generate_xml_file (RejillaProcess *process,
				      const gchar *path,
				      GError **error)
{
	RejillaVcdImagerPrivate *priv;
	GSList *tracks = NULL;
	xmlTextWriter *xml;
	gchar buffer [64];
	gint success;
	GSList *iter;
	gchar *name;
	gint i;

	REJILLA_JOB_LOG (process, "Creating (S)VCD layout xml file (%s)", path);

	xml = xmlNewTextWriterFilename (path, 0);
	if (!xml)
		return REJILLA_BURN_ERR;

	priv = REJILLA_VCD_IMAGER_PRIVATE (process);

	xmlTextWriterSetIndent (xml, 1);
	xmlTextWriterSetIndentString (xml, (xmlChar *) "\t");

	success = xmlTextWriterStartDocument (xml,
					      NULL,
					      "UTF8",
					      NULL);
	if (success < 0)
		goto error;

	success = xmlTextWriterWriteDTD (xml,
					(xmlChar *) "videocd",
					(xmlChar *) "-//GNU//DTD VideoCD//EN",
					(xmlChar *) "http://www.gnu.org/software/vcdimager/videocd.dtd",
					(xmlChar *) NULL);
	if (success < 0)
		goto error;

	/* let's start */
	success = xmlTextWriterStartElement (xml, (xmlChar *) "videocd");
	if (success < 0)
		goto error;

	success = xmlTextWriterWriteAttribute (xml,
					       (xmlChar *) "xmlns",
					       (xmlChar *) "http://www.gnu.org/software/vcdimager/1.0/");
	if (success < 0)
		goto error;

	if (priv->svcd)
		success = xmlTextWriterWriteAttribute (xml,
						       (xmlChar *) "class",
						       (xmlChar *) "svcd");
	else
		success = xmlTextWriterWriteAttribute (xml,
						       (xmlChar *) "class",
						       (xmlChar *) "vcd");

	if (success < 0)
		goto error;

	if (priv->svcd)
		success = xmlTextWriterWriteAttribute (xml,
						       (xmlChar *) "version",
						       (xmlChar *) "1.0");
	else
		success = xmlTextWriterWriteAttribute (xml,
						       (xmlChar *) "version",
						       (xmlChar *) "2.0");
	if (success < 0)
		goto error;

	/* info part */
	success = xmlTextWriterStartElement (xml, (xmlChar *) "info");
	if (success < 0)
		goto error;

	/* name of the volume */
	name = NULL;
	rejilla_job_get_audio_title (REJILLA_JOB (process), &name);
	success = xmlTextWriterWriteElement (xml,
					     (xmlChar *) "album-id",
					     (xmlChar *) name);
	g_free (name);
	if (success < 0)
		goto error;

	/* number of CDs */
	success = xmlTextWriterWriteElement (xml,
					     (xmlChar *) "volume-count",
					     (xmlChar *) "1");
	if (success < 0)
		goto error;

	/* CD number */
	success = xmlTextWriterWriteElement (xml,
					     (xmlChar *) "volume-number",
					     (xmlChar *) "1");
	if (success < 0)
		goto error;

	/* close info part */
	success = xmlTextWriterEndElement (xml);
	if (success < 0)
		goto error;

	/* Primary Volume descriptor */
	success = xmlTextWriterStartElement (xml, (xmlChar *) "pvd");
	if (success < 0)
		goto error;

	/* NOTE: no need to convert a possible non compliant name as this will 
	 * be done by vcdimager. */
	name = NULL;
	rejilla_job_get_audio_title (REJILLA_JOB (process), &name);
	success = xmlTextWriterWriteElement (xml,
					     (xmlChar *) "volume-id",
					     (xmlChar *) name);
	g_free (name);
	if (success < 0)
		goto error;

	/* Makes it CD-i compatible */
	success = xmlTextWriterWriteElement (xml,
					     (xmlChar *) "system-id",
					     (xmlChar *) "CD-RTOS CD-BRIDGE");
	if (success < 0)
		goto error;

	/* Close Primary Volume descriptor */
	success = xmlTextWriterEndElement (xml);
	if (success < 0)
		goto error;

	/* the tracks */
	success = xmlTextWriterStartElement (xml, (xmlChar *) "sequence-items");
	if (success < 0)
		goto error;

	/* get all tracks */
	rejilla_job_get_tracks (REJILLA_JOB (process), &tracks);
	priv->num_tracks = g_slist_length (tracks);
	for (i = 0, iter = tracks; iter; iter = iter->next, i++) {
		RejillaTrack *track;
		gchar *video;

		track = iter->data;
		success = xmlTextWriterStartElement (xml, (xmlChar *) "sequence-item");
		if (success < 0)
			goto error;

		video = rejilla_track_stream_get_source (REJILLA_TRACK_STREAM (track), FALSE);
		success = xmlTextWriterWriteAttribute (xml,
						       (xmlChar *) "src",
						       (xmlChar *) video);
		g_free (video);

		if (success < 0)
			goto error;

		sprintf (buffer, "track-%i", i);
		success = xmlTextWriterWriteAttribute (xml,
						       (xmlChar *) "id",
						       (xmlChar *) buffer);
		if (success < 0)
			goto error;

		/* close sequence-item */
		success = xmlTextWriterEndElement (xml);
		if (success < 0)
			goto error;
	}

	/* sequence-items */
	success = xmlTextWriterEndElement (xml);
	if (success < 0)
		goto error;

	/* the navigation */
	success = xmlTextWriterStartElement (xml, (xmlChar *) "pbc");
	if (success < 0)
		goto error;

	/* get all tracks */
	rejilla_job_get_tracks (REJILLA_JOB (process), &tracks);
	for (i = 0, iter = tracks; iter; iter = iter->next, i++) {
		RejillaTrack *track;

		track = iter->data;

		sprintf (buffer, "playlist-%i", i);
		success = xmlTextWriterStartElement (xml, (xmlChar *) "playlist");
		if (success < 0)
			goto error;

		success = xmlTextWriterWriteAttribute (xml,
						       (xmlChar *) "id",
						       (xmlChar *) buffer);
		if (success < 0)
			goto error;

		success = xmlTextWriterWriteElement (xml,
						     (xmlChar *) "wait",
						     (xmlChar *) "0");
		if (success < 0)
			goto error;

		success = xmlTextWriterStartElement (xml, (xmlChar *) "play-item");
		if (success < 0)
			goto error;

		sprintf (buffer, "track-%i", i);
		success = xmlTextWriterWriteAttribute (xml,
						       (xmlChar *) "ref",
						       (xmlChar *) buffer);
		if (success < 0)
			goto error;

		/* play-item */
		success = xmlTextWriterEndElement (xml);
		if (success < 0)
			goto error;

		/* playlist */
		success = xmlTextWriterEndElement (xml);
		if (success < 0)
			goto error;
	}

	/* pbc */
	success = xmlTextWriterEndElement (xml);
	if (success < 0)
		goto error;

	/* close videocd */
	success = xmlTextWriterEndElement (xml);
	if (success < 0)
		goto error;

	xmlTextWriterEndDocument (xml);
	xmlFreeTextWriter (xml);

	return REJILLA_BURN_OK;

error:

	REJILLA_JOB_LOG (process, "Error");

	/* close everything */
	xmlTextWriterEndDocument (xml);
	xmlFreeTextWriter (xml);

	/* FIXME: get the error */

	return REJILLA_BURN_ERR;
}