Beispiel #1
0
void xml_start(struct writer * w , const char * tag, const char * descr ) {
	struct xml_writer_private * p = w->priv;

	if (xmlTextWriterStartElement(p->xw, BAD_CAST tag) < 0)
		log_warnx("lldpctl", "cannot start '%s' element", tag);

	if ( descr && (strlen(descr) > 0) ) {
		if (xmlTextWriterWriteFormatAttribute(p->xw, BAD_CAST "label", "%s", descr) < 0)
			log_warnx("lldpctl", "cannot add attribute 'label' to element %s", tag);
	}
}
Beispiel #2
0
AEResult AEXMLWriter::WriteDouble(const std::wstring& propName, double value)
{
	if (!m_IsReady)
	{
		return AEResult::NotReady;
	}

	std::string propNameStr = AE_Base::WideStr2String(propName);

	int rsc = xmlTextWriterWriteFormatAttribute(m_XMLWriter, BAD_CAST propNameStr.c_str(), "%.6f", value);
	if (rsc < 0)
	{
		AETODO("Better return code");
		return AEResult::Fail;
	}

	return AEResult::Ok;
}
Beispiel #3
0
AEResult AEXMLWriter::WriteVect4i(const std::wstring& propName, const glm::ivec4& value)
{
	if (!m_IsReady)
	{
		return AEResult::NotReady;
	}

	std::string propNameStr = AE_Base::WideStr2String(propName);

	int rsc = xmlTextWriterWriteFormatAttribute(m_XMLWriter, BAD_CAST propNameStr.c_str(), "%d %d %d %d", value.x, value.y, value.z, value.w);
	if (rsc < 0)
	{
		AETODO("Better return code");
		return AEResult::Fail;
	}

	return AEResult::Ok;
}
Beispiel #4
0
/**
Writes the attribute, their values and the status.

@internalComponent
@released

@param aOneSetExeAtt - Reference to the attributes, their value and status
*/
void XmlWriter::WriteExeAttribute(ExeAttribute& aOneSetExeAtt)
{
	xmlTextWriterStartElement(iXmlTextWriter, BAD_CAST aOneSetExeAtt.iAttName.c_str());
 	if (!(strcmp(KDepName.c_str(),aOneSetExeAtt.iAttName.c_str())) 
		|| !(strcmp(KXMLDbgFlag.c_str(),aOneSetExeAtt.iAttName.c_str())))
	{
		xmlTextWriterWriteAttribute(iXmlTextWriter, BAD_CAST KDepAtt1.c_str(),
								BAD_CAST aOneSetExeAtt.iAttValue.c_str());
	}
	else
	{
		xmlTextWriterWriteFormatAttribute(iXmlTextWriter, BAD_CAST KAtt2.c_str(),
			"0x%X",(Common::StringToInt(aOneSetExeAtt.iAttValue)));
	}
	
	xmlTextWriterWriteAttribute(iXmlTextWriter, BAD_CAST KAtt1.c_str(),
								BAD_CAST aOneSetExeAtt.iAttStatus.c_str());
	xmlTextWriterEndElement(iXmlTextWriter);
}
Beispiel #5
0
AEResult AEXMLWriter::WriteVect2b(const std::wstring& propName, const glm::bvec2& value)
{
	if (!m_IsReady)
	{
		return AEResult::NotReady;
	}

	std::string propNameStr = AE_Base::WideStr2String(propName);
	std::string valueStrX = (value.x ? "true" : "false");
	std::string valueStrY = (value.y ? "true" : "false");

	int rsc = xmlTextWriterWriteFormatAttribute(m_XMLWriter, BAD_CAST propNameStr.c_str(), "%s %s", valueStrX, valueStrY);
	if (rsc < 0)
	{
		AETODO("Better return code");
		return AEResult::Fail;
	}

	return AEResult::Ok;
}
Beispiel #6
0
AEResult AEXMLWriter::WriteMat2f(const std::wstring& propName, const glm::mat2& value)
{
	if (!m_IsReady)
	{
		return AEResult::NotReady;
	}

	std::string propNameStr = AE_Base::WideStr2String(propName);

	int rsc = xmlTextWriterWriteFormatAttribute(m_XMLWriter, BAD_CAST propNameStr.c_str(),
		"%.4f %.4f "
		"%.4f %.4f"
		, value[0].x, value[0].y
		, value[1].x, value[1].y);

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

	return AEResult::Ok;
}
Beispiel #7
0
bool XMLBBoxWriter::putNextFrameResult(vector<Result2D>& result)
{
	rc = xmlTextWriterStartElement(writer, BAD_CAST "frame");
	rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "number",
		"%d",frameCount);
	rc=xmlTextWriterStartElement(writer,BAD_CAST"objectlist");
	vector<Result2D>::iterator it;
	for (it=result.begin();it<result.end();it++)
	{
		rc = xmlTextWriterStartElement(writer, BAD_CAST "object");
		rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "id",
			"%d",(*it).id);
		rc=xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "confidence",
			"%lf",(*it).response);
		rc = xmlTextWriterStartElement(writer, BAD_CAST "box");
		rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "h",
			"%f",(*it).h);
		rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "w",
			"%f",(*it).w);
		rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "xc",
			"%f",(*it).xc);
		rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "yc",
			"%f",(*it).yc);
		//end box
		rc = xmlTextWriterEndElement(writer);
		//end object
		rc = xmlTextWriterEndElement(writer);
	}
	//end objectlist
	rc = xmlTextWriterEndElement(writer);
	//end frame
	rc = xmlTextWriterEndElement(writer);

	frameCount++;
	return true;
}
Beispiel #8
0
/* ========================================================================= */
static int writeState(xmlTextWriterPtr writer, ghmm_xmlfile* f, int moNo, int sNo) {
#define CUR_PROC "writeState"

  int rc;
  double w_pi;
  char *w_desc=NULL;

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

  /* write id attribute */
  if (0 > xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "id", "%d", sNo))
    GHMM_LOG(LERROR, "failed to write statte id attribute");

  /* read state attribute from different model types */
  switch (f->modelType & PTR_TYPE_MASK) {
  case GHMM_kDiscreteHMM:
    w_pi = f->model.d[moNo]->s[sNo].pi;
    w_desc = f->model.d[moNo]->s[sNo].desc;
    break;
  case (GHMM_kDiscreteHMM+GHMM_kTransitionClasses):
    w_pi = f->model.ds[moNo]->s[sNo].pi;
    w_desc = f->model.ds[moNo]->s[sNo].desc;
    break;
  case (GHMM_kDiscreteHMM+GHMM_kPairHMM):
  case (GHMM_kDiscreteHMM+GHMM_kPairHMM+GHMM_kTransitionClasses):
    /*
    w_pi = f->model.d[moNo]->s[sNo].pi;
    w_desc = f->model.d[moNo]->s[sNo];
    */
    break;
  case GHMM_kContinuousHMM:
  case (GHMM_kContinuousHMM+GHMM_kTransitionClasses):
  case (GHMM_kContinuousHMM+GHMM_kMultivariate):
  case (GHMM_kContinuousHMM+GHMM_kMultivariate+GHMM_kTransitionClasses):
    w_pi = f->model.c[moNo]->s[sNo].pi;
    w_desc = f->model.c[moNo]->s[sNo].desc;
    break;
  default:
    GHMM_LOG(LCRITIC, "invalid modelType");}

  /* write initial probability as attribute */
  WRITE_DOUBLE_ATTRIBUTE(writer, "initial", w_pi);

  /* write state description */
  if (w_desc) {
    if (xmlTextWriterWriteAttribute(writer, BAD_CAST "desc", BAD_CAST replaceXMLEntity(w_desc)))
      GHMM_LOG(LERROR, "writing state description failed");
  }

  /* write state contents for different model types */
  switch (f->modelType & PTR_TYPE_MASK) {
  case GHMM_kDiscreteHMM:
    rc = writeDiscreteStateContents(writer, f, moNo, sNo);
    break;
  case (GHMM_kDiscreteHMM+GHMM_kTransitionClasses):
    rc = writeDiscreteSwitchingStateContents(writer, f, moNo, sNo);
    break;
  case (GHMM_kDiscreteHMM+GHMM_kPairHMM):
  case (GHMM_kDiscreteHMM+GHMM_kPairHMM+GHMM_kTransitionClasses):
    /*
    rc = writeDiscretePairStateContents(writer, f, moNo, sNo);
    */
    break;
  case GHMM_kContinuousHMM:
  case (GHMM_kContinuousHMM+GHMM_kTransitionClasses):
  case (GHMM_kContinuousHMM+GHMM_kMultivariate):
  case (GHMM_kContinuousHMM+GHMM_kMultivariate+GHMM_kTransitionClasses):
    rc = writeContinuousStateContents(writer, f, moNo, sNo);
    break;
  default:
    GHMM_LOG(LCRITIC, "invalid modelType");
    goto STOP;
  }

  if (rc) {
      GHMM_LOG_PRINTF(LERROR, LOC, "writing state contents failed. model_type = %s",
                      strModeltype(f->modelType & PTR_TYPE_MASK));
    goto STOP;
  }


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

  return 0;
STOP:
  return -1;
#undef CUR_PROC
}
Beispiel #9
0
/* ========================================================================= */
static int writeContinuousStateContents(xmlTextWriterPtr writer, ghmm_xmlfile* f,
                                      int moNo, int sNo) {
#define CUR_PROC "writeContinuousStateContents"

  int i;
  ghmm_cstate *state = f->model.c[moNo]->s + sNo;
  int allFixed = state->fix;
  ghmm_c_emission *emission;

  /* writing continuous distribution */
  if (0 > xmlTextWriterStartElement(writer, BAD_CAST "mixture")) {
    GHMM_LOG(LERROR, "Error at xmlTextWriterStartElement (mixture)");
    goto STOP;
  }

  if (f->model.c[moNo]->s[sNo].fix)
    allFixed = 1;

  for(i=0; i < f->model.c[moNo]->s[sNo].M; i++){
    emission = f->model.c[moNo]->s[sNo].e+i;
    switch (emission->type) {
      case normal:
        if (0 > xmlTextWriterStartElement(writer, BAD_CAST "normal")) {
          GHMM_LOG(LERROR, "Error at xmlTextWriterStartElement (normal)");
          goto STOP;
        }
        WRITE_DOUBLE_ATTRIBUTE(writer, "mean", emission->mean.val);
        WRITE_DOUBLE_ATTRIBUTE(writer, "variance", emission->variance.val);
        break;
      case multinormal:
        if (0 > xmlTextWriterStartElement(writer, BAD_CAST "multinormal")) {
          GHMM_LOG(LERROR, "Error at xmlTextWriterStartElement (multinormal)");
          goto STOP;
        }
        if (0 > xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "dimension",
                                                  "%d", emission->dimension)) {
          GHMM_LOG(LERROR, "failed to write dimension attribute");
          goto STOP;
        }
        break;
      case normal_left:
        if (0 > xmlTextWriterStartElement(writer, BAD_CAST "normalLeftTail")) {
          GHMM_LOG(LERROR, "Error at xmlTextWriterStartElement (normalLeftTail)");
          goto STOP;
        }
        WRITE_DOUBLE_ATTRIBUTE(writer, "mean", emission->mean.val);
        WRITE_DOUBLE_ATTRIBUTE(writer, "variance", emission->variance.val);
        WRITE_DOUBLE_ATTRIBUTE(writer, "max", emission->min);
        break;
      case normal_right:
        if (0 > xmlTextWriterStartElement(writer, BAD_CAST "normalRightTail")) {
          GHMM_LOG(LERROR, "Error at xmlTextWriterStartElement (normalRightTail)");
          goto STOP;
        }
        WRITE_DOUBLE_ATTRIBUTE(writer, "mean", emission->mean.val);
        WRITE_DOUBLE_ATTRIBUTE(writer, "variance", emission->variance.val);
        WRITE_DOUBLE_ATTRIBUTE(writer, "min", emission->max);
        break;
      case uniform:
        if (0 > xmlTextWriterStartElement(writer, BAD_CAST "uniform")) {
          GHMM_LOG(LERROR, "Error at xmlTextWriterStartElement (uniform)");
          goto STOP;
        }
        WRITE_DOUBLE_ATTRIBUTE(writer, "min", emission->min);
        WRITE_DOUBLE_ATTRIBUTE(writer, "max", emission->max);
        break;
      default:
        GHMM_LOG_PRINTF(LERROR, LOC, "invalid density %d at position %d", emission->type, i);
        goto STOP;
    }

    /*optional values */
    if (allFixed || emission->fixed) {
      if (0 > xmlTextWriterWriteAttribute(writer, BAD_CAST "fixed", BAD_CAST "1")) {
        GHMM_LOG(LERROR, "failed to set fixed attribute");
        goto STOP;
      }
    }
    if (state->M > 1) {
      WRITE_DOUBLE_ATTRIBUTE(writer, "prior", state->c[i]);
    }

    /* write mean vector and covariance matrix as childs for multinormal */
    if (emission->type == multinormal) {
      if (0 > writeMultiNormal(writer, emission)) {
        GHMM_LOG(LERROR, "failed to write mean and covariance childs");
        goto STOP;
      }
    }

    if (0 > xmlTextWriterEndElement(writer)) {
      GHMM_LOG(LERROR, "Error at xmlTextWriterEndElement (all densities)");
      goto STOP;
    }
  }

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

  /* writing positions */
  if ((state->xPosition > 0) && (state->yPosition > 0)) {
    if (xmlTextWriterStartElement(writer, BAD_CAST "position") < 0) {
      GHMM_LOG(LERROR, "failed to start position element (position)");
      goto STOP;
    }
    if (0 > xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "x", "%d",
                                              state->xPosition)) {
      GHMM_LOG(LERROR, "failed to write x position");
      goto STOP;
    }
    if (0 > xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "y", "%d",
                                              state->yPosition)) {
      GHMM_LOG(LERROR, "failed to write y position");
      goto STOP;
    }
    if (xmlTextWriterEndElement(writer) < 0) {
      GHMM_LOG(LERROR, "Error at xmlTextWriterEndElement (position)");
      goto STOP;
    }
  }

  return 0;
STOP:
  return -1;
#undef CUR_PROC
}
Beispiel #10
0
/* ========================================================================= */
static int writeDiscreteSwitchingStateContents(xmlTextWriterPtr writer,
                                               ghmm_xmlfile* f, int moNo,
                                               int sNo) {
#define CUR_PROC "writeDiscreteSwitchingStateContents"

  int bgId, cLabel, rc, order, tied;
  char * tmp=NULL;

  /* writing discrete distribution */
  if (0 > xmlTextWriterStartElement(writer, BAD_CAST "discrete")) {
    GHMM_LOG(LERROR, "Error at xmlTextWriterStartElement (discrete)");
    goto STOP;
  }

  if (0 > xmlTextWriterWriteAttribute(writer, BAD_CAST "id", BAD_CAST "0")) {
    GHMM_LOG(LERROR, "failed to write alphabet id");
    goto STOP;
  }

  if (f->model.ds[moNo]->s[sNo].fix)
    if (0 > xmlTextWriterWriteAttribute(writer, BAD_CAST "fixed", BAD_CAST "1")) {
      GHMM_LOG(LERROR, "failed to write fixed attriute");
      goto STOP;
    }

  if ((f->model.ds[moNo]->model_type & GHMM_kHigherOrderEmissions)
      && f->model.ds[moNo]->order[sNo]) {
    order = f->model.ds[moNo]->order[sNo];
    if (0 > xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "order", "%d", order)) {
      GHMM_LOG(LERROR, "failed to write order attribute for discrete distribution");
      goto STOP;
    }
  } else
    order = 0;

  tmp = doubleArrayToCSV(f->model.ds[moNo]->s[sNo].b, pow(f->model.ds[moNo]->M, order+1));
  if (tmp) {
    if (0 > xmlTextWriterWriteRaw(writer, BAD_CAST tmp)) {
      GHMM_LOG(LERROR, "Error at xmlTextWriterWriteRaw while writing"
               "discrete distribution CSV");
      m_free(tmp);
      goto STOP;
    }
    m_free(tmp);
  } else {
    GHMM_LOG(LERROR, "converting array to CSV failed for discrete distribution");
    goto STOP;
  }

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

  /* writing backgroung key */
  if (f->model.ds[moNo]->model_type & GHMM_kBackgroundDistributions) {
    bgId = f->model.ds[moNo]->background_id[sNo];
    if (bgId != GHMM_kNoBackgroundDistribution) {
      if (f->model.ds[moNo]->bp->name[bgId]) {
        rc = xmlTextWriterWriteElement(writer, BAD_CAST "backgroundKey",
                                       BAD_CAST f->model.ds[moNo]->bp->name[bgId]);
        if (rc<0) {
          GHMM_LOG(LERROR, "Error at xmlTextWriterWriteElement (backgroundKey)");
          goto STOP;
        }
      } else {
        GHMM_LOG(LERROR, "background name is NULL pointer, invalid model");
        goto STOP;
      }
    }
  }

  /* writing class label */
  if (f->model.ds[moNo]->model_type & GHMM_kLabeledStates) {
    cLabel = f->model.ds[moNo]->label[sNo];
    rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "class", "%d", cLabel);
    if (rc<0) {
      GHMM_LOG(LERROR, "failed to write class label");
      goto STOP;
    }
  }

  /* duration (not implemented yet, maybe never */
#if 0
  if (f->model.ds[moNo]->model_type & GHMM_kDurations) {
    if (f->model.ds[moNo]->duration[sNo] > 0) {
      rc = xmlTextWriterWriteElement(writer, BAD_CAST "duration",
                                     BAD_CAST f->model.ds[moNo]->duration[sNo]);
      if (rc<0) {
        GHMM_LOG(LERROR, "Error at xmlTextWriterWriteElement (duration)");
        goto STOP;
      }
    }
  }
#endif

  /* writing positions */
  if ((f->model.ds[moNo]->s[sNo].xPosition > 0)
      && (f->model.ds[moNo]->s[sNo].xPosition > 0)) {
    if (xmlTextWriterStartElement(writer, BAD_CAST "position") < 0) {
      GHMM_LOG(LERROR, "failed to start position element (position)"); goto STOP;}
    if (0 > xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "x", "%d",
                                          f->model.ds[moNo]->s[sNo].xPosition)) {
      GHMM_LOG(LERROR, "failed to write x position"); goto STOP;}
    if (0 > xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "y", "%d",
                                          f->model.ds[moNo]->s[sNo].yPosition)) {
      GHMM_LOG(LERROR, "failed to write y position"); goto STOP;}
    if (xmlTextWriterEndElement(writer) < 0) {
      GHMM_LOG(LERROR, "Error at xmlTextWriterEndElement (position)"); goto STOP;}
  }


  /* writing tied states */
  if (f->model.ds[moNo]->model_type & GHMM_kTiedEmissions) {
    tied = f->model.ds[moNo]->tied_to[sNo];
    if (tied != GHMM_kUntied) {
      rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "tiedTo", "%d", tied);
      if (rc<0) {
        GHMM_LOG(LERROR, "failed to write tiedTo element");
        goto STOP;
      }
    }
  }

  return 0;
STOP:
  return -1;
#undef CUR_PROC
}
Beispiel #11
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
}
void CSaveSceneView::SceneNodeExplore(Ogre::SceneNode *SceneNode)
{
	Ogre::Entity *Entity = NULL;
	Ogre::Camera *Camera = NULL;
	Ogre::Light *Light = NULL;
	Ogre::ParticleSystem *ParticleSystem = NULL;
	Ogre::ManualObject *ManualObject = NULL;
	Ogre::BillboardSet *BillboardSet = NULL;

	xmlTextWriterStartElement(m_XmlWriter, BAD_CAST "SceneNode");
	
	Ogre::String SceneNodeName = SceneNode->getName();

	xmlTextWriterWriteAttribute(m_XmlWriter, 
										BAD_CAST "SceneNodeName",
										BAD_CAST SceneNodeName.c_str());

	Ogre::SceneNode::ObjectIterator obji = SceneNode->getAttachedObjectIterator();

	while (obji.hasMoreElements())
	{
		Ogre::MovableObject* mobj = obji.getNext();
	
		Ogre::String Type = mobj->getMovableType();
	
		if (Type == "Entity")
		{
			Entity = (Ogre::Entity *)(mobj);
			Ogre::String EntityName = Entity->getName();
			xmlTextWriterStartElement(m_XmlWriter, BAD_CAST "Entity");
			xmlTextWriterWriteAttribute(m_XmlWriter, 
										BAD_CAST "EntityName",
										BAD_CAST EntityName.c_str());

			Ogre::MeshPtr Mesh = Entity->getMesh();
			Ogre::String MeshName = Mesh->getName();
			xmlTextWriterWriteAttribute(m_XmlWriter, 
										BAD_CAST "MeshName",
										BAD_CAST MeshName.c_str());
			xmlTextWriterEndElement(m_XmlWriter); 
		}
		
		if (Type == "Camera")
		{
			Camera = (Ogre::Camera *)(mobj);
			Ogre::String CameraName = Camera->getName();
			xmlTextWriterStartElement(m_XmlWriter, BAD_CAST "Camera");
			
			xmlTextWriterWriteAttribute(m_XmlWriter, 
										BAD_CAST "CameraName",
										BAD_CAST CameraName.c_str());
			
			Ogre::Vector3 CameraPosition = Camera->getPosition();
			
			xmlTextWriterWriteFormatAttribute(m_XmlWriter, 
										BAD_CAST "XPosition",
										"%f",CameraPosition.x);
			xmlTextWriterWriteFormatAttribute(m_XmlWriter, 
										BAD_CAST "YPosition",
										"%f",CameraPosition.y);
			xmlTextWriterWriteFormatAttribute(m_XmlWriter, 
										BAD_CAST "ZPosition",
										"%f",CameraPosition.z);

			Ogre::Vector3 CameraDirection = Camera->getDirection();

			xmlTextWriterWriteFormatAttribute(m_XmlWriter, 
										BAD_CAST "XDirection",
										"%f",CameraDirection.x);
			xmlTextWriterWriteFormatAttribute(m_XmlWriter, 
										BAD_CAST "YDirection",
										"%f",CameraDirection.y);
			xmlTextWriterWriteFormatAttribute(m_XmlWriter, 
										BAD_CAST "ZDirection",
										"%f",CameraDirection.z);

			xmlTextWriterEndElement(m_XmlWriter); 
		}

		if (Type == "Light")
		{
			Light = (Ogre::Light *)(mobj);
		}

		if (Type == "ParticleSystem")
		{
			ParticleSystem = (Ogre::ParticleSystem *)(mobj);
		}

		if (Type == "ManualObject")
		{
			ManualObject = (Ogre::ManualObject *)(mobj);
		}

		if (Type == "BillboardSet")
		{
			BillboardSet = (Ogre::BillboardSet *)(mobj);
		}

	}

	Ogre::Node::ChildNodeIterator nodei = SceneNode->getChildIterator();

	while (nodei.hasMoreElements())
	{
		Ogre::SceneNode* node = (Ogre::SceneNode*)(nodei.getNext());
			// Add this subnode and its children...
		SceneNodeExplore(node);
	}

	xmlTextWriterEndElement(m_XmlWriter); //end SceneNode
}
Beispiel #13
0
void OpenDocument::span_style(xmlTextWriterPtr writer, const ustring & marker, const ustring & name, const ustring & fontname, double fontpercentage, ustring italic, ustring bold, ustring underline, ustring smallcaps, bool superscript, unsigned int color)
{
  // Open the style.
  xmlTextWriterStartElement(writer, BAD_CAST "style:style");
  {

    // Style properties.
    xmlTextWriterWriteAttribute(writer, BAD_CAST "style:name", BAD_CAST marker.c_str());
    ustring marker_name = marker + " " + name;
    xmlTextWriterWriteAttribute(writer, BAD_CAST "style:display-name", BAD_CAST marker_name.c_str());
    xmlTextWriterWriteAttribute(writer, BAD_CAST "style:family", BAD_CAST "text");

    // Text properties.
    xmlTextWriterStartElement(writer, BAD_CAST "style:text-properties");
    {
      if (!fontname.empty()) {
        xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "style:font-name", "%s", fontname.c_str());
      }
      if (fontpercentage != 100) {
        xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:font-size", "%.1f%%", fontpercentage);
        xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:font-size-asian", "%.1f%%", fontpercentage);
        xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:font-size-complex", "%.1f%%", fontpercentage);
      }
      if ((italic == ON) || (italic == TOGGLE))
        italic = "italic";
      else
        italic = "normal";
      // Note that ON and TOGGlE both switch italic on 
      // and OFF and INHERIT switch italic off. 
      // Improvements could be made here.
      // Bold, underline, etc., work the same.
      xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:font-style", BAD_CAST italic.c_str());
      xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:font-style-asian", BAD_CAST italic.c_str());
      xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:font-style-complex", BAD_CAST italic.c_str());
      if ((bold == ON) || (bold == TOGGLE))
        bold = "bold";
      else
        bold = "normal";
      xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:font-weight", BAD_CAST bold.c_str());
      xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:font-weight-asian", BAD_CAST bold.c_str());
      xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:font-weight-complex", BAD_CAST bold.c_str());
      if ((underline == ON) || (underline == TOGGLE))
        underline = "solid";
      else
        underline = "none";
      xmlTextWriterWriteAttribute(writer, BAD_CAST "style:text-underline-style", BAD_CAST underline.c_str());
      xmlTextWriterWriteAttribute(writer, BAD_CAST "style:text-underline-width", BAD_CAST "auto");
      xmlTextWriterWriteAttribute(writer, BAD_CAST "style:text-underline-color", BAD_CAST "font-color");
      if ((smallcaps == ON) || (smallcaps == TOGGLE))
        smallcaps = "small-caps";
      else
        smallcaps = "normal";
      xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:font-variant", BAD_CAST smallcaps.c_str());
      if (superscript) {
        xmlTextWriterWriteAttribute(writer, BAD_CAST "style:text-position", BAD_CAST "super 58%");
      }
      if (color != 0) {
        xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:color", "#%s", color_decimal_to_hex(color).c_str());
      }
    }
    xmlTextWriterEndElement(writer);
  }

  // Close style.
  xmlTextWriterEndElement(writer);
}
Beispiel #14
0
/**
 * Takes a metadata linked list and generates XML data.
 * This should be called automatically.
 * 
 * @param p_metadata a pointer to the structure as input.
 * @param data a pointer to the array to output.
 * @param len a pointer to the length of the output.
 * @return zero on success.
 * @see VitaMTP_SendObjectMetadata()
 */
int metadata_to_xml(metadata_t *p_metadata, char** data, int *len){
    xmlTextWriterPtr writer;
    xmlBufferPtr buf;
    
    buf = xmlBufferCreate();
    if (buf == NULL) {
        if(IS_LOGGING(ERROR_LOG)){
            fprintf(stderr, "metadata_to_xml: Error creating the xml buffer\n");
            return 1;
        }
    }
    writer = xmlNewTextWriterMemory(buf, 0);
    if (writer == NULL) {
        if(IS_LOGGING(ERROR_LOG)){
            fprintf(stderr, "metadata_to_xml: Error creating the xml writer\n");
            return 1;
        }
    }
    if(xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL) < 0){
        if(IS_LOGGING(ERROR_LOG)){
            fprintf(stderr, "metadata_to_xml: Error at xmlTextWriterStartDocument\n");
            return 1;
        }
    }
    xmlTextWriterStartElement(writer, BAD_CAST "objectMetadata");
    
    for(metadata_t *current = p_metadata; current != NULL; current = current->next_metadata){
        char *timestamp;
        switch(current->dataType){
            case Folder:
                xmlTextWriterStartElement(writer, BAD_CAST "folder");
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "type", "%d", current->data.folder.type);
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "name", "%s", current->data.folder.name);
                break;
            case File:
                xmlTextWriterStartElement(writer, BAD_CAST "file");
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "name", "%s", current->data.file.name);
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "statusType", "%d", current->data.file.statusType);
                break;
            case SaveData:
                xmlTextWriterStartElement(writer, BAD_CAST "saveData");
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "detail", "%s", current->data.saveData.detail);
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "dirName", "%s", current->data.saveData.dirName);
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "savedataTitle", "%s", current->data.saveData.savedataTitle);
                timestamp = vita_make_time(current->data.saveData.dateTimeUpdated);
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "dateTimeUpdated", "%s", timestamp);
                free(timestamp);
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "statusType", "%d", current->data.saveData.statusType);
                break;
            case Thumbnail:
                xmlTextWriterStartElement(writer, BAD_CAST "thumbnail");
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "codecType", "%d", current->data.thumbnail.codecType);
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "width", "%d", current->data.thumbnail.width);
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "height", "%d", current->data.thumbnail.height);
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "type", "%d", current->data.thumbnail.type);
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "orientationType", "%d", current->data.thumbnail.orientationType);
                char *aspectRatio;
                asprintf(&aspectRatio, "%.6f", current->data.thumbnail.aspectRatio);
                char *period = strchr(aspectRatio, '.');
                *period = ','; // All this to make period a comma, maybe there is an easier way?
                xmlTextWriterWriteAttribute(writer, BAD_CAST "aspectRatio", BAD_CAST aspectRatio);
                free(aspectRatio);
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fromType", "%d", current->data.thumbnail.fromType);
                break;
            default:
                continue;
        }
        xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "index", "%d", current->index);
        xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "ohfiParent", "%d", current->ohfiParent);
        xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "ohfi", "%d", current->ohfi);
        xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "title", "%s", current->title);
        xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "size", "%lu", current->size);
        timestamp = vita_make_time(current->dateTimeCreated);
        xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "dateTimeCreated", "%s", timestamp);
        free(timestamp);
        xmlTextWriterEndElement(writer);
    }
    
    xmlTextWriterEndElement(writer);
    if (xmlTextWriterEndDocument(writer) < 0) {
        if(IS_LOGGING(ERROR_LOG)){
            fprintf(stderr, "metadata_to_xml: Error at xmlTextWriterEndDocument\n");
            return 1;
        }
    }
    xmlFreeTextWriter(writer);
    *data = add_size_header((char*)buf->content, (uint32_t)buf->use + 1);
    *len = buf->use + sizeof(uint32_t) + 1;
    xmlBufferFree(buf);
    return 0;
}
Beispiel #15
0
void xml_attr(struct writer *w, const char *tag, const char *descr, const char *value ) {
	struct xml_writer_private *p = w->priv;

	if (xmlTextWriterWriteFormatAttribute(p->xw, BAD_CAST tag, "%s", value?value:"") < 0)
		log_warnx("lldpctl", "cannot add attribute %s with value %s", tag, value?value:"(none)");
}
Beispiel #16
0
void xml_attr(struct writer * w, const char * tag, const char * descr, const char * value ) {
	struct xml_writer_private * p = w->priv;

	if (xmlTextWriterWriteFormatAttribute(p->xw, BAD_CAST tag, "%s", value) < 0)
		LLOG_WARNX("cannot add attribute %s with value %s", tag, value);
}
Beispiel #17
0
/**
 *  Write to xml
 */
void
Node::writeByXmlWriter( xmlTextWriterPtr writer)
{
	xmlTextWriterWriteFormatAttribute( writer, BAD_CAST "id", "%d", userId());
}
Beispiel #18
0
void writeCurrentPatchToFile(const char *file) {
    int rc, chord_index, note_index;
    xmlTextWriterPtr writer;
    xmlChar *tmp;
    xmlDocPtr doc;

    /* Create a new XmlWriter for DOM, with no compression. */
    writer = xmlNewTextWriterDoc(&doc, 0);
    if (writer == NULL) {
        printf("writeCurrentPatchToFile: Error creating the xml writer\n");
        return;
    }

    /* Start the document with the xml default for the version,
     * encoding UTF-8 and the default for the standalone
     * declaration. */
    rc = xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL);
    if (rc < 0) {
        printf("writeCurrentPatchToFile: Error at xmlTextWriterStartDocument\n");
        return;
    }

    /* Start an element named "patch". Since thist is the first
     * element, this will be the root element of the document. */
    rc = xmlTextWriterStartElement(writer, BAD_CAST "patch");
    if (rc < 0) {
        printf("writeCurrentPatchToFile: Error at xmlTextWriterStartElement\n");
        return;
    }

		/* Add an attribute with name "velocity" and value chord[i].note.velocity to note. */
		rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "midi_channel", "%d", midi_channel);
		if (rc < 0) {
			printf("writeCurrentPatchToFile: Error at xmlTextWriterWriteAttribute\n");
			return;
		}

    /* Start an element named "chords". */
    rc = xmlTextWriterStartElement(writer, BAD_CAST "chords");
    if (rc < 0) {
        printf("writeCurrentPatchToFile: Error at xmlTextWriterStartElement\n");
        return;
    }

	
	for (chord_index = 0; chord_index < ALL_COLOR_COMBINATIONS; chord_index++) {
		if (chord[chord_index].size > 0) {
			/* Start an element named "chord" as child of patch. */
			rc = xmlTextWriterStartElement(writer, BAD_CAST "chord");
			if (rc < 0) {
				printf("writeCurrentPatchToFile: Error at xmlTextWriterStartElement\n");
				return;
			}

			if (chord_index & GREEN) {

				rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "green", BAD_CAST "true");
				if (rc < 0) {
					printf("writeCurrentPatchToFile: Error at xmlTextWriterWriteAttribute\n");
					return;
				}
			}
			if (chord_index & RED) {
				rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "red", BAD_CAST "true");
				if (rc < 0) {
					printf("writeCurrentPatchToFile: Error at xmlTextWriterWriteAttribute\n");
					return;
				}
			}
			if (chord_index & YELLOW) {
				rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "yellow", BAD_CAST "true");
				if (rc < 0) {
					printf("writeCurrentPatchToFile: Error at xmlTextWriterWriteAttribute\n");
					return;
				}
			}
			if (chord_index & BLUE) {
				rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "blue", BAD_CAST "true");
				if (rc < 0) {
					printf("writeCurrentPatchToFile: Error at xmlTextWriterWriteAttribute\n");
					return;
				}
			}
			if (chord_index & ORANGE) {
				rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "orange", BAD_CAST "true");
				if (rc < 0) {
					printf("writeCurrentPatchToFile: Error at xmlTextWriterWriteAttribute\n");
					return;
				}
			}

			rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "number_of_notes", "%d", chord[chord_index].size);
			if (rc < 0) {
				printf("writeCurrentPatchToFile: Error at xmlTextWriterWriteAttribute\n");
				return;
			}

			for (note_index = 0; note_index < chord[chord_index].size; note_index++) {
				/* Start an element named "note" as child of chord. */
				rc = xmlTextWriterStartElement(writer, BAD_CAST "note");
				if (rc < 0) {
					printf("writeCurrentPatchToFile: Error at xmlTextWriterStartElement\n");
					return;
				}

				/* Add an attribute with name "note_number" and value chord[i].note.note_number to note. */
				rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "note_number", "%d", chord[chord_index].note[note_index].note_number);
				if (rc < 0) {
					printf("writeCurrentPatchToFile: Error at xmlTextWriterWriteAttribute\n");
					return;
				}

				/* Add an attribute with name "velocity" and value chord[i].note.velocity to note. */
				rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "velocity", "%d", chord[chord_index].note[note_index].velocity);
				if (rc < 0) {
					printf("writeCurrentPatchToFile: Error at xmlTextWriterWriteAttribute\n");
					return;
				}
				if (chord[chord_index].note[note_index].delay != 0) {
					/* Add an attribute with name "delay" and value chord[i].note.delay to note. */
					rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "delay", "%d", chord[chord_index].note[note_index].delay);
					if (rc < 0) {
						printf("writeCurrentPatchToFile: Error at xmlTextWriterWriteAttribute\n");
						return;
					}
				}

				/* Close the element named note. */
				rc = xmlTextWriterEndElement(writer);
				if (rc < 0) {
					printf("writeCurrentPatchToFile: Error at xmlTextWriterEndElement\n");
					return;
				}
			}
			/* Close the element named chord. */
			rc = xmlTextWriterEndElement(writer);
			if (rc < 0) {
				printf("writeCurrentPatchToFile: Error at xmlTextWriterEndElement\n");
				return;
			}

		}
	}

    /* Here we could close the elements ORDER and EXAMPLE using the
     * function xmlTextWriterEndElement, but since we do not want to
     * write any other elements, we simply call xmlTextWriterEndDocument,
     * which will do all the work. */
    rc = xmlTextWriterEndDocument(writer);
    if (rc < 0) {
        printf("writeCurrentPatchToFile: Error at xmlTextWriterEndDocument\n");
        return;
    }

    xmlFreeTextWriter(writer);

    xmlSaveFileEnc(file, doc, MY_ENCODING);

    xmlFreeDoc(doc);
}
Beispiel #19
0
void OpenDocument::generate_styles_xml(bool right_to_left)
// This generates the file "styles.xml" in the OpenDocument.
{
  // Start the new xml document.
  xmlBufferPtr buffer = xmlBufferCreate();
  xmlTextWriterPtr writer = xmlNewTextWriterMemory(buffer, 0);
  xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL);
  xmlTextWriterSetIndent(writer, 1);
  xmlTextWriterStartElement(writer, BAD_CAST "office:document-styles");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:office", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:office:1.0");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:style", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:style:1.0");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:text", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:text:1.0");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:table", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:table:1.0");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:draw", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:fo", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:xlink", BAD_CAST "http://www.w3.org/1999/xlink");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:dc", BAD_CAST "http://purl.org/dc/elements/1.1/");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:meta", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:meta:1.0");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:number", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:svg", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:chart", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:chart:1.0");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:dr3d", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:math", BAD_CAST "http://www.w3.org/1998/Math/MathML");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:form", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:form:1.0");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:script", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:script:1.0");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:ooo", BAD_CAST "http://openoffice.org/2004/office");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:ooow", BAD_CAST "http://openoffice.org/2004/writer");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:oooc", BAD_CAST "http://openoffice.org/2004/calc");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:dom", BAD_CAST "http://www.w3.org/2001/xml-events");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "office:version", BAD_CAST "1.0");

  // Font face declarations.
  xmlTextWriterStartElement(writer, BAD_CAST "office:font-face-decls");
  xmlTextWriterEndElement(writer);

  // Styles.
  xmlTextWriterStartElement(writer, BAD_CAST "office:styles");
  generate_styles(writer);
  xmlTextWriterEndElement(writer);

  // Automatic styles.
  xmlTextWriterStartElement(writer, BAD_CAST "office:automatic-styles");
  xmlTextWriterStartElement(writer, BAD_CAST "style:page-layout");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "style:name", BAD_CAST "pm1");
  xmlTextWriterStartElement(writer, BAD_CAST "style:page-layout-properties");
  extern Settings *settings;
  xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:page-width", "%.2fcm", settings->genconfig.paper_width_get());
  xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:page-height", "%.2fcm", settings->genconfig.paper_height_get());
  xmlTextWriterWriteAttribute(writer, BAD_CAST "style:print-orientation", BAD_CAST "portrait");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "style:num-format", BAD_CAST "1");
  xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:margin-top", "%.2fcm", settings->genconfig.paper_top_margin_get());
  xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:margin-bottom", "%.2fcm", settings->genconfig.paper_bottom_margin_get());
  xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:margin-left", "%.2fcm", settings->genconfig.paper_inside_margin_get());
  xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:margin-right", "%.2fcm", settings->genconfig.paper_outside_margin_get());
  if (right_to_left) {
    xmlTextWriterWriteAttribute(writer, BAD_CAST "style:writing-mode", BAD_CAST "rl-tb");
    xmlTextWriterWriteAttribute(writer, BAD_CAST "writing-mode", BAD_CAST "rl-tb");
  }
  xmlTextWriterEndElement(writer);
  xmlTextWriterEndElement(writer);
  xmlTextWriterEndElement(writer);

  // Master styles.
  xmlTextWriterStartElement(writer, BAD_CAST "office:master-styles");
  xmlTextWriterStartElement(writer, BAD_CAST "style:master-page");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "style:name", BAD_CAST "Standard");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "style:page-layout-name", BAD_CAST "pm1");
  xmlTextWriterEndElement(writer);
  xmlTextWriterEndElement(writer);

  // Close document.
  xmlTextWriterEndElement(writer);

  // Close document and write it to disk.
  xmlTextWriterEndDocument(writer);
  xmlTextWriterFlush(writer);
  ustring filename = gw_build_filename(workingdirectory, "styles.xml");
  g_file_set_contents(filename.c_str(), (const gchar *)buffer->content, -1, NULL);

  // Free memory.
  if (writer)
    xmlFreeTextWriter(writer);
  if (buffer)
    xmlBufferFree(buffer);
}
Beispiel #20
0
/* ========================================================================= */
static int writeTransition(xmlTextWriterPtr writer, ghmm_xmlfile* f, int moNo,
                           int sNo) {
#define CUR_PROC "writeTransition"


  int cos, i, j;
  int out_states, * out_id;
  double * * out_a;
  double * w_out_a;
  char * tmp;

  /* write state contents for different model types */
  switch (f->modelType & PTR_TYPE_MASK) {
  case GHMM_kDiscreteHMM:
    out_states = f->model.d[moNo]->s[sNo].out_states;
    out_id     = f->model.d[moNo]->s[sNo].out_id;
    out_a      = &(f->model.d[moNo]->s[sNo].out_a);
    cos        = 1;
    break;
  case (GHMM_kDiscreteHMM+GHMM_kTransitionClasses):
    out_states = f->model.ds[moNo]->s[sNo].out_states;
    out_id     = f->model.ds[moNo]->s[sNo].out_id;
    out_a      = f->model.ds[moNo]->s[sNo].out_a;
    cos        = f->model.ds[moNo]->cos;
    break;
  case (GHMM_kDiscreteHMM+GHMM_kPairHMM):
  case (GHMM_kDiscreteHMM+GHMM_kPairHMM+GHMM_kTransitionClasses):
    /*
    out_states = f->model.dp[moNo]->s[sNo].out_states;
    out_id     = f->model.dp[moNo]->s[sNo].out_id;
    out_a      = f->model.dp[moNo]->s[sNo].out_a;
    cos        = f->model.dp[moNo]->cos;
    */
    break;
  case GHMM_kContinuousHMM:
  case (GHMM_kContinuousHMM+GHMM_kTransitionClasses):
  case (GHMM_kContinuousHMM+GHMM_kMultivariate):
  case (GHMM_kContinuousHMM+GHMM_kMultivariate+GHMM_kTransitionClasses):
    out_states = f->model.c[moNo]->s[sNo].out_states;
    out_id     = f->model.c[moNo]->s[sNo].out_id;
    out_a      = f->model.c[moNo]->s[sNo].out_a;
    cos        = f->model.c[moNo]->cos;
    break;
  default:
    GHMM_LOG(LCRITIC, "invalid modelType");}

  ARRAY_MALLOC(w_out_a, cos);

  for (i=0; i<out_states; i++) {
    if (0 > xmlTextWriterStartElement(writer, BAD_CAST "transition")) {
      GHMM_LOG(LERROR, "Error at xmlTextWriterStartElement (transition)");
      goto STOP;
    }

    /* write source id (current state attribute */
    if (0 > xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "source", "%d", sNo))
      GHMM_LOG(LERROR, "failed to write transition source attribute");

    /* write target id as attribute */
    if (0 > xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "target", "%d", out_id[i]))
      GHMM_LOG(LERROR, "failed to write transition target attribute");

    for (j=0; j<cos; j++)
      w_out_a[j] = out_a[j][i];

    tmp = doubleArrayToCSV(w_out_a, cos);
    if (tmp) {
      if (0 > xmlTextWriterWriteElement(writer, BAD_CAST "probability", BAD_CAST tmp)) {
        GHMM_LOG(LERROR, "Error at xmlTextWriterWriteElement (transition probabilities)");
        m_free(tmp);
        goto STOP;
      }
      m_free(tmp);
    } else {
      GHMM_LOG(LERROR, "converting transition probabilities array to CSV failed");
      goto STOP;
    }

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

  return 0;
STOP:
  return -1;
#undef CUR_PROC
}
Beispiel #21
0
void
rs_metadata_cache_save(RSMetadata *metadata, const gchar *filename)
{
	if (!filename)
	  return;

	gchar *cache_filename;
	gchar *thumb_filename;
	xmlTextWriterPtr writer;
	static GMutex lock;

	g_return_if_fail(RS_IS_METADATA(metadata));

	g_mutex_lock(&lock);

	cache_filename = rs_metadata_dotdir_helper(filename, DOTDIR_METACACHE);

	writer = xmlNewTextWriterFilename(cache_filename, 0);
	if (writer)
	{
		xmlTextWriterSetIndent(writer, 1);

		xmlTextWriterStartDocument(writer, NULL, "ISO-8859-1", NULL);
		xmlTextWriterStartElement(writer, BAD_CAST "rawstudio-metadata");
		xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "version", "%d", METACACHEVERSION);
		if (metadata->make != MAKE_UNKNOWN)
			xmlTextWriterWriteFormatElement(writer, BAD_CAST "make", "%d", metadata->make);
		if (metadata->make_ascii)
			xmlTextWriterWriteFormatElement(writer, BAD_CAST "make_ascii","%s", metadata->make_ascii);
		if (metadata->model_ascii)
			xmlTextWriterWriteFormatElement(writer, BAD_CAST "model_ascii", "%s", metadata->model_ascii);
		if (metadata->time_ascii)
			xmlTextWriterWriteFormatElement(writer, BAD_CAST "time_ascii", "%s", metadata->time_ascii);
		if (metadata->timestamp > -1)
			xmlTextWriterWriteFormatElement(writer, BAD_CAST "timestamp", "%d", metadata->timestamp);
		/* Can we make orientation conditional? */
		xmlTextWriterWriteFormatElement(writer, BAD_CAST "orientation", "%u", metadata->orientation);
		if (metadata->aperture > -1.0)
			xmlTextWriterWriteFormatElement(writer, BAD_CAST "aperture", "%f", metadata->aperture);
		if (metadata->exposurebias != -999.0)
			xmlTextWriterWriteFormatElement(writer, BAD_CAST "exposurebias", "%f", metadata->exposurebias);
		if (metadata->iso > 0)
			xmlTextWriterWriteFormatElement(writer, BAD_CAST "iso", "%u", metadata->iso);
		if (metadata->shutterspeed > -1.0)
			xmlTextWriterWriteFormatElement(writer, BAD_CAST "shutterspeed", "%f", metadata->shutterspeed);
		if (metadata->cam_mul[0] > 0.0)
			xmlTextWriterWriteFormatElement(writer, BAD_CAST "cam_mul", "%f %f %f %f", metadata->cam_mul[0], metadata->cam_mul[1], metadata->cam_mul[2], metadata->cam_mul[3]);
		if (metadata->contrast > -1.0)
			xmlTextWriterWriteFormatElement(writer, BAD_CAST "contrast", "%f", metadata->contrast);
		if (metadata->saturation > -1.0)
			xmlTextWriterWriteFormatElement(writer, BAD_CAST "saturation", "%f", metadata->saturation);
		if (metadata->color_tone > -1.0)
			xmlTextWriterWriteFormatElement(writer, BAD_CAST "color_tone", "%f", metadata->color_tone);
		if (metadata->focallength > 0)
			xmlTextWriterWriteFormatElement(writer, BAD_CAST "focallength", "%d", metadata->focallength);
		if (metadata->lens_id > -1.0)
			xmlTextWriterWriteFormatElement(writer, BAD_CAST "lens_id", "%d", metadata->lens_id);
		if (metadata->lens_min_focal > -1)
			xmlTextWriterWriteFormatElement(writer, BAD_CAST "lens_min_focal", "%f", metadata->lens_min_focal);
		if (metadata->lens_max_focal > -1.0)
			xmlTextWriterWriteFormatElement(writer, BAD_CAST "lens_max_focal", "%f", metadata->lens_max_focal);
		if (metadata->lens_min_aperture > -1.0)
			xmlTextWriterWriteFormatElement(writer, BAD_CAST "lens_min_aperture", "%f", metadata->lens_min_aperture);
		if (metadata->lens_max_aperture > -1.0)
			xmlTextWriterWriteFormatElement(writer, BAD_CAST "lens_max_aperture", "%f", metadata->lens_max_aperture);
		if (metadata->fixed_lens_identifier)
			xmlTextWriterWriteFormatElement(writer, BAD_CAST "fixed_lens_identifier", "%s", metadata->fixed_lens_identifier);
		xmlTextWriterEndDocument(writer);
		xmlFreeTextWriter(writer);
	}
	g_free(cache_filename);
	g_mutex_unlock(&lock);

	if (metadata->thumbnail)
	{
		thumb_filename = rs_metadata_dotdir_helper(filename, DOTDIR_THUMB);
		gdk_pixbuf_save(metadata->thumbnail, thumb_filename, "jpeg", NULL, "quality", "90", NULL);
		g_free(thumb_filename);
	}
}
Beispiel #22
0
/* ========================================================================= */
static int writeHMM(xmlTextWriterPtr writer, ghmm_xmlfile* f, int number) {
#define CUR_PROC "writeHMM"
  int rc=0, i, N;
  int w_cos;
  double w_prior;
  char *w_name;
  char * w_type;

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

  /* write HMM attributes applicable */
  switch (f->modelType & PTR_TYPE_MASK) {
  case GHMM_kDiscreteHMM:
    w_name  = f->model.d[number]->name;
    w_type  = strModeltype(f->model.d[number]->model_type);
    w_prior = f->model.d[number]->prior;
    N       = f->model.d[number]->N;
    w_cos   = 1;
    break;
  case (GHMM_kDiscreteHMM+GHMM_kTransitionClasses):
    w_name  = f->model.ds[number]->name;
    w_type  = strModeltype(f->model.ds[number]->model_type);
    w_prior = f->model.ds[number]->prior;
    N       = f->model.ds[number]->N;
    w_cos   = 0;
    break;
  case (GHMM_kDiscreteHMM+GHMM_kPairHMM):
  case (GHMM_kDiscreteHMM+GHMM_kPairHMM+GHMM_kTransitionClasses):
    /*
    w_name  = f->model.dp[number]->name;
    w_type  = strModeltype(f->model.dp[number]->model_type);
    w_prior = f->model.dp[number]->prior;
    N       = f->model.dp[number]->N;
    w_cos   = 0;
    */
    break;
  case GHMM_kContinuousHMM:
  case (GHMM_kContinuousHMM+GHMM_kMultivariate):
  case (GHMM_kContinuousHMM+GHMM_kTransitionClasses):
  case (GHMM_kContinuousHMM+GHMM_kMultivariate+GHMM_kTransitionClasses):
    w_name  = f->model.c[number]->name;
    if (f->model.c[number]->model_type)
      w_type  = strModeltype(f->model.c[number]->model_type);
    else
      w_type  = strModeltype(f->modelType);
    w_prior = f->model.c[number]->prior;
    N       = f->model.c[number]->N;
    w_cos   = f->model.c[number]->cos;
    break;
  default:
    GHMM_LOG(LERROR, "invalid modelType");
    goto STOP;}

  if (w_name) {
    if (xmlTextWriterWriteAttribute(writer, BAD_CAST "name", w_name))
      GHMM_LOG(LERROR, "writing HMM name failed");
  }
  if (xmlTextWriterWriteAttribute(writer, BAD_CAST "type", BAD_CAST w_type))
    GHMM_LOG(LERROR, "writing HMM type failed");

  if (w_prior >= 0.0) {
    WRITE_DOUBLE_ATTRIBUTE(writer, "prior", w_prior);
  }

  if (w_cos > 1)
    if (0 > xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "transitionClasses",
                                              "%d", w_cos))
      GHMM_LOG(LERROR, "failed to write no of transitionClasses");
   

  /* write alphabet if applicable */
  switch (f->modelType & (GHMM_kDiscreteHMM + GHMM_kTransitionClasses
                          + GHMM_kPairHMM)) {
  case GHMM_kDiscreteHMM:
    rc = writeAlphabet(writer, f->model.d[number]->alphabet, kAlphabet);
    break;
  case (GHMM_kDiscreteHMM+GHMM_kTransitionClasses):
    /*rc = writeAlphabet(writer, f->model.ds[number]->alphabet, kAlphabet);*/
    break;
  case (GHMM_kDiscreteHMM+GHMM_kPairHMM):
  case (GHMM_kDiscreteHMM+GHMM_kPairHMM+GHMM_kTransitionClasses):
    /*rc = writeAlphabet(writer, f->model.dp[number]->alphabets[0], kAlphabet);
    if (rc) {
      GHMM_LOG(LERROR, "writing first alphabet of discrete pair HMM failed");
      goto STOP;
    }
    rc = writeAlphabet(writer, f->model.dp[number]->alphabets[1], kAlphabet);*/
    break;
  }

  if (rc) {
      GHMM_LOG_PRINTF(LERROR, LOC, "writing alphabet for HMM %d (type %s) failed",
                      number, strModeltype(f->modelType));
      goto STOP;
  }

  /* write label alphabet if applicable */
  if ((f->modelType & PTR_TYPE_MASK) == GHMM_kDiscreteHMM
      && f->modelType & GHMM_kLabeledStates) {
    if (writeAlphabet(writer, f->model.d[number]->label_alphabet, kLabelAlphabet))
      GHMM_LOG(LERROR, "writing of label alphabet failed");
  }

  /* write background distributions if applicable */
  if ((f->modelType & PTR_TYPE_MASK) == GHMM_kDiscreteHMM
      && f->modelType & GHMM_kBackgroundDistributions) {
    if (writeBackground(writer, f->model.d[number]->bp))
      GHMM_LOG(LERROR, "writing of background distributions failed");
  }

  /* write all states */
  for (i=0; i<N; i++)
    if (writeState(writer, f, number, i)) {
      GHMM_LOG_PRINTF(LERROR, LOC, "writing of state %d in HMM %d failed", i, number);
      goto STOP;
    }

  /* write all outgoing transitions */
  for (i=0; i<N; i++)
    if (writeTransition(writer, f, number, i)) {
      GHMM_LOG_PRINTF(LERROR, LOC, "writing transitions of state %d in HMM %d failed",
                     i, number);
      goto STOP;
    }

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

  return 0;
STOP:
  return -1;
#undef CUR_PROC
}
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;
}
Beispiel #24
0
void Stylesheet::save ()
// Saves the stylesheet to its native xml format.
{
  // If no name is given, we work with the template. It can't be saved.
  if (name.empty())
    return;

  // Start the new xml document.
  xmlBufferPtr buffer = xmlBufferCreate();
  xmlTextWriterPtr writer = xmlNewTextWriterMemory(buffer, 0);
  xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL);
  xmlTextWriterSetIndent(writer, 1);
  xmlTextWriterStartElement(writer, BAD_CAST "bibledit-configuration");

  // Get the combined information, and write it to the document.
  for (unsigned int i = 0; i < styles.size(); i++) {

    StyleV2 * style = styles[i];

    // Open a style for the marker
    xmlTextWriterStartElement(writer, BAD_CAST "style");
    xmlTextWriterWriteFormatAttribute (writer, BAD_CAST "marker", "%s", style->marker.c_str());

    // Write values.

    if (!style->name.empty()) {
      xmlTextWriterStartElement(writer, BAD_CAST "name");
      xmlTextWriterWriteFormatString(writer, "%s", style->name.c_str());
      xmlTextWriterEndElement(writer);
    }        

    if (!style->info.empty()) {
      xmlTextWriterStartElement(writer, BAD_CAST "info");
      xmlTextWriterWriteFormatString(writer, "%s", style->info.c_str());
      xmlTextWriterEndElement(writer);
    }

    xmlTextWriterStartElement(writer, BAD_CAST "type");
    xmlTextWriterWriteFormatString(writer, "%d", style->type);
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "subtype");
    xmlTextWriterWriteFormatString(writer, "%d", style->subtype);
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "fontsize");
    xmlTextWriterWriteFormatString(writer, "%s", convert_to_string (style->fontsize).c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "italic");
    xmlTextWriterWriteFormatString(writer, "%s", style->italic.c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "bold");
    xmlTextWriterWriteFormatString(writer, "%s", style->bold.c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "underline");
    xmlTextWriterWriteFormatString(writer, "%s", style->underline.c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "smallcaps");
    xmlTextWriterWriteFormatString(writer, "%s", style->smallcaps.c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "superscript");
    xmlTextWriterWriteFormatString(writer, "%s", convert_to_string (style->superscript).c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "justification");
    xmlTextWriterWriteFormatString(writer, "%s", style->justification.c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "spacebefore");
    xmlTextWriterWriteFormatString(writer, "%s", convert_to_string (style->spacebefore).c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "spaceafter");
    xmlTextWriterWriteFormatString(writer, "%s", convert_to_string (style->spaceafter).c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "leftmargin");
    xmlTextWriterWriteFormatString(writer, "%s", convert_to_string (style->leftmargin).c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "rightmargin");
    xmlTextWriterWriteFormatString(writer, "%s", convert_to_string (style->rightmargin).c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "firstlineindent");
    xmlTextWriterWriteFormatString(writer, "%s", convert_to_string (style->firstlineindent).c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "spancolumns");
    xmlTextWriterWriteFormatString(writer, "%s", convert_to_string (style->spancolumns).c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "color");
    xmlTextWriterWriteFormatString(writer, "%d", style->color);
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "print");
    xmlTextWriterWriteFormatString(writer, "%s", convert_to_string (style->print).c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "userbool1");
    xmlTextWriterWriteFormatString(writer, "%s", convert_to_string (style->userbool1).c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "userbool2");
    xmlTextWriterWriteFormatString(writer, "%s", convert_to_string (style->userbool2).c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "userbool3");
    xmlTextWriterWriteFormatString(writer, "%s", convert_to_string (style->userbool3).c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "userint1");
    xmlTextWriterWriteFormatString(writer, "%d", style->userint1);
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "userint2");
    xmlTextWriterWriteFormatString(writer, "%d", style->userint2);
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "userint3");
    xmlTextWriterWriteFormatString(writer, "%d", style->userint3);
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "userstring1");
    xmlTextWriterWriteFormatString(writer, "%s", style->userstring1.c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "userstring2");
    xmlTextWriterWriteFormatString(writer, "%s", style->userstring2.c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "userstring3");
    xmlTextWriterWriteFormatString(writer, "%s", style->userstring3.c_str());
    xmlTextWriterEndElement(writer);

    // Close the style.
    xmlTextWriterEndElement(writer);
  }

  // Close document and write it to disk.
  xmlTextWriterEndDocument(writer);
  xmlTextWriterFlush(writer);
  ustring filename = stylesheet_xml_filename (name);
  g_file_set_contents(filename.c_str(), (const gchar *)buffer->content, -1, NULL);

  // Free memory.
  if (writer)
    xmlFreeTextWriter(writer);
  if (buffer)
    xmlBufferFree(buffer);
}
Beispiel #25
0
void OpenDocument::paragraph_style(xmlTextWriterPtr writer, const ustring & marker, const ustring & name, const ustring & fontname, double fontsize, int lineheight, const ustring & italic, const ustring & bold, const ustring & underline, const ustring & smallcaps, ustring justification, double spacebefore, double spaceafter, double leftmargin, double rightmargin, double firstlineindent, bool spancolumns, bool startpage)
{
  // Style properties.
  xmlTextWriterStartElement(writer, BAD_CAST "style:style");
  {
    xmlTextWriterWriteAttribute(writer, BAD_CAST "style:name", BAD_CAST marker.c_str());
    ustring marker_name = marker + " " + name;
    xmlTextWriterWriteAttribute(writer, BAD_CAST "style:display-name", BAD_CAST marker_name.c_str());
    xmlTextWriterWriteAttribute(writer, BAD_CAST "style:family", BAD_CAST "paragraph");
    xmlTextWriterWriteAttribute(writer, BAD_CAST "style:parent-style-name", BAD_CAST "Standard");

    // Paragraph properties.  
    xmlTextWriterStartElement(writer, BAD_CAST "style:paragraph-properties");
    {
      if (lineheight != 100) {
        xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:line-height", "%d%%", lineheight);
      }
      if (!justification.empty()) {
        if (justification == LEFT) {
          justification = "start";
        } else if (justification == RIGHT) {
          justification = "end";
        }
        xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:text-align", BAD_CAST justification.c_str());
        xmlTextWriterWriteAttribute(writer, BAD_CAST "style:justify-single-word", BAD_CAST "false");
      }
      if (spacebefore != 0) {
        xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:margin-top", "%.1fmm", spacebefore);
      }
      if (spaceafter != 0) {
        xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:margin-bottom", "%.1fmm", spaceafter);
      }
      if (leftmargin != 0) {
        xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:margin-left", "%.1fmm", leftmargin);
      }
      if (rightmargin != 0) {
        xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:margin-right", "%.1fmm", rightmargin);
      }
      if (firstlineindent != 0) {
        xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:text-indent", "%.1fmm", firstlineindent);
      }
      // Starting odd pages is not supported in OpenDocument 1.0.
      if (startpage) {
        xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:break-before", BAD_CAST "page");
      }
      // Spanning of columns is not implemented because that interferes with how
      // easily the text can be edited.
    }
    xmlTextWriterEndElement(writer);

    // Text properties.
    xmlTextWriterStartElement(writer, BAD_CAST "style:text-properties");
    {
      xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:font-size", "%.1fpt", fontsize);
      xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:font-size-asian", "%.1fpt", fontsize);
      xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:font-size-complex", "%.1fpt", fontsize);
      if (!fontname.empty()) {
        xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "style:font-name", "%s", fontname.c_str());
      }
      if (italic == ON) {
        xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:font-style", BAD_CAST "italic");
        xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:font-style-asian", BAD_CAST "italic");
        xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:font-style-complex", BAD_CAST "italic");
      }
      if (bold == ON) {
        xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:font-weight", BAD_CAST "bold");
        xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:font-weight-asian", BAD_CAST "bold");
        xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:font-weight-complex", BAD_CAST "bold");
      }
      if (underline == ON) {
        xmlTextWriterWriteAttribute(writer, BAD_CAST "style:text-underline-style", BAD_CAST "solid");
        xmlTextWriterWriteAttribute(writer, BAD_CAST "style:text-underline-width", BAD_CAST "auto");
        xmlTextWriterWriteAttribute(writer, BAD_CAST "style:text-underline-color", BAD_CAST "font-color");
      }
      if (smallcaps == ON) {
        xmlTextWriterWriteAttribute(writer, BAD_CAST "fo:font-variant", BAD_CAST "small-caps");
      }
    }
    xmlTextWriterEndElement(writer);
  }

  // Close style  
  xmlTextWriterEndElement(writer);
}
Beispiel #26
0
void write_cache()
{
	const char *uri=cache_path;
	int rc;
	char str_ip[IP6_STR_SIZE];
	xmlTextWriterPtr writer;
	neighbor_list_t *tmp = neighbors;
	FILE *dat = NULL;

	printf("Writing cache...\n");

	/* Create a new XmlWriter for uri, with no compression. */
	writer = xmlNewTextWriterFilename(uri, 0);
	if (writer == NULL)
	{
		printf("testXmlwriterFilename: Error creating the xml writer\n");
		return;
	}

	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)
	{
		printf("testXmlwriterFilename: Error at xmlTextWriterStartDocument\n");
		return;
	}

	xmlTextWriterStartDTD	(writer, (xmlChar*)"neighbor_list", NULL, (xmlChar*)dtd_path);
	xmlTextWriterEndDTD (writer);	

	/* Give the stylesheet for display in the web interface */
	xmlTextWriterWriteRaw(writer, (xmlChar*)"<?xml-stylesheet type=\"text/xsl\" href=\"neighbor.xsl\" ?>\n");

	/* Start an element named "neighbor_list". Since this is the first
	 * element, this will be the root element of the document. */
	rc = xmlTextWriterStartElement(writer, BAD_CAST "neighbor_list");
	if (rc < 0)
	{
		printf("testXmlwriterFilename: Error at xmlTextWriterStartElement\n");
		return;
	}

	/*for each neighbor in the cache a new neighbor element with its 
	 *attributes is created in the file */
	while(tmp != NULL)
	{
		address_t *atmp = tmp->addresses;
		ethernet_t *etmp = tmp->old_mac;
		/* to format the time */
		time_t timep;
		char time_str[27];
		char vlan_str[10];

		/* Start an element named "neighbor" as child of neighbor_list. */
		rc = xmlTextWriterStartElement(writer, BAD_CAST "neighbor");
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterStartElement\n");
			return;
		}
		/* Attribute vlan_id */

		snprintf(vlan_str,9,"%d",(int) tmp->vlan_id);
		rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "vlan_id", "%s", vlan_str);
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
			return;
		}

		/* Attribute mac */
		rc = xmlTextWriterStartElement(writer, BAD_CAST "mac");
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
			return;
		}
#ifdef _MACRESOLUTION_
		rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "vendor", "%s", tmp->vendor);
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterWriteAttribute %d\n",rc);
		}
#endif
		rc = xmlTextWriterWriteRaw(writer, BAD_CAST ether_ntoa(&(tmp->mac)));
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
			return;
		}

		rc = xmlTextWriterEndElement(writer);
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n");
			return;
		}
		/*
		rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "mac", "%s", ether_ntoa(&(tmp->mac)));
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
			return;
		}
		*/

		/* Attribute lla */
		ipv6_ntoa(str_ip, tmp->lla);
		rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "lla", "%s", str_ip);
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
			return;
		}

		/* element time */
		rc = xmlTextWriterStartElement(writer, BAD_CAST "time");
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
			return;
		}

#if 0
		rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "time", "%d",tmp->timer);
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
			return;
		}
#endif

		/* convert to str representation in order to display it in the web interface */
		timep = tmp->timer;
		strcpy(time_str, ctime(&timep));
		rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "timestr", "%s", time_str);
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterWriteAttribute %d\n",rc);
		}

		/* the content */
		snprintf(time_str,27,"%d",(int) tmp->timer);
		rc = xmlTextWriterWriteRaw(writer, BAD_CAST time_str);
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
			return;
		}

		rc = xmlTextWriterEndElement(writer);
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n");
			return;
		}

		/* Addresses */
		/* rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "adresses", NULL, NULL); */
		rc = xmlTextWriterStartElement(writer, BAD_CAST "addresses");
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
			return;
		}

		while(atmp != NULL)
		{
			/* to store a char * version of the int + \O */
			ipv6_ntoa(str_ip, atmp->address);

			/* the address element */
			rc = xmlTextWriterStartElement(writer, BAD_CAST "address");
			if (rc < 0)
			{
				printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
				return;
			}

			/* lastseen timer */
			rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "lastseen", "%d", (int)atmp->lastseen);
			if (rc < 0)
			{
				printf("testXmlwriterFilename: Error at xmlTextWriterWriteAttribute %d\n",rc);
			}

			/* convert to str representation in order to display it in the web interface */
			timep = atmp->lastseen;
			strcpy(time_str, ctime(&timep));
			rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "lastseenstr", "%s", time_str);
			if (rc < 0)
			{
				printf("testXmlwriterFilename: Error at xmlTextWriterWriteAttribute %d\n",rc);
			}

			/* firstseen timer */
			rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "firstseen", "%d", (int)atmp->firstseen);
			if (rc < 0)
			{
				printf("testXmlwriterFilename: Error at xmlTextWriterWriteAttribute %d\n",rc);
			}

			/* convert to str representation in order to display it in the web interface */
			timep = atmp->firstseen;
			strcpy(time_str, ctime(&timep));
			rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "firstseenstr", "%s", time_str);
			if (rc < 0)
			{
				printf("testXmlwriterFilename: Error at xmlTextWriterWriteAttribute %d\n",rc);
			}

			/* the content */
			rc = xmlTextWriterWriteRaw(writer, BAD_CAST str_ip);
			if (rc < 0)
			{
				printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
				return;
			}
	
			rc = xmlTextWriterEndElement(writer);
			if (rc < 0)
			{
				printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n");
				return;
			}

			atmp = atmp->next;
		}    

		rc = xmlTextWriterEndElement(writer);
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n");
			return;
		}


		/* Old Mac */
		rc = xmlTextWriterStartElement(writer, BAD_CAST "old_mac");
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
			return;
		}

		while(etmp != NULL)
		{
			rc = xmlTextWriterStartElement(writer, BAD_CAST "mac");
			if (rc < 0)
			{
				printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
				return;
			}
			if(!MEMCMP(&(etmp->mac),&(tmp->previous_mac), sizeof(struct ether_addr)))
			{
				rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "last", "%s", "true");
				if (rc < 0)
				{
					printf("testXmlwriterFilename: Error at xmlTextWriterWriteAttribute %d\n",rc);
				}
			}
#ifdef _MACRESOLUTION_
			rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "vendor", "%s", etmp->vendor);
			if (rc < 0)
			{
				printf("testXmlwriterFilename: Error at xmlTextWriterWriteAttribute %d\n",rc);
			}
#endif
			rc = xmlTextWriterWriteRaw(writer, BAD_CAST ether_ntoa(&(etmp->mac)));
			if (rc < 0)
			{
				printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
				return;
			}

			rc = xmlTextWriterEndElement(writer);
			if (rc < 0)
			{
				printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n");
				return;
			}

			etmp = etmp->next;
		}    

		rc = xmlTextWriterEndElement(writer);
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n");
			return;
		}

		/* Close neighbor */
		rc = xmlTextWriterEndElement(writer);
		if (rc < 0)
		{
			printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n");
			return;
		}
		tmp = tmp->next;
	}

	/* Close neighbor_list */
	rc = xmlTextWriterEndElement(writer);
	if (rc < 0)
	{
		printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n");
		return;
	}

	xmlFreeTextWriter(writer);

	/* Write in discovery_history.dat the number of neighbors in the cache for statistics */
	if( (dat = fopen(discovery_history_path,"a")) != NULL)
	{
		fprintf(dat,"%d %d\n", (int)time(NULL), nb_neighbor(neighbors) );
		fclose(dat);
	}

}
Beispiel #27
0
gboolean saveNotes(char *uri)
{
	GList *it = notesList;
	struct noteItem *ni = NULL;
	int rc;
	GtkWidget *dialog = NULL;
	xmlTextWriterPtr writer;

	/* Create a new XmlWriter for uri, with no compression. */
	writer = xmlNewTextWriterFilename(uri, 0);
	if (writer == NULL)
	{
		dialog = gtk_message_dialog_new(GTK_WINDOW(win_preview),
				GTK_DIALOG_DESTROY_WITH_PARENT,
				GTK_MESSAGE_ERROR,
				GTK_BUTTONS_OK,
				"xml: Error creating the xml writer.");
		gtk_dialog_run(GTK_DIALOG(dialog));
		gtk_widget_destroy(dialog);
		xmlCleanupParser();
		return FALSE;
	}

	/* Start the document with the xml default for the version, encoding
	 * UTF-8 and the default for the standalone declaration. */
	rc = xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL);
	if (rc < 0)
	{
		dialog = gtk_message_dialog_new(GTK_WINDOW(win_preview),
				GTK_DIALOG_DESTROY_WITH_PARENT,
				GTK_MESSAGE_ERROR,
				GTK_BUTTONS_OK,
				"xml: Could not start document. %d.", rc);
		gtk_dialog_run(GTK_DIALOG(dialog));
		gtk_widget_destroy(dialog);
		xmlFreeTextWriter(writer);
		xmlCleanupParser();
		return FALSE;
	}

	/* Start root element. It's okay to use "BAD_CAST" since there
	 * are no non-ascii letters. */
	rc = xmlTextWriterStartElement(writer, BAD_CAST "notes");
	if (rc < 0)
	{
		dialog = gtk_message_dialog_new(GTK_WINDOW(win_preview),
				GTK_DIALOG_DESTROY_WITH_PARENT,
				GTK_MESSAGE_ERROR,
				GTK_BUTTONS_OK,
				"xml: Could not start element \"notes\". %d.", rc);
		gtk_dialog_run(GTK_DIALOG(dialog));
		gtk_widget_destroy(dialog);
		xmlFreeTextWriter(writer);
		xmlCleanupParser();
		return FALSE;
	}

	/* Save all notes which do exist. Leave out empty slides. */
	while (it)
	{
		ni = (struct noteItem *)(it->data);
		if (ni->text != NULL && g_strcmp0("", ni->text) != 0)
		{
			/* Start of "slide" element. */
			rc = xmlTextWriterStartElement(writer, BAD_CAST "slide");
			if (rc < 0)
			{
				dialog = gtk_message_dialog_new(GTK_WINDOW(win_preview),
						GTK_DIALOG_DESTROY_WITH_PARENT,
						GTK_MESSAGE_ERROR,
						GTK_BUTTONS_OK,
						"xml: Could not start element \"slide\". %d.",
						rc);
				gtk_dialog_run(GTK_DIALOG(dialog));
				gtk_widget_destroy(dialog);
				xmlFreeTextWriter(writer);
				xmlCleanupParser();
				return FALSE;
			}

			/* Write page number as attribute. */
			rc = xmlTextWriterWriteFormatAttribute(writer,
					BAD_CAST "number", "%d", ni->number);
			if (rc < 0)
			{
				dialog = gtk_message_dialog_new(GTK_WINDOW(win_preview),
						GTK_DIALOG_DESTROY_WITH_PARENT,
						GTK_MESSAGE_ERROR,
						GTK_BUTTONS_OK,
						"xml: Could not write attribute \"number\""
						" for slide %d. %d.", ni->number, rc);
				gtk_dialog_run(GTK_DIALOG(dialog));
				gtk_widget_destroy(dialog);
				xmlFreeTextWriter(writer);
				xmlCleanupParser();
				return FALSE;
			}

			/* Write note as element content. */
			rc = xmlTextWriterWriteFormatString(writer,
					"%s", ni->text);
			if (rc < 0)
			{
				dialog = gtk_message_dialog_new(GTK_WINDOW(win_preview),
						GTK_DIALOG_DESTROY_WITH_PARENT,
						GTK_MESSAGE_ERROR,
						GTK_BUTTONS_OK,
						"xml: Could not write string"
						" for slide %d. %d.", ni->number, rc);
				gtk_dialog_run(GTK_DIALOG(dialog));
				gtk_widget_destroy(dialog);
				xmlFreeTextWriter(writer);
				xmlCleanupParser();
				return FALSE;
			}

			/* End of "slide" element. */
			rc = xmlTextWriterEndElement(writer);
			if (rc < 0)
			{
				dialog = gtk_message_dialog_new(GTK_WINDOW(win_preview),
						GTK_DIALOG_DESTROY_WITH_PARENT,
						GTK_MESSAGE_ERROR,
						GTK_BUTTONS_OK,
						"xml: Could not end element \"slide\". %d.",
						rc);
				gtk_dialog_run(GTK_DIALOG(dialog));
				gtk_widget_destroy(dialog);
				xmlFreeTextWriter(writer);
				xmlCleanupParser();
				return FALSE;
			}
		}

		it = g_list_next(it);
	}

	/* Here we could close open elements 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)
	{
		dialog = gtk_message_dialog_new(GTK_WINDOW(win_preview),
				GTK_DIALOG_DESTROY_WITH_PARENT,
				GTK_MESSAGE_ERROR,
				GTK_BUTTONS_OK,
				"xml: Could not end document. %d.", rc);
		gtk_dialog_run(GTK_DIALOG(dialog));
		gtk_widget_destroy(dialog);
		xmlFreeTextWriter(writer);
		xmlCleanupParser();
		return FALSE;
	}

	xmlFreeTextWriter(writer);
	xmlCleanupParser();

	/* Report success. */
	return TRUE;
}