Ejemplo n.º 1
0
bool XmlReader::MoveToNextAttribute() {
  end_element = false;

  bool r(xmlTextReaderMoveToNextAttribute(libxml_stuff->reader) == 1);
  while (r) {
    int const node_type = xmlTextReaderNodeType(libxml_stuff->reader);
    if (node_type == XML_READER_TYPE_ATTRIBUTE)
      break;

    r = (xmlTextReaderMoveToNextAttribute(libxml_stuff->reader) == 1);
  }
  return r;
  //return (xmlTextReaderMoveToNextAttribute(libxml_stuff->reader) == 1);
}
Ejemplo n.º 2
0
TileMapParseStatus TileMapLayer_parse_data(xmlTextReaderPtr reader,
                                           TileMap *map, TileMapLayer *layer) {
  TileMapParseStatus status = TILEMAP_PARSE_OK;
  
  while (xmlTextReaderMoveToNextAttribute(reader)) {
    xmlChar *attrName = xmlTextReaderName(reader);
    xmlChar *attrVal = xmlTextReaderValue(reader);
    
    if (streq(attrName, "encoding")) {
      check(streq(attrVal, "base64"), "Incorrect layer data encoding");
    } else if (streq(attrName, "compression")) {
      check(streq(attrVal, "gzip"), "Incorrect layer data compression");
    }
  }
  
  while (xmlTextReaderRead(reader)) {
    xmlChar *childName = xmlTextReaderName(reader);
    if (xmlTextReaderNodeType(reader) == XML_ELEMENT_DECL &&
        streq(childName, "data")) {
      break;
    } else if (xmlTextReaderNodeType(reader) == XML_TEXT_NODE) {
      int tile_count = 0;
      extract_gids_from_encoded_data(xmlTextReaderValue(reader),
                                     &(layer->tile_gids), &tile_count);
      check(tile_count == map->rows * map->cols, "Inconsistent layer size");
      layer->gid_count = tile_count;
    }
  }
  
  return status;
error:
  return TILEMAP_PARSE_INVALID_FORMAT;
}
Ejemplo n.º 3
0
/*
 * Parse the configuration file's pg element about connection information
 */
static void ows_parse_config_pg(ows * o, xmlTextReaderPtr r)
{
    xmlChar *a, *v;

    assert(o);
    assert(r);

    if (xmlTextReaderMoveToFirstAttribute(r) != 1) return;
    do {
        a = xmlTextReaderName(r);

        if (       !strcmp((char *) a, "host")
                || !strcmp((char *) a, "user")
                || !strcmp((char *) a, "password")
                || !strcmp((char *) a, "dbname")
                || !strcmp((char *) a, "port")) {
            v = xmlTextReaderValue(r);
            buffer_add_str(o->pg_dsn, (char *) a);
            buffer_add_str(o->pg_dsn, "=");
            buffer_add_str(o->pg_dsn, (char *) v);
            buffer_add_str(o->pg_dsn, " ");
            xmlFree(v);
        } else if (!strcmp((char *) a, "encoding")) { 
            v = xmlTextReaderValue(r); 
            buffer_add_str(o->db_encoding, (char *) v); 
            xmlFree(v); 
        }

        xmlFree(a);
    } while (xmlTextReaderMoveToNextAttribute(r) == 1);

    if (!o->db_encoding->use)
        buffer_add_str(o->db_encoding, OWS_DEFAULT_DB_ENCODING);
}
Ejemplo n.º 4
0
gboolean
xml_reader_move_to_next_attribute (XmlReader *reader)
{
  g_return_val_if_fail (XML_IS_READER (reader), FALSE);

  return (xmlTextReaderMoveToNextAttribute (reader->xml) == 1);
}
Ejemplo n.º 5
0
int XMIResource::loadBase64(xmlTextReaderPtr reader, enum object_properties_t property, const model::BaseObject& o)
{
    // iterate on attributes
    for (int rc = xmlTextReaderMoveToFirstAttribute(reader); rc > 0; rc = xmlTextReaderMoveToNextAttribute(reader))
    {
        auto found = std::find(constXcosNames.begin(), constXcosNames.end(), xmlTextReaderConstName(reader));
        enum xcosNames current = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), found));

        switch (current)
        {
            case e_base64:
            {
                const xmlChar* base64 = xmlTextReaderConstValue(reader);
                std::vector<double> v = base64::decode<std::vector<double> >(to_string(base64));
                controller.setObjectProperty(o.id(), o.kind(), property, v);
                break;
            }
            default:
                // ignore other parameters
                // TODO: Does other metamodels might be managed there ?
                break;
        }
    }

    return 1;
}
Ejemplo n.º 6
0
int XMIResource::loadDiagram(xmlTextReaderPtr reader, const model::BaseObject& o)
{
    assert(o.kind() == DIAGRAM);

    // abstract Layer is not decoded there as it has no attribute

    // iterate on attributes
    for (int rc = xmlTextReaderMoveToFirstAttribute(reader); rc > 0; rc = xmlTextReaderMoveToNextAttribute(reader))
    {
        auto found = std::find(constXcosNames.begin(), constXcosNames.end(), xmlTextReaderConstName(reader));
        enum xcosNames current = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), found));
        switch (current)
        {
            case e_title:
                controller.setObjectProperty(o.id(), o.kind(), TITLE, to_string(xmlTextReaderConstValue(reader)));
                break;
            case e_path:
                controller.setObjectProperty(o.id(), o.kind(), PATH, to_string(xmlTextReaderConstValue(reader)));
                break;
            case e_debugLevel:
                controller.setObjectProperty(o.id(), o.kind(), DEBUG_LEVEL, to_int(xmlTextReaderConstValue(reader)));
                break;
            case e_version:
                controller.setObjectProperty(o.id(), o.kind(), VERSION_NUMBER, to_string(xmlTextReaderConstValue(reader)));
                break;
            default:
                // ignore other parameters
                // TODO: Does other metamodels might be managed there ?
                break;
        }
    }

    return 1;
}
Ejemplo n.º 7
0
void XmlParser::_readMember() {
    std::string type;
    std::string ref;
    std::string role;
    // Read attributes
    if (xmlTextReaderHasAttributes(_reader) == XmlStatus::TRUE) {
        while (xmlTextReaderMoveToNextAttribute(_reader)) {
            std::string k = (char*) xmlTextReaderConstName(_reader);
            std::string v = (char*) xmlTextReaderConstValue(_reader);
            if (k == "type") {
                type = v;
            } else if (k == "ref") {
                ref = v;
            } else if (k == "role") {
                role = v;
            }
        }
    }
    if (_prevMemberParentElementId == _parentElementId) {
        _dbBuilder.addMember(_parentElementId, ref, type, role, false);
    } else {
        _dbBuilder.addMember(_parentElementId, ref, type, role, true);
        _prevMemberParentElementId = _parentElementId;
    }
}
Ejemplo n.º 8
0
int XMIResource::loadPoint(xmlTextReaderPtr reader, const model::BaseObject& o)
{
    assert(o.kind() == LINK);

    std::vector<double> points;
    controller.getObjectProperty(o.id(), o.kind(), CONTROL_POINTS, points);

    // iterate on attributes
    for (int rc = xmlTextReaderMoveToFirstAttribute(reader); rc > 0; rc = xmlTextReaderMoveToNextAttribute(reader))
    {
        auto found = std::find(constXcosNames.begin(), constXcosNames.end(), xmlTextReaderConstName(reader));
        enum xcosNames current = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), found));
        switch (current)
        {
            case e_x:
                points.push_back(to_double(xmlTextReaderConstValue(reader)));
                break;
            case e_y:
                points.push_back(to_double(xmlTextReaderConstValue(reader)));
                break;
            default:
                // ignore other parameters
                // TODO: Does other metamodels might be managed there ?
                break;
        }
    }

    controller.setObjectProperty(o.id(), o.kind(), CONTROL_POINTS, points);
    return 1;
}
Ejemplo n.º 9
0
static int _exml_read(EXML *xml, xmlTextReaderPtr reader)
{
	int empty;
	xmlChar *name, *value;

	if (!reader)
		return -1;

	exml_clear( xml );

	while( xmlTextReaderRead( reader ) == 1 ) {
		name = xmlTextReaderName(reader);
		value = xmlTextReaderValue(reader);
		empty = xmlTextReaderIsEmptyElement(reader);

		switch( xmlTextReaderNodeType(reader) ) {
			case XML_READER_TYPE_ELEMENT:
				exml_start(xml);
				exml_tag_set(xml, (char *) name);
		
				if (xmlTextReaderHasAttributes(reader)) {
					xmlTextReaderMoveToFirstAttribute(reader);
					do {
						xmlChar *attr_name, *attr_value;

						attr_name = xmlTextReaderName(reader);
						attr_value = xmlTextReaderValue(reader);

						exml_attribute_set(xml, (char *) attr_name, (char *) attr_value);

						xmlFree(attr_name);
						xmlFree(attr_value);
					} while( xmlTextReaderMoveToNextAttribute(reader) == 1 );
				}

				if (!empty)
					break;
			case XML_READER_TYPE_END_ELEMENT:
				exml_end(xml);
				break;
			case XML_READER_TYPE_WHITESPACE:
				break;
			case XML_READER_TYPE_TEXT:
				exml_value_set(xml, (char *) value);
				break;
		}
		xmlFree(name);
		xmlFree(value);
	}

	xmlTextReaderClose(reader);
	xmlFreeTextReader(reader);

	exml_goto_top( xml );

	return TRUE;
}
Ejemplo n.º 10
0
TileMapParseStatus TileMap_parse_map(xmlTextReaderPtr reader, Engine *engine,
                                     TileMap *map) {
  TileMapParseStatus status = TILEMAP_PARSE_OK;
  
  xmlChar *name = xmlTextReaderName(reader);
  if (!(streq(name, "map") &&
        xmlTextReaderNodeType(reader) == XML_ELEMENT_NODE)) {
    return TILEMAP_PARSE_INVALID_FORMAT;
  }
  
  while (xmlTextReaderMoveToNextAttribute(reader)) {
    xmlChar *attrName = xmlTextReaderName(reader);
    xmlChar *attrVal = xmlTextReaderValue(reader);
    
    if (streq(attrName, "orientation")) {
      if (!streq(attrVal, "orthogonal")) {
        return TILEMAP_PARSE_INVALID_ORIENTATION;
      }
    } else if (streq(attrName, "width")) {
      map->cols = atoi((const char *)attrVal);
    } else if (streq(attrName, "height")) {
      map->rows = atoi((const char *)attrVal);
    } else if (streq(attrName, "tilewidth")) {
      map->tile_size.w = atoi((const char *)attrVal);
    } else if (streq(attrName, "tileheight")) {
      map->tile_size.h = atoi((const char *)attrVal);
    }
  }
  
  while (xmlTextReaderRead(reader)) {
    xmlChar *childName = xmlTextReaderName(reader);
    if (xmlTextReaderNodeType(reader) == XML_ELEMENT_DECL &&
        streq(childName, "map")) {
      break;
    } else if (streq(childName, "tileset")) {
      Tileset *tileset = NULL;
      status = TileMap_parse_tileset(reader, engine, map, &tileset);
      if (status != TILEMAP_PARSE_OK) return status;
      DArray_push(map->tilesets, tileset);
    } else if (streq(childName, "layer")) {
      TileMapLayer *layer = NULL;
      status = TileMap_parse_layer(reader, map, &layer);
      if (status != TILEMAP_PARSE_OK) return status;
      DArray_push(map->layers, layer);
    }
  }
  
  return status;
}
Ejemplo n.º 11
0
int XMIResource::loadSimulationConfig(xmlTextReaderPtr reader, const model::BaseObject& o)
{
    assert(o.kind() == DIAGRAM);

    std::vector<double> properties;
    controller.getObjectProperty(o.id(), o.kind(), PROPERTIES, properties);
    properties.resize(8);

    // iterate on attributes
    for (int rc = xmlTextReaderMoveToFirstAttribute(reader); rc > 0; rc = xmlTextReaderMoveToNextAttribute(reader))
    {
        auto found = std::find(constXcosNames.begin(), constXcosNames.end(), xmlTextReaderConstName(reader));
        enum xcosNames current = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), found));
        switch (current)
        {
            case e_finalTime:
                properties[0] = to_double(xmlTextReaderConstValue(reader));
                break;
            case e_absoluteTolerance:
                properties[1] = to_double(xmlTextReaderConstValue(reader));
                break;
            case e_relativeTolerance:
                properties[2] = to_double(xmlTextReaderConstValue(reader));
                break;
            case e_timeTolerance:
                properties[3] = to_double(xmlTextReaderConstValue(reader));
                break;
            case e_deltaT:
                properties[4] = to_double(xmlTextReaderConstValue(reader));
                break;
            case e_realtimeScale:
                properties[5] = to_double(xmlTextReaderConstValue(reader));
                break;
            case e_solver:
                properties[6] = to_double(xmlTextReaderConstValue(reader));
                break;
            case e_deltaH:
                properties[7] = to_double(xmlTextReaderConstValue(reader));
                break;
            default:
                // ignore other parameters
                // TODO: Does other metamodels might be managed there ?
                break;
        }
    }

    controller.setObjectProperty(o.id(), o.kind(), PROPERTIES, properties);
    return 1;
}
Ejemplo n.º 12
0
/**
 * processNode:
 * @reader: the xmlReader
 *
 * Dump information about the current node
 */
static void
processNode(xmlTextReaderPtr reader) {
    const xmlChar *name, *value;
    int nodetype;
 
    static char spaces[33]="                                ";

    name = xmlTextReaderConstName(reader);
    if (name == NULL)
	name = BAD_CAST "--";
 
    value = xmlTextReaderConstValue(reader);
 
    nodetype = xmlTextReaderNodeType(reader);
    if (nodetype!=14 && nodetype!=15)	// Skip all text bodies and "/" entities.
    {
#ifdef DETAILS
    printf("%s%d %d %s %d %d", 
    	    (spaces + (32-2*xmlTextReaderDepth(reader))),
	    xmlTextReaderDepth(reader),
	    nodetype,
	    name,
	    xmlTextReaderIsEmptyElement(reader),
	    xmlTextReaderHasValue(reader));
#else
    printf("%s%s", (spaces + (32-2*xmlTextReaderDepth(reader))), name);
#endif

    if (value == NULL)
	printf("\n");
    else {
        if (xmlStrlen(value) > 40)
            printf(" %.40s...\n", value);
        else
	    printf(" %s\n", value);
    }
    }

    if (nodetype==1)	// Element - possibly has attributes
    {
	while (xmlTextReaderMoveToNextAttribute(reader))
	    printf("%s    Attrib: %s=\"%s\"\n", 
		(spaces + (32-2*xmlTextReaderDepth(reader))),
		xmlTextReaderConstName(reader), 
		xmlTextReaderConstValue(reader));
    }

}
Ejemplo n.º 13
0
char *
_gweather_parser_get_msgctxt_value (GWeatherParser *parser)
{
    const char *value;
    const char *name;

    while(xmlTextReaderMoveToNextAttribute(parser->xml)) {
	name = (const char *)xmlTextReaderConstName(parser->xml);
	if (!strcmp (name, "msgctxt")) {
	    value = (const char *)xmlTextReaderConstValue(parser->xml);
	    return g_strdup (value);
	}
    }

    return NULL;
}
Ejemplo n.º 14
0
void XmlParser::_readOsm() {
    std::string versionStr;
    std::string generatorStr;
    // Read attributes
    if (xmlTextReaderHasAttributes(_reader) == XmlStatus::TRUE) {
        while (xmlTextReaderMoveToNextAttribute(_reader)) {
            std::string k = (char*) xmlTextReaderConstName(_reader);
            std::string v = (char*) xmlTextReaderConstValue(_reader);
            if (k == "version") {
                versionStr = v;
            } else if (k == "generator") {
                generatorStr = v;
            }
        }
    }
    _dbBuilder.addOSM(versionStr, generatorStr);
}
Ejemplo n.º 15
0
void XmlParser::_readNode() {
    std::string idStr;
    std::string latStr;
    std::string lonStr;
    std::string versionStr;
    std::string timestampStr;
    std::string changesetStr;
    std::string uidStr;
    std::string userStr;
    std::string actionStr;
    std::string visibleStr;
    // Read attributes
    if (xmlTextReaderHasAttributes(_reader) == XmlStatus::TRUE) {
        while (xmlTextReaderMoveToNextAttribute(_reader)) {
            std::string k = (char*) xmlTextReaderConstName(_reader);
            std::string v = (char*) xmlTextReaderConstValue(_reader);
            if (k == "id") {
                idStr = v;
            } else if (k == "lat") {
                latStr = v;
            } else if (k == "lon") {
                lonStr = v;
            } else if (k == "version") {
                versionStr = v;
            } else if (k == "timestamp") {
                timestampStr = v;
            } else if (k == "changeset") {
                changesetStr = v;
            } else if (k == "uid") {
                uidStr = v;
            } else if (k == "user") {
                userStr = v;
            } else if (k == "action") {
                actionStr = v;
            } else if (k == "visible") {
                visibleStr = v;
            }
        }
    }
    _parentElementType = ElementType::NODE;
    _parentElementId = idStr;
    _dbBuilder.addNode(idStr, latStr, lonStr, versionStr, timestampStr,
                   changesetStr, uidStr, userStr, actionStr, visibleStr);
}
Ejemplo n.º 16
0
//typedef void (*oval_behavior_consumer)(struct oval_behavior_node *, void*);
int oval_behavior_parse_tag(xmlTextReaderPtr reader,
			    struct oval_parser_context *context,
			    oval_family_t family, oval_behavior_consumer consumer, void *user)
{
	__attribute__nonnull__(context);

	while (xmlTextReaderMoveToNextAttribute(reader) == 1) {

		const char *name = (const char *)xmlTextReaderConstName(reader);
		const char *value = (const char *)xmlTextReaderConstValue(reader);

		if (name && value) {
			oval_behavior_t *behavior = oval_behavior_new(context->definition_model);
			oval_behavior_set_keyval(behavior, name, value);
			(*consumer) (behavior, user);
		}
	}
	return 0;
}
Ejemplo n.º 17
0
int XMIResource::loadAbstractBaseObject(xmlTextReaderPtr reader, const model::BaseObject& o)
{
    assert(o.kind() == BLOCK || o.kind() == ANNOTATION || o.kind() == LINK);

    // abstract Layer is not decoded there as it has no attribute

    // iterate on attributes
    for (int rc = xmlTextReaderMoveToFirstAttribute(reader); rc > 0; rc = xmlTextReaderMoveToNextAttribute(reader))
    {
        auto found = std::find(constXcosNames.begin(), constXcosNames.end(), xmlTextReaderConstName(reader));
        enum xcosNames current = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), found));
        switch (current)
        {
            case e_uid:
            {
                std::string uid = to_string(xmlTextReaderConstValue(reader));
                controller.setObjectProperty(o.id(), o.kind(), UID, uid);
                references.insert(std::make_pair(uid, o.id()));
                break;
            }
            case e_parentDiagram:
            {
                // not lookup needed ; only one diagram is serialized at a time
                controller.setObjectProperty(o.id(), o.kind(), PARENT_DIAGRAM, root);
                break;
            }
            case e_parent:
            {
                // not lookup needed thanks to the XML hierarchy
                const model::BaseObject& parent = *(processed.end() - 2);
                controller.setObjectProperty(o.id(), o.kind(), PARENT_BLOCK, parent.id());
                break;
            }
            default:
                // ignore other parameters
                // TODO: Does other metamodels might be managed there ?
                break;
        }
    }

    return 1;
}
Ejemplo n.º 18
0
void XmlParser::_readNd() {
    if (_prevParentElementId == _parentElementId) {
        ++_ndPosCount;
    } else {
        _prevParentElementId = _parentElementId;
        _ndPosCount = 0;
    }
    std::string ref;
    // Read attributes
    if (xmlTextReaderHasAttributes(_reader) == XmlStatus::TRUE) {
        while (xmlTextReaderMoveToNextAttribute(_reader)) {
            std::string k = (char*) xmlTextReaderConstName(_reader);
            std::string v = (char*) xmlTextReaderConstValue(_reader);
            if (k == "ref") {
                ref = v;
            }
        }
    }
    _dbBuilder.addNd(_parentElementId, ref, _ndPosCount);
}
Ejemplo n.º 19
0
libvisio::VSDXRelationship::VSDXRelationship(xmlTextReaderPtr reader)
  : m_id(), m_type(), m_target()
{
  if (reader)
    // TODO: check whether we are actually parsing "Relationship" element
  {
    while (xmlTextReaderMoveToNextAttribute(reader))
    {
      const xmlChar *name = xmlTextReaderConstName(reader);
      const xmlChar *value = xmlTextReaderConstValue(reader);
      if (xmlStrEqual(name, BAD_CAST("Id")))
        m_id = (const char *)value;
      else if (xmlStrEqual(name, BAD_CAST("Type")))
        m_type = (const char *)value;
      else if (xmlStrEqual(name, BAD_CAST("Target")))
        m_target = (const char *)value;
    }
    // VSD_DEBUG_MSG(("Relationship : %s type: %s target: %s\n", m_id.c_str(), m_type.c_str(), m_target.c_str()));
  }
}
Ejemplo n.º 20
0
int XMIResource::loadAnnotation(xmlTextReaderPtr reader, const model::BaseObject& o)
{
    assert(o.kind() == ANNOTATION);

    // load the base class
    int ret = loadAbstractBaseObject(reader, o);
    if (ret != 1)
    {
        return ret;
    }

    // geometry is handled as a node

    // iterate on attributes
    for (int rc = xmlTextReaderMoveToFirstAttribute(reader); rc > 0; rc = xmlTextReaderMoveToNextAttribute(reader))
    {
        auto found = std::find(constXcosNames.begin(), constXcosNames.end(), xmlTextReaderConstName(reader));
        enum xcosNames current = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), found));
        switch (current)
        {
            case e_description:
                controller.setObjectProperty(o.id(), o.kind(), DESCRIPTION, to_string(xmlTextReaderConstValue(reader)));
                break;
            case e_font:
                controller.setObjectProperty(o.id(), o.kind(), FONT, to_string(xmlTextReaderConstValue(reader)));
                break;
            case e_fontSize:
                controller.setObjectProperty(o.id(), o.kind(), FONT_SIZE, to_string(xmlTextReaderConstValue(reader)));
                break;
            case e_style:
                controller.setObjectProperty(o.id(), o.kind(), STYLE, to_string(xmlTextReaderConstValue(reader)));
                break;
            default:
                // ignore other parameters
                // TODO: Does other metamodels might be managed there ?
                break;
        }
    }

    return ret;
}
Ejemplo n.º 21
0
        bool next()
        {
            int res;
            if(first) {
                res = xmlTextReaderMoveToFirstAttribute(reader);
            } else {
                res = xmlTextReaderMoveToNextAttribute(reader);
                
            }

            if(res < 0)
                throw std::runtime_error("parse error.");
            if(res == 0) {
                last = true;
                xmlTextReaderMoveToElement(reader);               
                return false;
            }
            first = false;

            return true;
        }
Ejemplo n.º 22
0
TileMapParseStatus TileMap_parse_layer(xmlTextReaderPtr reader, TileMap *map,
                                       TileMapLayer **out_layer) {
  TileMapParseStatus status = TILEMAP_PARSE_OK;
  TileMapLayer *layer = TileMapLayer_create();
  check(layer != NULL, "Couldn't create layer");
  
  while (xmlTextReaderMoveToNextAttribute(reader)) {
    xmlChar *attrName = xmlTextReaderName(reader);
    xmlChar *attrVal = xmlTextReaderValue(reader);
    
    if (streq(attrName, "name")) {
      layer->name = calloc(1, strlen((const char *)attrVal) + 1);
      strcpy(layer->name, (const char *)attrVal);
    } else if (streq(attrName, "opacity")) {
      layer->opacity = atof((const char *)attrVal);
    } else if (streq(attrName, "visible")) {
      layer->visible = atoi((const char *)attrVal);
    }
  }
  
  while (xmlTextReaderRead(reader)) {
    xmlChar *childName = xmlTextReaderName(reader);
    if (xmlTextReaderNodeType(reader) == XML_ELEMENT_DECL &&
        streq(childName, "layer")) {
      break;
    } else if (streq(childName, "data")) {
      status = TileMapLayer_parse_data(reader, map, layer);
      check(status == TILEMAP_PARSE_OK, "Failed to parse layer data");
    }
  }
  
  if (status == TILEMAP_PARSE_OK) {
    *out_layer = layer;
    return status;
  }
error:
  if (layer) TileMapLayer_destroy(layer);
  if (status == TILEMAP_PARSE_OK) status = TILEMAP_PARSE_UNKNOWN_ERR;
  return status;
}
Ejemplo n.º 23
0
bool MMSXMLServerInterface::funcSendEvent(xmlNodePtr node, string *answer) {
    xmlChar  *heading, *name, *value;/**pluginid*/
    xmlTextReader *reader;
	MMSEvent *event;

    if(!node || !answer) return false;

    /* get attributes */
    heading  = xmlGetProp(node, (const xmlChar*)"heading");
    reader = xmlReaderWalker(node->doc);
    //pluginid = xmlTextReaderGetAttribute(reader, (const xmlChar*)"pluginid");

    if(!heading /*|| !pluginid*/) return false;

    event = new MMSEvent((const char*)heading);

    /* through <func/> childs */
    while(xmlTextReaderRead(reader)) {
        name = (xmlChar*)xmlTextReaderConstName(reader);
        if(name && xmlStrEqual(name, (const xmlChar*)"param")) {
            while(xmlTextReaderMoveToNextAttribute(reader)) {
                name  = xmlTextReaderName(reader);
                value = xmlTextReaderValue(reader);
                event->setData((const char*)name, (const char*)value);
                xmlFree(name);
                xmlFree(value);
            }
        }
    }
	/* build answer */
	*answer = "<ret/>";

    event->send();


    return true;
}
Ejemplo n.º 24
0
int XMIResource::loadGeometry(xmlTextReaderPtr reader, const model::BaseObject& o)
{
    assert(o.kind() == BLOCK || o.kind() == ANNOTATION || o.kind() == LINK);

    std::vector<double> geom;
    controller.getObjectProperty(o.id(), o.kind(), GEOMETRY, geom);
    geom.resize(4);

    // iterate on attributes
    for (int rc = xmlTextReaderMoveToFirstAttribute(reader); rc > 0; rc = xmlTextReaderMoveToNextAttribute(reader))
    {
        auto found = std::find(constXcosNames.begin(), constXcosNames.end(), xmlTextReaderConstName(reader));
        enum xcosNames current = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), found));
        switch (current)
        {
            case e_x:
                geom[0] = to_double(xmlTextReaderConstValue(reader));
                break;
            case e_y:
                geom[1] = to_double(xmlTextReaderConstValue(reader));
                break;
            case e_width:
                geom[2] = to_double(xmlTextReaderConstValue(reader));
                break;
            case e_height:
                geom[3] = to_double(xmlTextReaderConstValue(reader));
                break;
            default:
                // ignore other parameters
                // TODO: Does other metamodels might be managed there ?
                break;
        }
    }

    controller.setObjectProperty(o.id(), o.kind(), GEOMETRY, geom);
    return 1;
}
Ejemplo n.º 25
0
void XmlParser::_readTag() {
    std::string k;
    std::string v;
    // Read attributes
    if (xmlTextReaderHasAttributes(_reader) == XmlStatus::TRUE) {
        while (xmlTextReaderMoveToNextAttribute(_reader)) {
            std::string key = (char*) xmlTextReaderConstName(_reader);
            std::string val = (char*) xmlTextReaderConstValue(_reader);
            if (key == "k") {
                k = val;
            } else if (key == "v") {
                v = val;
            }
        }
    }
    
    // Only blast the previous tags for the element once when updating.
    if (_prevTagParentElementId == _parentElementId) {
        _dbBuilder.addTag(_parentElementType, _parentElementId, k, v, false);
    } else {
        _dbBuilder.addTag(_parentElementType, _parentElementId, k, v, true);
        _prevTagParentElementId = _parentElementId;
    }
}
Ejemplo n.º 26
0
void daeLIBXMLPlugin::readAttributes( daeElement *element, xmlTextReaderPtr reader ) {
	// See if the element has attributes
	if(xmlTextReaderHasAttributes(reader))
	{
		// Read in and set all the attributes
		while(xmlTextReaderMoveToNextAttribute(reader))
		{
			daeMetaAttribute *ma = element->getMeta()->getMetaAttribute((const daeString)xmlTextReaderConstName(reader));
			if( ( ma != NULL && ma->getType() != NULL && ma->getType()->getUsesStrings() ) || 
				strcmp(element->getMeta()->getName(), "any") == 0 )
			{
				// String is used as one piece
				if(!element->setAttribute( (const daeString)xmlTextReaderConstName(reader), 
					(const daeString)xmlTextReaderConstValue(reader) ) )
				{
					const xmlChar * attName	 = xmlTextReaderConstName(reader);
					const xmlChar * attValue = xmlTextReaderConstValue(reader);
					char err[256];
					memset( err, 0, 256 );
#if LIBXML_VERSION >= 20620
					sprintf(err,"The DOM was unable to create an attribute %s = %s at line %d\nProbably a schema violation.\n", attName, attValue ,xmlTextReaderGetParserLineNumber(reader));
#else
					sprintf(err,"The DOM was unable to create an attribute %s = %s \nProbably a schema violation.\n", attName, attValue);
#endif
					daeErrorHandler::get()->handleWarning( err );
				}
			}
			else
			{
				// String needs to be broken up into whitespace seperated items.  The "set" methods for numbers are smart enough to
				// grab just the first number in a string, but the ones for string lists require a null terminator between each
				// string.  If this could be fixed we could avoid a copy and memory allocation by using xmlTextReaderConstValue(reader)
				if ( ma == NULL ) {
					const xmlChar * attName	 = xmlTextReaderConstName(reader);
					const xmlChar * attValue = xmlTextReaderConstValue(reader);
					char err[256];
					memset( err, 0, 256 );
#if LIBXML_VERSION >= 20620
					sprintf(err,"The DOM was unable to create an attribute %s = %s at line %d\nProbably a schema violation.\n", attName, attValue ,xmlTextReaderGetParserLineNumber(reader));
#else				
					sprintf(err,"The DOM was unable to create an attribute %s = %s \nProbably a schema violation.\n", attName, attValue);
#endif
					daeErrorHandler::get()->handleWarning( err );
					continue;
				}
				xmlChar* value = xmlTextReaderValue(reader);
				daeChar* current = (daeChar *)value;
				while(*current != 0)
				{
					// !!!GAC NEEDS TO BE CHANGED to use XML standard whitespace parsing
					// Skip leading whitespace
					while(*current == ' ' || *current == '\r' || *current == '\n' || *current == '\t') current++;
					if(*current != 0)
					{
						daeChar* start=current;
						// Find end of string and insert a zero terminator
						while(*current != ' ' && *current != '\r' && *current != '\n' && *current != '\t' && *current != 0) current++;
						if(*current != 0)
						{
							*current = 0;
							current++;
						}
						if(!element->setAttribute( (const daeString)xmlTextReaderConstName(reader), start) )
						{
							const xmlChar * attName	 = xmlTextReaderConstName(reader);
							const xmlChar * attValue = xmlTextReaderConstValue(reader);
							char err[256];
							memset( err, 0, 256 );
#if LIBXML_VERSION >= 20620
							sprintf(err,"The DOM was unable to create an attribute %s = %s at line %d\nProbably a schema violation.\n", attName, attValue ,xmlTextReaderGetParserLineNumber(reader));
#else
							sprintf(err,"The DOM was unable to create an attribute %s = %s \nProbably a schema violation.\n", attName, attValue);
#endif
							daeErrorHandler::get()->handleWarning( err );
						}
					}
				}
				xmlFree(value);
			}
		}
	}
}
Ejemplo n.º 27
0
int readxml
  (
    const char *xmlfile, /* filename to read */
    const struct elemdesc *elems, /* array terminated by entry with null elemname field */
    const struct elemattr *attrs /* array terminated by entry with null elem field */
  )
  /* opens and reads an XML file according to the given element and attribute definitions. */
  {
    enum
      {
        maxdepth = 10, /* should be enough */
      };
    int curstate = 0, statehistory[maxdepth];
    xmlTextReaderPtr f;
    struct vfile fd;

    fd = varied_open(xmlfile, O_RDONLY, "XML file");
    f = xmlReaderForIO(xml_varied_read, xml_varied_close, &fd, xmlfile, NULL, 0);
    if (!f)
      {
        fprintf(stderr, "ERR:  Unable to open XML file %s\n", xmlfile);
        return 1;
      } /*if*/
    while (true)
      {
        int r = xmlTextReaderRead(f);
        if (!r)
          {
            fprintf(stderr, "ERR:  Read premature EOF\n");
            return 1;
          } /*if*/
        if (r != 1)
          {
            fprintf(stderr, "ERR:  Error in parsing XML\n");
            return 1;
          } /*if*/
        switch (xmlTextReaderNodeType(f))
          {
        case XML_READER_TYPE_SIGNIFICANT_WHITESPACE:
        case XML_READER_TYPE_WHITESPACE:
        case XML_READER_TYPE_COMMENT:
          /* ignore */
        break;
        case XML_READER_TYPE_ELEMENT:
          {
            const char * const elemname = (const char *)xmlTextReaderName(f);
            int tagindex;
            assert(!parser_body);
            for (tagindex = 0; elems[tagindex].elemname; tagindex++)
                if
                  (
                        curstate == elems[tagindex].parentstate
                    &&
                        !strcmp(elemname, elems[tagindex].elemname)
                  )
                  {
                    // reading the attributes causes these values to change
                    // so if you want to use them later, save them now
                    const bool empty = xmlTextReaderIsEmptyElement(f);
                    const int depth = xmlTextReaderDepth(f);
                    if (depth >= maxdepth)
                      {
                        fprintf
                          (
                            stderr,
                            "ERR:  max XML parsing depth of %d exceeded\n",
                            maxdepth - 1
                          );
                        exit(1);
                      } /*if*/
                    if (elems[tagindex].start)
                      {
                        elems[tagindex].start();
                        if (parser_err)
                            return 1;
                      } /*if*/
                    while (xmlTextReaderMoveToNextAttribute(f))
                      {
                        const char * const nm = (const char *)xmlTextReaderName(f);
                        const char * const v = (const char *)xmlTextReaderValue(f);
                        int attrindex;
                        for (attrindex = 0; attrs[attrindex].elem; attrindex++)
                            if
                              (
                                    !strcmp(attrs[attrindex].elem, elems[tagindex].elemname)
                                &&
                                    !strcmp(attrs[attrindex].attr, nm)
                              )
                              {
                                attrs[attrindex].f(v);
                                if (parser_err)
                                    return 1;
                                break;
                              } /*if*/
                        if (!attrs[attrindex].elem)
                          {
                            bool gotattr = false;
                            fprintf
                              (
                                stderr,
                                "ERR:  Cannot match attribute '%s' in tag '%s'."
                                    "  Valid attributes are:\n",
                                nm,
                                elems[tagindex].elemname
                              );
                            for (attrindex = 0; attrs[attrindex].elem; attrindex++)
                                if (!strcmp(attrs[attrindex].elem, elems[tagindex].elemname))
                                  {
                                    fprintf(stderr, "ERR:      %s\n", attrs[attrindex]. attr);
                                    gotattr = true;
                                  } /*if*/
                            if (!gotattr)
                              {
                                fprintf(stderr, "ERR:      (none)\n");
                              } /*if*/
                            return 1;
                          } /*if*/
                        xmlFree((xmlChar *)nm);
                        xmlFree((xmlChar *)v);
                      } /*while*/
                    if (empty)
                      {
                      /* tag ends immediately */
                        if (elems[tagindex].end)
                          {
                            elems[tagindex].end();
                            if (parser_err)
                                return 1;
                          } /*if*/
                      }
                    else
                      {
                        statehistory[depth] = tagindex;
                        curstate = elems[tagindex].newstate;
                      } /*if*/
                    break;
                  } /*if; for*/
            if (!elems[tagindex].elemname)
              {
                fprintf(stderr, "ERR:  Cannot match start tag '%s'.  Valid tags are:\n", elemname);
                for (tagindex = 0; elems[tagindex].elemname; tagindex++)
                    if (curstate == elems[tagindex].parentstate)
                        fprintf(stderr, "ERR:      %s\n", elems[tagindex].elemname);
                return 1;
              } /*if*/
            xmlFree((xmlChar *)elemname);
          }
        break;
        case XML_READER_TYPE_END_ELEMENT:
          {
            const int tagindex = statehistory[xmlTextReaderDepth(f)];
            if (elems[tagindex].end)
              {
                elems[tagindex].end();
                if (parser_err)
                    return 1;
              } /*if*/
            curstate = elems[tagindex].parentstate;
          /* Note I don't handle sub-tags mixed with content! */
            free(parser_body);
            parser_body = 0;
            parser_acceptbody = false;
            if (!curstate)
                goto done_parsing;
          }
        break;
        case XML_READER_TYPE_TEXT:
        case XML_READER_TYPE_CDATA:
          {
            const char * const v = (const char *)xmlTextReaderValue(f);
            if (!parser_body)
              {
                // stupid buggy libxml2 2.5.4 that ships with RedHat 9.0!
                // we must manually check if this is just whitespace
                int i;
                for (i = 0; v[i]; i++)
                    if
                      (
                            v[i] != '\r'
                        &&
                            v[i] != '\n'
                        &&
                            v[i] != ' '
                        &&
                            v[i] != '\t'
                      )
                        goto has_nonws_body;
                xmlFree((xmlChar *)v);
                break;
              } /*if*/
has_nonws_body:
            if (!parser_acceptbody)
              {
                fprintf(stderr, "ERR:  text not allowed here\n");
                return 1;
              } /*if*/
            if (!parser_body)
                parser_body = strdup(v); /* first lot of tag content */
            else
              {
              /* append to previous tag content */
                parser_body = realloc(parser_body, strlen(parser_body) + strlen(v) + 1);
                strcat(parser_body, v);
              } /*if*/
            xmlFree((xmlChar *)v);
          }
        break;
        default:
            fprintf(stderr, "ERR:  Unknown XML node type %d\n", xmlTextReaderNodeType(f));
            exit(1);
          } /*switch*/
      } /*while*/
 done_parsing:
    xmlFreeTextReader(f);
    return 0;
  } /*readxml*/
Ejemplo n.º 28
0
static int ooxml_content_cb(int fd, cli_ctx *ctx)
{
    int ret = CL_SUCCESS, tmp, toval = 0, state;
    int core=0, extn=0, cust=0, dsig=0;
    int mcore=0, mextn=0, mcust=0;
    const xmlChar *name, *value, *CT, *PN;
    xmlTextReaderPtr reader = NULL;
    uint32_t loff;

    unsigned long sav_scansize = ctx->scansize;
    unsigned int sav_scannedfiles = ctx->scannedfiles;

    cli_dbgmsg("in ooxml_content_cb\n");

    /* perform engine limit checks in temporary tracking session */
    ret = ooxml_updatelimits(fd, ctx);
    if (ret != CL_CLEAN)
        return ret;

    /* apply a reader to the document */
    reader = xmlReaderForFd(fd, "[Content_Types].xml", NULL, CLAMAV_MIN_XMLREADER_FLAGS);
    if (reader == NULL) {
        cli_dbgmsg("ooxml_content_cb: xmlReaderForFd error for ""[Content_Types].xml""\n");
        cli_json_parse_error(ctx->wrkproperty, "OOXML_ERROR_XML_READER_FD");

        ctx->scansize = sav_scansize;
        ctx->scannedfiles = sav_scannedfiles;
        return CL_SUCCESS; // libxml2 failed!
    }

    /* locate core-properties, extended-properties, and custom-properties (optional) */
    while ((state = xmlTextReaderRead(reader)) == 1) {
        if (cli_json_timeout_cycle_check(ctx, &toval) != CL_SUCCESS) {
            ret = CL_ETIMEOUT;
            goto ooxml_content_exit;
        }

        name = xmlTextReaderConstLocalName(reader);
        if (name == NULL) continue;

        if (strcmp((const char *)name, "Override")) continue;

        if (xmlTextReaderHasAttributes(reader) != 1) continue;

        CT = PN = NULL;
        while (xmlTextReaderMoveToNextAttribute(reader) == 1) {
            name = xmlTextReaderConstLocalName(reader);
            value = xmlTextReaderConstValue(reader);
            if (name == NULL || value == NULL) continue;

            if (!xmlStrcmp(name, (const xmlChar *)"ContentType")) {
                CT = value;
            }
            else if (!xmlStrcmp(name, (const xmlChar *)"PartName")) {
                PN = value;
            }

            cli_dbgmsg("%s: %s\n", name, value);
        }

        if (!CT && !PN) continue;

        if (!xmlStrcmp(CT, (const xmlChar *)"application/vnd.openxmlformats-package.core-properties+xml")) {
            /* default: /docProps/core.xml*/
            tmp = unzip_search_single(ctx, (const char *)(PN+1), xmlStrlen(PN)-1, &loff);
            if (tmp == CL_ETIMEOUT) {
                ret = tmp;
            }
            else if (tmp != CL_VIRUS) {
                cli_dbgmsg("cli_process_ooxml: failed to find core properties file \"%s\"!\n", PN);
                mcore++;
            }
            else {
                cli_dbgmsg("ooxml_content_cb: found core properties file \"%s\" @ %x\n", PN, loff);
                if (!core) {
                    tmp = unzip_single_internal(ctx, loff, ooxml_core_cb);
                    if (tmp == CL_ETIMEOUT || tmp == CL_EMEM) {
                        ret = tmp;
                    }
                }
                core++;
            }
        }
        else if (!xmlStrcmp(CT, (const xmlChar *)"application/vnd.openxmlformats-officedocument.extended-properties+xml")) {
            /* default: /docProps/app.xml */
            tmp = unzip_search_single(ctx, (const char *)(PN+1), xmlStrlen(PN)-1, &loff);
            if (tmp == CL_ETIMEOUT) {
                ret = tmp;
            }
            else if (tmp != CL_VIRUS) {
                cli_dbgmsg("cli_process_ooxml: failed to find extended properties file \"%s\"!\n", PN);
                mextn++;
            }
            else {
                cli_dbgmsg("ooxml_content_cb: found extended properties file \"%s\" @ %x\n", PN, loff);
                if (!extn) {
                    tmp = unzip_single_internal(ctx, loff, ooxml_extn_cb);
                    if (tmp == CL_ETIMEOUT || tmp == CL_EMEM) {
                        ret = tmp;
                    }
                }
                extn++;
            }
        }
        else if (!xmlStrcmp(CT, (const xmlChar *)"application/vnd.openxmlformats-officedocument.custom-properties+xml")) {
            /* default: /docProps/custom.xml */
            tmp = unzip_search_single(ctx, (const char *)(PN+1), xmlStrlen(PN)-1, &loff);
            if (tmp == CL_ETIMEOUT) {
                ret = tmp;
            }
            else if (tmp != CL_VIRUS) {
                cli_dbgmsg("cli_process_ooxml: failed to find custom properties file \"%s\"!\n", PN);
                mcust++;
            }
            else {
                cli_dbgmsg("ooxml_content_cb: found custom properties file \"%s\" @ %x\n", PN, loff);
                /* custom properties are not parsed */
                cust++;
            }
        }
        else if (!xmlStrcmp(CT, (const xmlChar *)"application/vnd.openxmlformats-package.digital-signature-xmlsignature+xml")) {
            dsig++;
        }

        if (ret != CL_SUCCESS)
            goto ooxml_content_exit;
    }

 ooxml_content_exit:
    if (core) {
        cli_jsonint(ctx->wrkproperty, "CorePropertiesFileCount", core);
        if (core > 1)
            cli_json_parse_error(ctx->wrkproperty, "OOXML_ERROR_MULTIPLE_CORE_PROPFILES");
    }
    else if (!mcore)
        cli_dbgmsg("cli_process_ooxml: file does not contain core properties file\n");
    if (mcore) {
        cli_jsonint(ctx->wrkproperty, "CorePropertiesMissingFileCount", mcore);
        cli_json_parse_error(ctx->wrkproperty, "OOXML_ERROR_MISSING_CORE_PROPFILES");
    }

    if (extn) {
        cli_jsonint(ctx->wrkproperty, "ExtendedPropertiesFileCount", extn);
        if (extn > 1)
            cli_json_parse_error(ctx->wrkproperty, "OOXML_ERROR_MULTIPLE_EXTN_PROPFILES");
    }
    else if (!mextn)
        cli_dbgmsg("cli_process_ooxml: file does not contain extended properties file\n");
    if (mextn) {
        cli_jsonint(ctx->wrkproperty, "ExtendedPropertiesMissingFileCount", mextn);
        cli_json_parse_error(ctx->wrkproperty, "OOXML_ERROR_MISSING_EXTN_PROPFILES");
    }

    if (cust) {
        cli_jsonint(ctx->wrkproperty, "CustomPropertiesFileCount", cust);
        if (cust > 1)
            cli_json_parse_error(ctx->wrkproperty, "OOXML_ERROR_MULTIPLE_CUSTOM_PROPFILES");
    }
    else if (!mcust)
        cli_dbgmsg("cli_process_ooxml: file does not contain custom properties file\n");
    if (mcust) {
        cli_jsonint(ctx->wrkproperty, "CustomPropertiesMissingFileCount", mcust);
        cli_json_parse_error(ctx->wrkproperty, "OOXML_ERROR_MISSING_CUST_PROPFILES");
    }

    if (dsig) {
        cli_jsonint(ctx->wrkproperty, "DigitalSignaturesCount", dsig);
    }

    /* restore the engine tracking limits; resets session limit tracking */
    ctx->scansize = sav_scansize;
    ctx->scannedfiles = sav_scannedfiles;

    xmlTextReaderClose(reader);
    xmlFreeTextReader(reader);
    return ret;
}
Ejemplo n.º 29
0
/*
 * call-seq:
 *    reader.move_to_next_attribute -> code
 *
 * Move the position of the current instance to the next attribute associated
 * with the current node.
 */
static VALUE rxml_reader_move_to_next_attr(VALUE self)
{
  return INT2FIX(xmlTextReaderMoveToNextAttribute(rxml_text_reader_get(self)));
}
Ejemplo n.º 30
0
int XMIResource::processElement(xmlTextReaderPtr reader)
{
    const xmlChar *name = xmlTextReaderConstLocalName(reader);
    parent = NB_XCOS_NAMES;

    // lookup for known node names
    // thanks to the string intern-ing, the pointer comparison could be used
    auto found = std::find(constXcosNames.begin(), constXcosNames.end(), name);
    enum xcosNames current = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), found));
    switch (current)
    {
        case e_Diagram:
        {
            // the root diagram should be decoded
            model::BaseObject o(root, DIAGRAM);

            processed.push_back(o);
            return loadDiagram(reader, o);
        }
        case e_child:
        {
            // this is a child of a diagram, resolve the type and call the loaders
            // iterate on attributes to lookup for EMF type

            // iterate on attributes
            for (int rc = xmlTextReaderMoveToFirstAttribute(reader); rc > 0; rc = xmlTextReaderMoveToNextAttribute(reader))
            {
                const xmlChar* nsURI  = xmlTextReaderConstNamespaceUri(reader);
                if (nsURI != xsiNamespaceUri)
                {
                    continue;
                }

                auto foundName = std::find(constXcosNames.begin(), constXcosNames.end(), xmlTextReaderConstLocalName(reader));
                enum xcosNames currentName = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), foundName));
                if (currentName != e_type)
                {
                    continue;
                }

                const xmlChar* value = xmlTextReaderConstValue(reader);
                const xmlChar* valueWithoutPrefix = BAD_CAST(std::strchr((const char*) value, ':'));
                if (valueWithoutPrefix == nullptr)
                {
                    valueWithoutPrefix = value;
                }
                else
                {
                    // remove the leading ':'
                    valueWithoutPrefix = valueWithoutPrefix + 1;
                }
                const xmlChar* interned = xmlTextReaderConstString(reader, valueWithoutPrefix);

                auto found = std::find(constXcosNames.begin(), constXcosNames.end(), interned);
                enum xcosNames current = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), found));
                switch (current)
                {
                    case e_Block:
                    {
                        ScicosID o = controller.createObject(BLOCK);

                        // assign the child
                        model::BaseObject parent = processed.back();
                        std::vector<ScicosID> children;
                        controller.getObjectProperty(parent.id(), parent.kind(), CHILDREN, children);
                        children.push_back(o);
                        controller.setObjectProperty(parent.id(), parent.kind(), CHILDREN, children);

                        model::BaseObject child(o, BLOCK);
                        processed.push_back(child);
                        return loadBlock(reader, child);
                    }
                    case e_Link:
                    {
                        ScicosID o = controller.createObject(LINK);

                        // assign the child
                        model::BaseObject parent = processed.back();
                        std::vector<ScicosID> children;
                        controller.getObjectProperty(parent.id(), parent.kind(), CHILDREN, children);
                        children.push_back(o);
                        controller.setObjectProperty(parent.id(), parent.kind(), CHILDREN, children);

                        model::BaseObject child(o, LINK);
                        processed.push_back(child);
                        return loadLink(reader, child);
                    }
                    case e_Annotation:
                    {
                        ScicosID o = controller.createObject(ANNOTATION);

                        // assign the child
                        model::BaseObject parent = processed.back();
                        std::vector<ScicosID> children;
                        controller.getObjectProperty(parent.id(), parent.kind(), CHILDREN, children);
                        children.push_back(o);
                        controller.setObjectProperty(parent.id(), parent.kind(), CHILDREN, children);

                        model::BaseObject child(o, ANNOTATION);
                        return loadAnnotation(reader, child);
                    }
                    default:
                        sciprint("Not handled child type=%s at line %d\n", *found,
                                 xmlTextReaderGetParserLineNumber(reader) - 1);
                        return -1;
                }
            }
            break;
        }
        case e_in: // no break on purpose
        case e_out: // no break on purpose
        case e_ein: // no break on purpose
        case e_eout:
        {
            ScicosID o = controller.createObject(PORT);

            enum object_properties_t p;
            switch (current)
            {
                case e_in:
                    p = INPUTS;
                    break;
                case e_out:
                    p = OUTPUTS;
                    break;
                case e_ein:
                    p = EVENT_INPUTS;
                    break;
                case e_eout:
                    p = EVENT_OUTPUTS;
                    break;
                default:
                    return -1;
            }

            model::BaseObject parent = processed.back();
            // add the port them to the parent
            std::vector<ScicosID> ports;
            controller.getObjectProperty(parent.id(), parent.kind(), p, ports);
            ports.push_back(o);
            controller.setObjectProperty(parent.id(), parent.kind(), p, ports);

            // decode content
            model::BaseObject child(o, PORT);
            return loadPort(reader, child);
        }
        case e_geometry:
            // geometry is used for rectangle coordinates of its parent
            return loadGeometry(reader, processed.back());
        case e_nzcross:
            // nzcross is a Block property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_nmode:
            // nmode is a Block property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_rpar:
            // rpar is a Block property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_ipar:
            // ipar is a Block property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_opar:
            // ipar is a Block property
            return loadBase64(reader, OPAR, processed.back());
        case e_state:
            // state is a Block property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_dstate:
            // dstate is a Block property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_odstate:
            // odstate is a Block property
            return loadBase64(reader, ODSTATE, processed.back());
        case e_equations:
            // equation is a Block property
            return loadBase64(reader, EQUATIONS, processed.back());
        case e_expression:
            // expression is a Block property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_exprs:
            // exprs is a Block property
            return loadBase64(reader, EXPRS, processed.back());
        case e_controlPoint:
            // controlPoint is a link property
            return loadPoint(reader, processed.back());
        case e_context:
            // context is a Layer property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_properties:
            // properties is a Diagram property
            return loadSimulationConfig(reader, processed.back());
        case e_datatype:
            // datatype is a Port property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        default:
            sciprint("Unknown \"%s\" element name at line %d\n", name, xmlTextReaderGetParserLineNumber(reader) - 1);
            return -1;
    }

    return 1;
}