예제 #1
0
파일: comment.c 프로젝트: ARYANJASHWAL/php7
/* {{{ proto void DOMComment::__construct([string value]); */
PHP_METHOD(domcomment, __construct)
{

	zval *id;
	xmlNodePtr nodep = NULL, oldnode = NULL;
	dom_object *intern;
	char *value = NULL;
	int value_len;
	zend_error_handling error_handling;

	zend_replace_error_handling(EH_THROW, dom_domexception_class_entry, &error_handling TSRMLS_CC);
	if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|s", &id, dom_comment_class_entry, &value, &value_len) == FAILURE) {
		zend_restore_error_handling(&error_handling TSRMLS_CC);
		return;
	}

	zend_restore_error_handling(&error_handling TSRMLS_CC);
	nodep = xmlNewComment((xmlChar *) value);

	if (!nodep) {
		php_dom_throw_error(INVALID_STATE_ERR, 1 TSRMLS_CC);
		RETURN_FALSE;
	}

	intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
	if (intern != NULL) {
		oldnode = dom_object_get_node(intern);
		if (oldnode != NULL) {
			php_libxml_node_free_resource(oldnode  TSRMLS_CC);
		}
		php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)nodep, (void *)intern TSRMLS_CC);
	}
}
예제 #2
0
파일: o_xml.cpp 프로젝트: AzyxWare/ryzom
bool COXml::xmlCommentInternal (const char *comment)
{
	nlassert( ! isReading() );

	// Check _InternalStream
	if ( _InternalStream )
	{
		// Not in the push mode ?
		if ( _CurrentNode != NULL)
		{
			// Add a comment node
			xmlNodePtr commentPtr = xmlNewComment ((const xmlChar *)comment);

			// Add the node
			xmlAddChild (_CurrentNode, commentPtr);
		}
		else
		{
			nlwarning ( "XML: You must call xmlCommentInternal between xmlPushBegin and xmlPushEnd.");
			return false;
		}
	}
	else
	{
		nlwarning ( "XML: Output stream has not been setuped.");
		return false;
	}
	// Ok
	return true;
}
예제 #3
0
파일: player.cpp 프로젝트: DuMuT6p/Epiar
/**\brief Generate an XMLNode of this PlayerInfo
 * \param[in] componentName This should always be "player".
 * \return A new XML node that represents the PlayerInfo.
 */
xmlNodePtr PlayerInfo::ToXMLNode(string componentName) {
	char buff[256];
	char *timestamp;
	xmlNodePtr section = xmlNewNode(NULL, BAD_CAST componentName.c_str());

	xmlNewChild(section, NULL, BAD_CAST "name", BAD_CAST name.c_str() );
	xmlNewChild(section, NULL, BAD_CAST "file", BAD_CAST file.c_str() );
	if( (avatar != NULL) && (avatar->GetPath() != "") ) {
		xmlNewChild(section, NULL, BAD_CAST "avatar", BAD_CAST avatar->GetPath().c_str() );
	}

	xmlNewChild(section, NULL, BAD_CAST "simulation", BAD_CAST simulation.c_str() );
	snprintf(buff, sizeof(buff), "%d", seed );
	xmlNewChild(section, NULL, BAD_CAST "seed", BAD_CAST buff );

	// Last Load Time
	snprintf(buff, sizeof(buff), "%d", (int)lastLoadTime );
	xmlNewChild(section, NULL, BAD_CAST "lastLoadTime", BAD_CAST buff );

	// Save a Human readable comment to explain the Last Load time
	strcpy( buff, "Last Load: " );
	timestamp = ctime( &lastLoadTime );
	timestamp[strlen(timestamp)-1] = '\0';
	xmlAddChild( section, xmlNewComment( BAD_CAST timestamp));

	return section;
}
예제 #4
0
/* {{{ proto void DOMComment::__construct([string value]); */
PHP_METHOD(domcomment, __construct)
{

	zval *id = getThis();
	xmlNodePtr nodep = NULL, oldnode = NULL;
	dom_object *intern;
	char *value = NULL;
	size_t value_len;

	if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "|s", &value, &value_len) == FAILURE) {
		return;
	}

	nodep = xmlNewComment((xmlChar *) value);

	if (!nodep) {
		php_dom_throw_error(INVALID_STATE_ERR, 1);
		RETURN_FALSE;
	}

	intern = Z_DOMOBJ_P(id);
	if (intern != NULL) {
		oldnode = dom_object_get_node(intern);
		if (oldnode != NULL) {
			php_libxml_node_free_resource(oldnode );
		}
		php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)nodep, (void *)intern);
	}
}
예제 #5
0
파일: xdoc.C 프로젝트: viatsko/parser3
// Comment createComment(in DOMString data)
static void _createComment(Request& r, MethodParams& params) {
	xmlChar* data=as_xmlchar(r, params, 0, XML_DATA_MUST_BE_STRING);

	VXdoc& vdoc=GET_SELF(r, VXdoc);

	xmlNode *node=xmlNewComment(data);
	writeNode(r, vdoc, node);
}
예제 #6
0
파일: lua.cpp 프로젝트: cthielen/epiar
xmlNodePtr Lua::ConvertToXML( lua_State *L, int value_index, int key_index) {
    int t;
    char buff[1024];
    xmlNodePtr section = xmlNewNode(NULL, BAD_CAST "value");

    // Using lua_tostring will convert a value into a string.
    // Never use this on a table key.
    lua_pushvalue(L, key_index);
    t = lua_type(L, key_index);

    // Save the Key and keytype
    xmlSetProp( section, BAD_CAST "key", BAD_CAST lua_tostring(L, lua_gettop(L)) );
    xmlSetProp( section, BAD_CAST "keytype", BAD_CAST lua_typename(L, t));

    lua_pop(L,1); // Pop the copied key now that we're done with it.

    // Save the type
    t = lua_type(L, value_index);
    xmlSetProp( section, BAD_CAST "type", BAD_CAST lua_typename(L, t));

    // Save the value
    switch (t) {
    case LUA_TBOOLEAN:
        xmlNodeSetContent( section, BAD_CAST (lua_toboolean(L, value_index) ? "true" : "false"));
        break;
    case LUA_TNUMBER:
        snprintf(buff, sizeof(buff), "%f", lua_tonumber(L, value_index) );
        xmlNodeSetContent( section, BAD_CAST buff);
        break;
    case LUA_TSTRING:
        xmlNodeSetContent( section, BAD_CAST lua_tostring(L, value_index) );
        break;
    case LUA_TTABLE:
        lua_pushnil(L);
        while(lua_next(L, value_index)) {
            xmlAddChild( section, Lua::ConvertToXML(L, lua_gettop(L), lua_gettop(L)-1));

            // Pop off this value
            lua_pop(L, 1);
        }

        break;
    case LUA_TNIL:
    case LUA_TLIGHTUSERDATA:
    case LUA_TFUNCTION:
    case LUA_TUSERDATA:
    case LUA_TTHREAD:
        xmlAddChild( section, xmlNewComment( BAD_CAST "Cannot convert to XML"));
        break;
    default:
        assert(0);
        break;
    }
    return section;
}
예제 #7
0
/**
 * Process a file, checking if it should be listed and retrieving its data in
 * XML format.
 */
xmlNodePtr
file_proc(const gchar *real_path,
          const gchar *file_name)
{
    gchar *file_name_utf8;
    const gchar *file_extension;
    FileParser *parser;
    xmlNodePtr file_node = NULL;

    /* get UTF-8 encoded filename and extension */
    file_name_utf8 = g_filename_to_utf8(file_name, -1, NULL, NULL, NULL);
    file_extension = filename_get_extension(file_name_utf8);

    /* check if we support this file */
    if (file_extension == NULL || file_extension[0] == '\0') {
        /* extension-less file, we just ignore */
    }
    else if ((parser = file_parser_get_by_extension(file_extension)) != NULL) {
        /* we have a parser for this file -- good -- go ahead */
        FILE *fp;

        /* create file node */
        file_node = xmlNewNode(NULL, "file");
        xmlNewProp(file_node, "name", file_name_utf8);

        if ((fp = fopen(real_path, "rb")) != NULL) {
            glong file_size;
            gchar size_string[64];

            /* retrieve file size */
            /* @TODO support 64-bit file sizes */
            fseek(fp, 0, SEEK_END);
            file_size = ftell(fp);

            g_snprintf(size_string, sizeof size_string, "%ld", file_size);
            xmlNewProp(file_node, "size", size_string);

            /* parse (or at least try to) the file */
            rewind(fp);
            parser->func(file_node, fp);
        }
        else {                          /* fopen() returned NULL */
            xmlNodePtr comment = xmlNewComment("error opening file");
            xmlAddChild(file_node, comment);

            g_warning("%s: %s", real_path, g_strerror(errno));
        }

    }

    g_free(file_name_utf8);             /* free UTF-8 converted filename */
    return file_node;
}
예제 #8
0
void
XmlBuilder::AddComment(const iStringT& comment)
{
	check( doc_ != 0 || node_ != 0 );

	CvtTA<> cntA( comment.CStr(), CP_UTF8 );

	xmlNodePtr text = xmlNewComment( (xmlChar*)cntA.str_ );
	check( text != 0 );

	if ( !xmlAddChild( node_, text ) ) throw XmlBuilderException();
}
예제 #9
0
/**
 * Process a directory, listing each file and descending recursively into its
 * subdirectories.
 *
 * \param real_path Real path to the directory.
 * \param dir_name Directory name, the last component of its path.
 * \returns A newly allocated xmlNodePtr.
 */
xmlNodePtr
directory_proc(const gchar *real_path, const gchar *dir_name)
{
    xmlNodePtr dir_node;
    GDir *dir;
    gchar *dir_name_utf8;

    /* create directory node */
    dir_node = xmlNewNode(NULL, "directory");
    dir_name_utf8 = g_filename_to_utf8(dir_name, -1, NULL, NULL, NULL);
    xmlNewProp(dir_node, "name", dir_name_utf8);

    /* open directory */
    dir = g_dir_open(real_path, 0, NULL);

    if (dir != NULL) {                  /* g_dir_open() succeeded */
        const gchar *entry;

        log_info("Processing \"%s\"...", real_path);

        /* visit each directory entry */
        while ((entry = g_dir_read_name(dir)) != NULL) {
            gchar *full_name = g_build_filename(real_path, entry, NULL);

            if (g_file_test(full_name, G_FILE_TEST_IS_DIR)) {
                xmlNodePtr subdir_node = directory_proc(full_name, entry);

                if (subdir_node != NULL)
                    xmlAddChild(dir_node, subdir_node);
            }
            else if (g_file_test(full_name, G_FILE_TEST_IS_REGULAR)) {
                xmlNodePtr file_node = file_proc(full_name, entry);

                if (file_node != NULL)
                    xmlAddChild(dir_node, file_node);
            }

            g_free(full_name);
        }

        g_dir_close(dir);
    }
    else {                              /* g_dir_open() returned NULL */
        xmlNodePtr comment = xmlNewComment("error opening directory");
        xmlAddChild(dir_node, comment);

        g_warning("%s: %s", real_path, g_strerror(errno));
    }

    g_free(dir_name_utf8);              /* free UTF-8 converted filename */
    return dir_node;
}
예제 #10
0
/*
 * call-seq:
 *    XML::Node.new_comment(content = nil) -> XML::Node
 *
 * Create a new comment node, optionally setting
 * the node's content.
 *
 */
static VALUE rxml_node_new_comment(int argc, VALUE *argv, VALUE klass)
{
  VALUE content = Qnil;
  xmlNodePtr xnode;

  rb_scan_args(argc, argv, "01", &content);

  if (NIL_P(content))
  {
    xnode = xmlNewComment(NULL);
  }
  else
  {
    content = rb_obj_as_string(content);
    xnode = xmlNewComment((xmlChar*) StringValueCStr(content));
  }

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

  return rxml_node_wrap(xnode);
}
/**
 * xsltExtElementTest:
 * @ctxt:  an XSLT processing context
 * @node:  The current node
 * @inst:  the instruction in the stylesheet
 * @comp:  precomputed informations
 *
 * Process a libxslt:test node
 */
static void
xsltExtElementTest(xsltTransformContextPtr ctxt, xmlNodePtr node,
                   xmlNodePtr inst,
                   xsltElemPreCompPtr comp ATTRIBUTE_UNUSED)
{
    xmlNodePtr commentNode;

    if (testData == NULL) {
        xsltGenericDebug(xsltGenericDebugContext,
                         "xsltExtElementTest: not initialized,"
                         " calling xsltGetExtData\n");
        xsltGetExtData(ctxt, (const xmlChar *) XSLT_TESTPLUGIN_URL);
        if (testData == NULL) {
            xsltTransformError(ctxt, NULL, inst,
                               "xsltExtElementTest: not initialized\n");
            return;
        }
    }
    if (ctxt == NULL) {
        xsltTransformError(ctxt, NULL, inst,
                           "xsltExtElementTest: no transformation context\n");
        return;
    }
    if (node == NULL) {
        xsltTransformError(ctxt, NULL, inst,
                           "xsltExtElementTest: no current node\n");
        return;
    }
    if (inst == NULL) {
        xsltTransformError(ctxt, NULL, inst,
                           "xsltExtElementTest: no instruction\n");
        return;
    }
    if (ctxt->insert == NULL) {
        xsltTransformError(ctxt, NULL, inst,
                           "xsltExtElementTest: no insertion point\n");
        return;
    }
    commentNode = xmlNewComment((const xmlChar *)
                                "libxslt:testplugin element test worked");
    xmlAddChild(ctxt->insert, commentNode);
}
예제 #12
0
파일: mapwfs11.c 프로젝트: EOX-A/mapserver
xmlNodePtr msWFSDumpLayer11(mapObj *map, layerObj *lp, xmlNsPtr psNsOws,
                            int nWFSVersion, const char* validate_language)
{
  rectObj ext;

  xmlNodePtr psRootNode, psNode;
  const char *value    = NULL;
  char *valueToFree;
  char **tokens;
  int n=0,i=0;

  psRootNode = xmlNewNode(NULL, BAD_CAST "FeatureType");

  /* add namespace to layer name */
  value = msOWSLookupMetadata(&(map->web.metadata), "FO", "namespace_prefix");

  /* FIXME? Should probably be applied to WFS 1.1 as well, but the addition */
  /* of the prefix can be disruptive for clients */
  if( value == NULL && nWFSVersion >= OWS_2_0_0 )
      value = MS_DEFAULT_NAMESPACE_PREFIX;

  if(value) {
    n = strlen(value)+strlen(lp->name)+1+1;
    valueToFree = (char *) msSmallMalloc(sizeof(char*)*n);
    snprintf(valueToFree, n, "%s%s%s", (value ? value : ""), (value ? ":" : ""), lp->name);

    psNode = xmlNewChild(psRootNode, NULL, BAD_CAST "Name", BAD_CAST valueToFree);
    msFree(valueToFree);
  } else {
    psNode = xmlNewChild(psRootNode, NULL, BAD_CAST "Name", BAD_CAST lp->name);
  }

  if (lp->name && strlen(lp->name) > 0 &&
      (msIsXMLTagValid(lp->name) == MS_FALSE || isdigit(lp->name[0])))
  {
    char szTmp[512];
    snprintf(szTmp, sizeof(szTmp),
             "WARNING: The layer name '%s' might contain spaces or "
             "invalid characters or may start with a number. This could lead to potential problems",
             lp->name);
    xmlAddSibling(psNode, xmlNewComment(BAD_CAST szTmp));
  }

  value = msOWSLookupMetadataWithLanguage(&(lp->metadata), "FO", "title", validate_language);
  if (!value)
    value =(const char*)lp->name;

  psNode = xmlNewChild(psRootNode, NULL, BAD_CAST "Title", BAD_CAST value);


  value = msOWSLookupMetadataWithLanguage(&(lp->metadata), "FO", "abstract", validate_language);
  if (value)
    psNode = xmlNewChild(psRootNode, NULL, BAD_CAST "Abstract", BAD_CAST value);



  value = msOWSLookupMetadataWithLanguage(&(lp->metadata), "FO", "keywordlist", validate_language);

  if(value)
    msLibXml2GenerateList(
        xmlNewChild(psRootNode, psNsOws, BAD_CAST "Keywords", NULL),
        NULL, "Keyword", value, ',' );

  /*support DefaultSRS and OtherSRS*/
  valueToFree = msOWSGetProjURN(&(map->projection),&(map->web.metadata),"FO",MS_FALSE);
  if (!valueToFree)
    valueToFree = msOWSGetProjURN(&(lp->projection), &(lp->metadata), "FO", MS_FALSE);

  if (valueToFree) {
    tokens = msStringSplit(valueToFree, ' ', &n);
    if (tokens && n > 0) {
      if( nWFSVersion == OWS_1_1_0 )
        psNode = xmlNewChild(psRootNode, NULL, BAD_CAST "DefaultSRS", BAD_CAST tokens[0]);
      else
        psNode = xmlNewChild(psRootNode, NULL, BAD_CAST "DefaultCRS", BAD_CAST tokens[0]);
      for (i=1; i<n; i++)
      {
        if( nWFSVersion == OWS_1_1_0 )
          psNode = xmlNewChild(psRootNode, NULL, BAD_CAST "OtherSRS", BAD_CAST tokens[i]);
        else
          psNode = xmlNewChild(psRootNode, NULL, BAD_CAST "OtherCRS", BAD_CAST tokens[i]);
      }

      msFreeCharArray(tokens, n);
    }
  } else
    xmlAddSibling(psNode,
                  xmlNewComment(BAD_CAST "WARNING: Mandatory mapfile parameter: (at least one of) MAP.PROJECTION, LAYER.PROJECTION or wfs/ows_srs metadata was missing in this context."));

  free(valueToFree);
  valueToFree = NULL;

  /*TODO: adevertize only gml3?*/
  psNode = xmlNewNode(NULL, BAD_CAST "OutputFormats");
  xmlAddChild(psRootNode, psNode);

  {
    char *formats_list = msWFSGetOutputFormatList( map, lp, nWFSVersion );
    int iformat, n;
    char **tokens;

    n = 0;
    tokens = msStringSplit(formats_list, ',', &n);

    for( iformat = 0; iformat < n; iformat++ )
      xmlNewChild(psNode, NULL, BAD_CAST "Format",
                  BAD_CAST tokens[iformat] );
    msFree( formats_list );
    msFreeCharArray( tokens, n );
  }

  /*bbox*/
  if (msOWSGetLayerExtent(map, lp, "FO", &ext) == MS_SUCCESS) {
    /*convert to latlong*/
    if (lp->projection.numargs > 0)
      msOWSProjectToWGS84(&lp->projection, &ext);
    else
      msOWSProjectToWGS84(&map->projection, &ext);

    xmlAddChild(psRootNode,
                msOWSCommonWGS84BoundingBox( psNsOws, 2,
                    ext.minx, ext.miny,
                    ext.maxx, ext.maxy));
  } else {
    xmlNewChild(psRootNode, psNsOws, BAD_CAST "WGS84BoundingBox", NULL);
    xmlAddSibling(psNode,
                  xmlNewComment(BAD_CAST "WARNING: Optional WGS84BoundingBox could not be established for this layer.  Consider setting the EXTENT in the LAYER object, or wfs_extent metadata. Also check that your data exists in the DATA statement"));
  }

  value = msOWSLookupMetadata(&(lp->metadata), "FO", "metadataurl_href");

  if (value) {
    if( nWFSVersion >= OWS_2_0_0 )
    {
        psNode = xmlNewChild(psRootNode, NULL, BAD_CAST "MetadataURL", NULL);
        xmlNewProp(psNode, BAD_CAST "xlink:href", BAD_CAST value);

        value = msOWSLookupMetadata(&(lp->metadata), "FO", "metadataurl_about");
        if( value != NULL )
            xmlNewProp(psNode, BAD_CAST "about", BAD_CAST value);
    }
    else
    {
        psNode = xmlNewChild(psRootNode, NULL, BAD_CAST "MetadataURL", BAD_CAST value);

        value = msOWSLookupMetadata(&(lp->metadata), "FO", "metadataurl_format");

        if (!value)
            value = msStrdup("text/html"); /* default */

        xmlNewProp(psNode, BAD_CAST "format", BAD_CAST value);

        value = msOWSLookupMetadata(&(lp->metadata), "FO", "metadataurl_type");

        if (!value)
            value = msStrdup("FGDC"); /* default */

        xmlNewProp(psNode, BAD_CAST "type", BAD_CAST value);
    }
  }

  return psRootNode;
}
예제 #13
0
int
main (G_GNUC_UNUSED int argc, G_GNUC_UNUSED char** argv)
{
        xmlDocPtr doc;
        xmlNodePtr node;
        gchar *fname;
	xmlNodePtr out_top_node;
	xmlBufferPtr buf;

        fname = g_build_filename (ROOT_DIR, "libgda", FILE_NAME, NULL);
	if (! g_file_test (fname, G_FILE_TEST_EXISTS)) {
		g_free (fname);
		fname = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, FILE_NAME, NULL);
		if (! g_file_test (fname, G_FILE_TEST_EXISTS)) {
			g_print ("Could not find '%s'.\n", FILE_NAME);
			exit (1);
		}
	}

	doc = xmlParseFile (fname);
	if (!doc) {
		g_print ("Missing or malformed file '%s', check your installation", fname);
		g_free (fname);
		exit (1);
        }
	
	node = xmlDocGetRootElement (doc);
	g_free (fname);
	if (strcmp ((gchar *) node->name, "schema")) {
		g_print ("Root node should be <schema>, got <%s>\n", (gchar *) node->name);
		xmlFreeDoc (doc);
		exit (1);
	}

	out_top_node = xmlNewNode (NULL, BAD_CAST "sect2");
	xmlAddChild (out_top_node, xmlNewComment (BAD_CAST 
						  "File generated by the tools/information-schema-doc program from the\n"
						  "libgda/information-schema.xml file,\ndo not modify"));
	xmlNewChild (out_top_node, NULL, BAD_CAST "title", BAD_CAST "Individual table description");
	xmlNewChild (out_top_node, NULL, BAD_CAST "para", BAD_CAST "This section individually describes each table.");
	
	for (node = node->children; node; node = node->next) {
		if (!strcmp ((gchar *) node->name, "table")) {
			xmlNodePtr snode, child, table, row, ref = NULL;
			xmlChar *prop;
			snode = xmlNewChild (out_top_node, NULL, BAD_CAST "sect3", NULL);
			prop = xmlGetProp (node, BAD_CAST "name");
			if (prop) {
				gchar *str;
				str = g_strdup_printf ("is:%s", (gchar *) prop);
				xmlSetProp (snode, BAD_CAST "id", BAD_CAST str);
				g_free (str);

				str = g_strdup_printf ("%s table", (gchar *) prop);
				xmlNewTextChild (snode, NULL, BAD_CAST "title", BAD_CAST str);
				g_free (str);
				xmlFree (prop);
			}
			else
				xmlNewChild (snode, NULL, BAD_CAST "title", BAD_CAST "FIXME: table not named");

			prop = xmlGetProp (node, BAD_CAST "descr");
			if (prop) {
				xmlNewTextChild (snode, NULL, BAD_CAST "para", prop);
				xmlFree (prop);
			}
			table = xmlNewChild (snode, NULL, BAD_CAST "para", BAD_CAST "The following table describes the columns:");
			table = xmlNewChild (table, NULL, BAD_CAST "informaltable", NULL);
			xmlSetProp (table, BAD_CAST "frame", BAD_CAST "all");
			table = xmlNewChild (table, NULL, BAD_CAST "tgroup", NULL);
			xmlSetProp (table, BAD_CAST "cols", BAD_CAST "5");
			xmlSetProp (table, BAD_CAST "colsep", BAD_CAST "1");
			xmlSetProp (table, BAD_CAST "rowsep", BAD_CAST "1");
			xmlSetProp (table, BAD_CAST "align", BAD_CAST "justify");
			
			child = xmlNewChild (table, NULL, BAD_CAST "thead", NULL);
			row = xmlNewChild (child, NULL, BAD_CAST "row", NULL);
			xmlNewChild (row, NULL, BAD_CAST "entry", BAD_CAST "Column name");
			xmlNewChild (row, NULL, BAD_CAST "entry", BAD_CAST "Type");
			xmlNewChild (row, NULL, BAD_CAST "entry", BAD_CAST "Key");
			xmlNewChild (row, NULL, BAD_CAST "entry", BAD_CAST "Can be NULL");
			xmlNewChild (row, NULL, BAD_CAST "entry", BAD_CAST "description");
			table = xmlNewChild (table, NULL, BAD_CAST "tbody", NULL);	
			for (child = node->children; child; child = child->next) {
				if (!strcmp ((gchar *) child->name, "column")) {
					row = xmlNewChild (table, NULL, BAD_CAST "row", NULL);
					
					prop = xmlGetProp (child, BAD_CAST "name");
					xmlNewChild (row, NULL, BAD_CAST "entry", prop ? prop : BAD_CAST "FIXME");
					if (prop) xmlFree (prop);
					
					prop = xmlGetProp (child, BAD_CAST "type");
					xmlNewChild (row, NULL, BAD_CAST "entry", prop ? prop : BAD_CAST "string");
					if (prop) xmlFree (prop);
					
					prop = xmlGetProp (child, BAD_CAST "pkey");
					xmlNewChild (row, NULL, BAD_CAST "entry", 
						     prop && ((*prop == 't') || (*prop == 'T')) ? 
						     BAD_CAST "Yes" : BAD_CAST "");
					if (prop) xmlFree (prop);

					prop = xmlGetProp (child, BAD_CAST "nullok");
					xmlNewChild (row, NULL, BAD_CAST "entry", 
						     prop && ((*prop == 't') || (*prop == 'T')) ? 
						     BAD_CAST "Yes" : BAD_CAST "No");
					if (prop) xmlFree (prop);

					prop = xmlGetProp (child, BAD_CAST "descr");
					xmlNewTextChild (row, NULL, BAD_CAST "entry", prop ? prop : BAD_CAST "");
					if (prop) xmlFree (prop);
				}
				else if (!strcmp ((gchar *) child->name, "fkey")) {
					xmlNodePtr fkey;
					if (!ref) {
						ref = xmlNewChild (snode, NULL, BAD_CAST "para", NULL);
						ref = xmlNewChild (ref, NULL, BAD_CAST "itemizedlist", NULL);
					}
					fkey = xmlNewChild (ref, NULL, BAD_CAST "listitem", NULL);

					prop = xmlGetProp (child, BAD_CAST "ref_table");
					if (prop) {
						gchar *str;
						GString *fk_str = NULL, *ref_pk_str = NULL;
						xmlNodePtr subnode, link;

						fkey = xmlNewChild (fkey, NULL, BAD_CAST "para", NULL);
						
						for (subnode = child->children; subnode; subnode = subnode->next) {
							xmlChar *column, *ref_column;
							if (strcmp ((gchar *) subnode->name, "part")) 
								continue;
							column = xmlGetProp (subnode, BAD_CAST "column");
							if (!column)
								continue;
							if (!fk_str) {
								fk_str = g_string_new ("(");
								ref_pk_str = g_string_new ("(");
							}
							else {
								g_string_append (fk_str, ", ");
								g_string_append (ref_pk_str, ", ");
							}
							g_string_append (fk_str, (gchar *) column);
							ref_column = xmlGetProp (subnode, BAD_CAST "ref_column");
							if (ref_column) {
								g_string_append (ref_pk_str, (gchar *) ref_column);
								xmlFree (ref_column);
							}
							else
								g_string_append (ref_pk_str, (gchar *) column);
							xmlFree (column);
						}
						if (fk_str) {
							g_string_append (fk_str, ") ");
							g_string_append (ref_pk_str, ") ");
						}

						if (fk_str) {
							xmlNodeAddContent (fkey, BAD_CAST fk_str->str);
							g_string_free (fk_str, TRUE);
						}
						xmlNodeAddContent (fkey, BAD_CAST "references ");
						link = xmlNewTextChild (fkey, NULL, BAD_CAST "link", prop);
						str = g_strdup_printf ("is:%s", prop);
						xmlSetProp (link, BAD_CAST "linkend", BAD_CAST str);
						g_free (str);
						if (ref_pk_str) {
							xmlNodeAddContent (fkey, BAD_CAST ref_pk_str->str);
							g_string_free (ref_pk_str, TRUE);
						}
						
						if (prop) xmlFree (prop);
					}
					else
						fkey = xmlNewChild (ref, NULL, BAD_CAST "para", BAD_CAST "FIXME");
				}
			}
			
		}
		else if (!strcmp ((gchar *) node->name, "view")) {
			xmlNodePtr snode, child, para;
			xmlChar *prop;
			snode = xmlNewChild (out_top_node, NULL, BAD_CAST "sect3", NULL);
			prop = xmlGetProp (node, BAD_CAST "name");
			if (prop) {
				gchar *str;
				str = g_strdup_printf ("is:%s", (gchar *) prop);
				xmlSetProp (snode, BAD_CAST "id", BAD_CAST str);
				g_free (str);

				str = g_strdup_printf ("%s view", (gchar *) prop);
				xmlNewTextChild (snode, NULL, BAD_CAST "title", BAD_CAST str);
				g_free (str);
				xmlFree (prop);
			}
			else
				xmlNewChild (snode, NULL, BAD_CAST "title", BAD_CAST "FIXME: view not named");

			prop = xmlGetProp (node, BAD_CAST "descr");
			if (prop) {
				xmlNewTextChild (snode, NULL, BAD_CAST "para", prop);
				xmlFree (prop);
			}
			for (child = node->children; child; child = child->next) {
				if (!strcmp ((gchar *) child->name, "definition")) {
					xmlChar *def;

					def = xmlNodeGetContent (child);
					para = xmlNewChild (snode, NULL, BAD_CAST "para", BAD_CAST "Definition is:");
					para = xmlNewTextChild (para, NULL, BAD_CAST "programlisting", def);
					xmlSetProp (para, BAD_CAST "width", BAD_CAST "80");
					xmlFree (def);
					break;
				}
			}
		}
	}
	xmlFreeDoc (doc);

	buf = xmlBufferCreate();
	xmlNodeDump (buf, NULL, out_top_node, 0, 1);
	if (! g_file_set_contents (OUT_FILE, (gchar*) xmlBufferContent (buf), -1, NULL)) 
		g_print ("Could not write output file '%s'\n", OUT_FILE);
	else
		g_print ("Doc. written to '%s'\n", OUT_FILE);
	xmlBufferFree (buf);
	
	return 0;
}
예제 #14
0
static DiaSvgRenderer *
new_svg_renderer(DiagramData *data, const char *filename)
{
  DiaSvgRenderer *renderer;
  SvgRenderer *svg_renderer;
  FILE *file;
  gchar buf[512];
  time_t time_now;
  Rectangle *extent;
  const char *name;
  xmlDtdPtr dtd;
 
  file = g_fopen(filename, "w");

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

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

  renderer->filename = g_strdup(filename);

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

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

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

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

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

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

  xmlNewChild(renderer->root, NULL, "title", dia->filename);
#endif
  
  return renderer;
}
예제 #15
0
static xmlNodePtr msWFSDumpLayer11(mapObj *map, layerObj *lp, xmlNsPtr psNsOws)
{
    rectObj ext;
   
    xmlNodePtr psRootNode, psNode;
    const char *value    = NULL;
    const char *encoding = NULL;
    char *encoded=NULL;
    char *valueToFree;
    char **tokens;
    int n=0,i=0;      

    encoding = msOWSLookupMetadata(&(map->web.metadata), "FO", "encoding");
    if (!encoding)
      encoding = "ISO-8859-1";

    psRootNode = xmlNewNode(NULL, BAD_CAST "FeatureType");

    /*if there is an encoding using it on some of the items*/
    psNode = msOWSCommonxmlNewChildEncoded(psRootNode, NULL, "Name", lp->name, encoding);


    if (lp->name && strlen(lp->name) > 0 &&
        (msIsXMLTagValid(lp->name) == MS_FALSE || isdigit(lp->name[0])))
      xmlAddSibling(psNode,
                    xmlNewComment(BAD_CAST "WARNING: The layer name '%s' might contain spaces or "
                                  "invalid characters or may start with a number. This could lead to potential problems"));
   
    value = msOWSLookupMetadata(&(lp->metadata), "FO", "title");
    if (!value)
      value =(const char*)lp->name;

    psNode = msOWSCommonxmlNewChildEncoded(psRootNode, NULL, "Title", value, encoding);

 
    value = msOWSLookupMetadata(&(lp->metadata), "FO", "abstract");
    if (value)
      psNode = msOWSCommonxmlNewChildEncoded(psRootNode, NULL, "Abstract", value, encoding);



    value = msOWSLookupMetadata(&(lp->metadata), "FO", "keywordlist");

    if (value)
    {
	if (encoding)
	  encoded = msGetEncodedString(value, encoding);
        else
          encoded = msGetEncodedString(value, "ISO-8859-1");

        msLibXml2GenerateList(
            xmlNewChild(psRootNode, psNsOws, BAD_CAST "Keywords", NULL),
            NULL, "Keyword", encoded, ',' );
	msFree(encoded);
    }
      /*support DefaultSRS and OtherSRS*/
    valueToFree = msOWSGetProjURN(&(map->projection),&(map->web.metadata),"FO",MS_FALSE);
    if (!valueToFree)
      valueToFree = msOWSGetProjURN(&(lp->projection), &(lp->metadata), "FO", MS_FALSE);

    if (valueToFree)
    {
        tokens = msStringSplit(valueToFree, ' ', &n);
        if (tokens && n > 0)
        {
            psNode = xmlNewChild(psRootNode, NULL, BAD_CAST "DefaultSRS", BAD_CAST tokens[0]);
            for (i=1; i<n; i++)
              psNode = xmlNewChild(psRootNode, NULL, BAD_CAST "OtherSRS", BAD_CAST tokens[i]);

            msFreeCharArray(tokens, n);
        }
    }
    else
      xmlAddSibling(psNode,
                    xmlNewComment(BAD_CAST "WARNING: Mandatory mapfile parameter: (at least one of) MAP.PROJECTION, LAYER.PROJECTION or wfs/ows_srs metadata was missing in this context."));

    free(valueToFree);
    valueToFree = NULL;

    /*TODO: adevertize only gml3?*/
    psNode = xmlNewNode(NULL, BAD_CAST "OutputFormats");
    xmlAddChild(psRootNode, psNode);

    {
        char *formats_list = msWFSGetOutputFormatList( map, lp, "1.1.0" );
        int iformat, n;
        char **tokens;

        n = 0;
        tokens = msStringSplit(formats_list, ',', &n);

        for( iformat = 0; iformat < n; iformat++ )
            xmlNewChild(psNode, NULL, BAD_CAST "Format", 
                        BAD_CAST tokens[iformat] );
        msFree( formats_list );
        msFreeCharArray( tokens, n );
    }
  
    /*bbox*/
    if (msOWSGetLayerExtent(map, lp, "FO", &ext) == MS_SUCCESS)
    {   
        /*convert to latlong*/
        if (lp->projection.numargs > 0)
        {
            if (!pj_is_latlong(&lp->projection.proj))
              msProjectRect(&lp->projection, NULL, &ext);
        }
        else if (map->projection.numargs > 0 && !pj_is_latlong(&map->projection.proj))
          msProjectRect(&map->projection, NULL, &ext);

        xmlAddChild(psRootNode,
                    msOWSCommonWGS84BoundingBox( psNsOws, 2,
                                                 ext.minx, ext.miny,
                                                 ext.maxx, ext.maxy));
    }
    else
    {
        xmlNewChild(psRootNode, psNsOws, BAD_CAST "WGS84BoundingBox", NULL);
        xmlAddSibling(psNode,
                      xmlNewComment(BAD_CAST "WARNING: Optional WGS84BoundingBox could not be established for this layer.  Consider setting the EXTENT in the LAYER object, or wfs_extent metadata. Also check that your data exists in the DATA statement"));
    }

    value = msOWSLookupMetadata(&(lp->metadata), "FO", "metadataurl_href");

    if (value)
    {
        psNode = xmlNewChild(psRootNode, NULL, BAD_CAST "MetadataURL", BAD_CAST value);

        value = msOWSLookupMetadata(&(lp->metadata), "FO", "metadataurl_format");

        if (!value)
          value = msStrdup("text/html"); /* default */

        xmlNewProp(psNode, BAD_CAST "format", BAD_CAST value);

        value = msOWSLookupMetadata(&(lp->metadata), "FO", "metadataurl_type");

        if (!value)
          value = msStrdup("FGDC"); /* default */

        xmlNewProp(psNode, BAD_CAST "type", BAD_CAST value);
    }

    return psRootNode;
}
예제 #16
0
void Settings::save()
{
	XOJ_CHECK_TYPE(Settings);

	if (this->timeoutId)
	{
		g_source_remove(this->timeoutId);
		this->timeoutId = 0;
	}

	xmlDocPtr doc;
	xmlNodePtr root;
	xmlNodePtr xmlNode;

	xmlIndentTreeOutput = TRUE;

	doc = xmlNewDoc((const xmlChar*) "1.0");
	if (doc == NULL)
	{
		return;
	}

	saveButtonConfig();

	/* Create metadata root */
	root = xmlNewDocNode(doc, NULL, (const xmlChar*) "settings", NULL);
	xmlDocSetRootElement(doc, root);
	xmlNodePtr com = xmlNewComment((const xmlChar*)
	                               "The Xournal++ settings file. Do not edit this file! "
	                               "The most settings are available in the Settings dialog, "
	                               "the others are commented in this file, but handle with care!");
	xmlAddPrevSibling(root, com);

	WRITE_BOOL_PROP(useXinput);
	WRITE_BOOL_PROP(presureSensitivity);
	WRITE_BOOL_PROP(ignoreCoreEvents);

	WRITE_STRING_PROP(selectedToolbar);
	WRITE_STRING_PROP(lastSavePath);
	WRITE_STRING_PROP(lastImagePath);

	WRITE_INT_PROP(displayDpi);
	WRITE_INT_PROP(mainWndWidth);
	WRITE_INT_PROP(mainWndHeight);
	WRITE_BOOL_PROP(maximized);

	WRITE_BOOL_PROP(showSidebar);
	WRITE_INT_PROP(sidebarWidth);

	WRITE_BOOL_PROP(sidebarOnRight);
	WRITE_BOOL_PROP(scrollbarOnLeft);
	WRITE_BOOL_PROP(showTwoPages);
	WRITE_BOOL_PROP(presentationMode);

	WRITE_STRING_PROP(fullscreenHideElements);
	WRITE_COMMENT("Which gui elements are hidden if you are in Fullscreen mode, separated by a colon (,)");

	WRITE_STRING_PROP(presentationHideElements);
	WRITE_COMMENT("Which gui elements are hidden if you are in Presentation mode, separated by a colon (,)");

	WRITE_BOOL_PROP(showBigCursor);

	if (this->scrollbarHideType == SCROLLBAR_HIDE_BOTH)
	{
		saveProperty((const char*) "scrollbarHideType", "both", root);
	}
	else if (this->scrollbarHideType == SCROLLBAR_HIDE_HORIZONTAL)
	{
		saveProperty((const char*) "scrollbarHideType", "horizontal", root);
	}
	else if (this->scrollbarHideType == SCROLLBAR_HIDE_VERTICAL)
	{
		saveProperty((const char*) "scrollbarHideType", "vertical", root);
	}
	else
	{
		saveProperty((const char*) "scrollbarHideType", "none", root);
	}


	WRITE_BOOL_PROP(autoloadPdfXoj);
	WRITE_COMMENT("Hides scroolbars in the main window, allowed values: \"none\", \"horizontal\", \"vertical\", \"both\"");

	WRITE_STRING_PROP(defaultSaveName);

	WRITE_STRING_PROP(visiblePageFormats);
	WRITE_COMMENT("This paper format is visible in the paper format dialog, separated by a colon");

	WRITE_BOOL_PROP(autosaveEnabled);
	WRITE_INT_PROP(autosaveTimeout);

	WRITE_BOOL_PROP(addHorizontalSpace);
	WRITE_BOOL_PROP(addVerticalSpace);

	WRITE_BOOL_PROP(fixXinput);

	WRITE_BOOL_PROP(enableLeafEnterWorkaround);
	WRITE_COMMENT("If Xournal crashes if you e.g. unplug your mouse set this to true. If you have input problems, you can turn it of with false.");

	String pageInsertType = pageInsertTypeToString(this->pageInsertType);
	WRITE_STRING_PROP(pageInsertType);

	WRITE_INT_PROP(pageBackgroundColor);
	WRITE_INT_PROP(selectionColor);

	WRITE_INT_PROP(pdfPageCacheSize);
	WRITE_COMMENT("The count of rendered PDF pages which will be cached.");

	WRITE_DOUBLE_PROP(widthMinimumMultiplier);
	WRITE_COMMENT("The multiplier for the pressure sensitivity of the pen");
	WRITE_DOUBLE_PROP(widthMaximumMultiplier);
	WRITE_COMMENT("The multiplier for the pressure sensitivity of the pen");

	xmlNodePtr xmlFont;
	xmlFont = xmlNewChild(root, NULL, (const xmlChar*) "property", NULL);
	xmlSetProp(xmlFont, (const xmlChar*) "name", (const xmlChar*) "font");
	xmlSetProp(xmlFont, (const xmlChar*) "font",
	           (const xmlChar*) this->font.getName().c_str());
	gchar* sSize = g_strdup_printf("%0.1lf", this->font.getSize());
	xmlSetProp(xmlFont, (const xmlChar*) "size", (const xmlChar*) sSize);
	g_free(sSize);

	std::map<String, SElement>::iterator it;
	for (it = data.begin(); it != data.end(); it++)
	{
		saveData(root, (*it).first, (*it).second);
	}

	xmlSaveFormatFile(filename.c_str(), doc, 1);
	xmlFreeDoc(doc);
}
예제 #17
0
파일: player.cpp 프로젝트: DuMuT6p/Epiar
/**\brief Save this Player to an xml node
 */
xmlNodePtr Player::ToXMLNode(string componentName) {
	char buff[256];
	char *timestamp;
    xmlNodePtr section = xmlNewNode(NULL, BAD_CAST componentName.c_str());

	// Version information
	snprintf(buff, sizeof(buff), "%d", EPIAR_VERSION_MAJOR);
	xmlNewChild(section, NULL, BAD_CAST "version-major", BAD_CAST buff);
	snprintf(buff, sizeof(buff), "%d", EPIAR_VERSION_MINOR);
	xmlNewChild(section, NULL, BAD_CAST "version-minor", BAD_CAST buff);
	snprintf(buff, sizeof(buff), "%d", EPIAR_VERSION_MICRO);
	xmlNewChild(section, NULL, BAD_CAST "version-macro", BAD_CAST buff);

	// Player Stats
	xmlNewChild(section, NULL, BAD_CAST "name", BAD_CAST GetName().c_str() );

	xmlNodePtr planet = xmlNewNode(NULL, BAD_CAST "planet" );
	xmlNewChild(planet, NULL, BAD_CAST "name", BAD_CAST lastPlanet.c_str()); 
	snprintf(buff, sizeof(buff), "%d", (int)GetWorldPosition().GetX() );
	xmlNewChild(planet, NULL, BAD_CAST "x", BAD_CAST buff );
	snprintf(buff, sizeof(buff), "%d", (int)GetWorldPosition().GetY() );
	xmlNewChild(planet, NULL, BAD_CAST "y", BAD_CAST buff );
	xmlAddChild(section,planet);
	
	xmlNewChild(section, NULL, BAD_CAST "model", BAD_CAST GetModelName().c_str() );
	xmlNewChild(section, NULL, BAD_CAST "engine", BAD_CAST GetEngineName().c_str() );
	snprintf(buff, sizeof(buff), "%d", this->GetCredits() );
	xmlNewChild(section, NULL, BAD_CAST "credits", BAD_CAST buff );

	// this part is becoming less important and may be removed at some point
	for(unsigned int i = 0; i < weaponSlots.size(); i++){
		xmlNewChild(section, NULL, BAD_CAST "weapon", BAD_CAST GetWeaponSlotContent(i).c_str() );
	}

	// Ammo
	for(int a=0;a<max_ammo;a++){
		if(GetAmmo(AmmoType(a)) != 0 ){ // Don't save empty ammo Nodes
			snprintf(buff, sizeof(buff), "%d", GetAmmo(AmmoType(a)) );

			xmlNodePtr ammo = xmlNewNode(NULL, BAD_CAST "ammo");
			xmlNewChild(ammo, NULL, BAD_CAST "type", BAD_CAST Weapon::AmmoTypeToName((AmmoType)a).c_str() );
			xmlNewChild(ammo, NULL, BAD_CAST "amount", BAD_CAST buff );
			xmlAddChild(section, ammo);
		}
	}

	// Weapon Slots
	// save info about whichever items players are able to change in their slot configuration (content and firing group)
	for(unsigned int w=0; w < weaponSlots.size(); w++){
		WeaponSlot *slot = &weaponSlots[w];
		xmlNodePtr slotPtr = xmlNewNode(NULL, BAD_CAST "weapSlot");

		xmlNewChild(slotPtr, NULL, BAD_CAST "name", BAD_CAST GetWeaponSlotName(w).c_str() );
		xmlNewChild(slotPtr, NULL, BAD_CAST "content", BAD_CAST GetWeaponSlotContent(w).c_str() );

		snprintf(buff, sizeof(buff), "%d", slot->firingGroup);
		xmlNewChild(slotPtr, NULL, BAD_CAST "firingGroup", BAD_CAST buff);
		xmlAddChild(section, slotPtr); // saved player data is less structured than model data, so just add it here
	}

	// Cargo
	map<Commodity*,unsigned int> cargo = this->GetCargo();
	map<Commodity*,unsigned int>::iterator iter_com;
	for(iter_com = cargo.begin(); iter_com!=cargo.end(); ++iter_com) {
		if( !(*iter_com).second )
		{
			continue; // Don't Save empty cargo Nodes
		}
		snprintf(buff, sizeof(buff), "%d", (*iter_com).second );
		xmlNodePtr ammo = xmlNewNode(NULL, BAD_CAST "cargo");
		xmlNewChild(ammo, NULL, BAD_CAST "type", BAD_CAST ((*iter_com).first)->GetName().c_str() );
		xmlNewChild(ammo, NULL, BAD_CAST "amount", BAD_CAST buff );
		xmlAddChild(section, ammo);
	}

	// Outfit
	list<Outfit*> *outfits = this->GetOutfits();
	for( list<Outfit*>::iterator it_w = outfits->begin(); it_w!=outfits->end(); ++it_w ){
		xmlNewChild(section, NULL, BAD_CAST "outfit", BAD_CAST (*it_w)->GetName().c_str() );
	}

	// Missions
	list<Mission*>::iterator iter_mission;
	for(iter_mission = missions.begin(); iter_mission != missions.end(); ++iter_mission){
		xmlAddChild( section,  (*iter_mission)->ToXMLNode() );
	}

	// Favor
	map<Alliance*,int>::iterator iter_favor;
	for(iter_favor = favor.begin(); iter_favor!=favor.end(); ++iter_favor) {
		if( !(*iter_favor).second )
		{
			continue; // Don't Save empty favor Nodes
		}
		snprintf(buff, sizeof(buff), "%d", (*iter_favor).second );
		xmlNodePtr ammo = xmlNewNode(NULL, BAD_CAST "favor");
		xmlNewChild(ammo, NULL, BAD_CAST "alliance", BAD_CAST ((*iter_favor).first)->GetName().c_str() );
		xmlNewChild(ammo, NULL, BAD_CAST "value", BAD_CAST buff );
		xmlAddChild(section, ammo);
	}

	// Hired escorts
	for(list<HiredEscort*>::iterator iter_escort = hiredEscorts.begin(); iter_escort != hiredEscorts.end(); iter_escort++){
		// Check that the sprite hasn't already been destroyed. (If it has, leave it out.)
		///\todo We should remove the SpriteManager reference here to remove a dependency on global variables.
		if(
		   (*iter_escort)->spriteID != -1 &&
		   SpriteManager::Instance()->GetSpriteByID(
		      (*iter_escort)->spriteID
		   ) != NULL
		){
			xmlNodePtr hePtr = xmlNewNode(NULL, BAD_CAST "hiredEscort");
			xmlNewChild(hePtr, NULL, BAD_CAST "type", BAD_CAST (*iter_escort)->type.c_str() );
			snprintf(buff, sizeof(buff), "%d", (*iter_escort)->pay);
			xmlNewChild(hePtr, NULL, BAD_CAST "pay", BAD_CAST buff);
			xmlAddChild(section, hePtr);
			// Don't include spriteID in the XML file, for obvious reasons.
		}
	}

	// Last Load Time
	snprintf(buff, sizeof(buff), "%d", (int)lastLoadTime );
	xmlNewChild(section, NULL, BAD_CAST "lastLoadTime", BAD_CAST buff );

	// Save a Human readable comment to explain the Last Load time
	strcpy( buff, "Last Load: " );
	timestamp = ctime( &lastLoadTime );
	timestamp[strlen(timestamp)-1] = '\0';
	xmlAddChild( section, xmlNewComment( BAD_CAST timestamp));

	return section;
}
예제 #18
0
/**
 * Build a new comment node.
 * @param data	Content of the text node.
 */
Comment::Comment(String data): Node(xmlNewComment(data)) {
	ASSERT(node);
}
예제 #19
0
void Settings::saveData(xmlNodePtr root, String name, SElement& elem)
{
	XOJ_CHECK_TYPE(Settings);

	xmlNodePtr xmlNode = xmlNewChild(root, NULL, (const xmlChar*) "data", NULL);

	xmlSetProp(xmlNode, (const xmlChar*) "name", (const xmlChar*) name.c_str());

	std::map<String, SAttribute>::iterator it;
	for (it = elem.attributes().begin(); it != elem.attributes().end(); it++)
	{
		String aname = (*it).first;
		SAttribute& attrib = (*it).second;

		XOJ_CHECK_TYPE_OBJ(&attrib, SAttribute);

		String type;
		String value;

		if (attrib.type == ATTRIBUTE_TYPE_BOOLEAN)
		{
			type = "boolean";

			if (attrib.iValue)
			{
				value = "true";
			}
			else
			{
				value = "false";
			}
		}
		else if (attrib.type == ATTRIBUTE_TYPE_INT)
		{
			type = "int";

			char* tmp = g_strdup_printf("%i", attrib.iValue);
			value = tmp;
			g_free(tmp);
		}
		else if (attrib.type == ATTRIBUTE_TYPE_DOUBLE)
		{
			type = "double";

			char* tmp = g_strdup_printf("%lf", attrib.dValue);
			value = tmp;
			g_free(tmp);
		}
		else if (attrib.type == ATTRIBUTE_TYPE_INT_HEX)
		{
			type = "hex";

			char* tmp = g_strdup_printf("%06x", attrib.iValue);
			value = tmp;
			g_free(tmp);
		}
		else if (attrib.type == ATTRIBUTE_TYPE_STRING)
		{
			type = "string";
			value = attrib.sValue;
		}
		else
		{
			// Unknown type or empty attribute
			continue;
		}

		xmlNodePtr at;
		at = xmlNewChild(xmlNode, NULL, (const xmlChar*) "attribute", NULL);

		xmlSetProp(at, (const xmlChar*) "name", (const xmlChar*) aname.c_str());
		xmlSetProp(at, (const xmlChar*) "type", (const xmlChar*) type.c_str());
		xmlSetProp(at, (const xmlChar*) "value", (const xmlChar*) value.c_str());

		if (!attrib.comment.isEmpty())
		{
			xmlNodePtr com = xmlNewComment((const xmlChar*) attrib.comment.c_str());
			xmlAddPrevSibling(xmlNode, com);
		}
	}

	std::map<String, SElement>::iterator i;
	for (i = elem.children().begin(); i != elem.children().end(); i++)
	{
		saveData(xmlNode, (*i).first, (*i).second);
	}
}
예제 #20
0
int yaz_marc_write_xml(yaz_marc_t mt, xmlNode **root_ptr,
                       const char *ns,
                       const char *format,
                       const char *type)
{
    struct yaz_marc_node *n;
    int identifier_length;
    const char *leader = 0;
    xmlNode *record_ptr;
    xmlNsPtr ns_record;
    WRBUF wr_cdata = 0;

    for (n = mt->nodes; n; n = n->next)
        if (n->which == YAZ_MARC_LEADER)
        {
            leader = n->u.leader;
            break;
        }

    if (!leader)
        return -1;
    if (!atoi_n_check(leader+11, 1, &identifier_length))
        return -1;

    wr_cdata = wrbuf_alloc();

    record_ptr = xmlNewNode(0, BAD_CAST "record");
    *root_ptr = record_ptr;

    ns_record = xmlNewNs(record_ptr, BAD_CAST ns, 0);
    xmlSetNs(record_ptr, ns_record);

    if (format)
        xmlNewProp(record_ptr, BAD_CAST "format", BAD_CAST format);
    if (type)
        xmlNewProp(record_ptr, BAD_CAST "type", BAD_CAST type);
    for (n = mt->nodes; n; n = n->next)
    {
        struct yaz_marc_subfield *s;
        xmlNode *ptr;

        switch(n->which)
        {
        case YAZ_MARC_DATAFIELD:
            ptr = xmlNewChild(record_ptr, ns_record, BAD_CAST "datafield", 0);
            xmlNewProp(ptr, BAD_CAST "tag", BAD_CAST n->u.datafield.tag);
            if (n->u.datafield.indicator)
            {
                int i;
                for (i = 0; n->u.datafield.indicator[i]; i++)
                {
                    char ind_str[6];
                    char ind_val[2];

                    sprintf(ind_str, "ind%d", i+1);
                    ind_val[0] = n->u.datafield.indicator[i];
                    ind_val[1] = '\0';
                    xmlNewProp(ptr, BAD_CAST ind_str, BAD_CAST ind_val);
                }
            }
            for (s = n->u.datafield.subfields; s; s = s->next)
            {
                xmlNode *ptr_subfield;
                size_t using_code_len = get_subfield_len(mt, s->code_data,
                                                         identifier_length);
                wrbuf_rewind(wr_cdata);
                wrbuf_iconv_puts(wr_cdata, mt->iconv_cd,
                                 s->code_data + using_code_len);
                marc_iconv_reset(mt, wr_cdata);
                ptr_subfield = xmlNewTextChild(
                    ptr, ns_record,
                    BAD_CAST "subfield",  BAD_CAST wrbuf_cstr(wr_cdata));

                wrbuf_rewind(wr_cdata);
                wrbuf_iconv_write(wr_cdata, mt->iconv_cd,
                                  s->code_data, using_code_len);
                xmlNewProp(ptr_subfield, BAD_CAST "code",
                           BAD_CAST wrbuf_cstr(wr_cdata));
            }
            break;
        case YAZ_MARC_CONTROLFIELD:
            wrbuf_rewind(wr_cdata);
            wrbuf_iconv_puts(wr_cdata, mt->iconv_cd, n->u.controlfield.data);
            marc_iconv_reset(mt, wr_cdata);

            ptr = xmlNewTextChild(record_ptr, ns_record,
                                  BAD_CAST "controlfield",
                                  BAD_CAST wrbuf_cstr(wr_cdata));

            xmlNewProp(ptr, BAD_CAST "tag", BAD_CAST n->u.controlfield.tag);
            break;
        case YAZ_MARC_COMMENT:
            ptr = xmlNewComment(BAD_CAST n->u.comment);
            xmlAddChild(record_ptr, ptr);
            break;
        case YAZ_MARC_LEADER:
            xmlNewTextChild(record_ptr, ns_record, BAD_CAST "leader",
                            BAD_CAST n->u.leader);
            break;
        }
    }
    wrbuf_destroy(wr_cdata);
    return 0;
}
예제 #21
0
xmlNodePtr msOWSCommonServiceProvider(xmlNsPtr psNsOws, xmlNsPtr psNsXLink,
                                      mapObj *map, const char *namespaces)
{
  const char *value = NULL;

  xmlNodePtr   psNode          = NULL;
  xmlNodePtr   psRootNode      = NULL;
  xmlNodePtr   psSubNode       = NULL;
  xmlNodePtr   psSubSubNode    = NULL;
  xmlNodePtr   psSubSubSubNode = NULL;

  if (_validateNamespace(psNsOws) == MS_FAILURE)
    psNsOws = xmlNewNs(psRootNode, BAD_CAST MS_OWSCOMMON_OWS_NAMESPACE_URI, BAD_CAST MS_OWSCOMMON_OWS_NAMESPACE_PREFIX);

  psRootNode = xmlNewNode(psNsOws, BAD_CAST "ServiceProvider");

  /* add child elements */

  value = msOWSLookupMetadata(&(map->web.metadata), namespaces, "contactorganization");

  psNode = xmlNewChild(psRootNode, psNsOws, BAD_CAST "ProviderName", BAD_CAST value);

  if (!value) {
    xmlAddSibling(psNode, xmlNewComment(BAD_CAST "WARNING: Mandatory metadata \"ows_contactorganization\" was missing for ows:ProviderName"));
  }

  psNode = xmlNewChild(psRootNode, psNsOws, BAD_CAST "ProviderSite", NULL);

  xmlNewNsProp(psNode, psNsXLink, BAD_CAST "type", BAD_CAST "simple");

  value = msOWSLookupMetadata(&(map->web.metadata), namespaces, "service_onlineresource");

  xmlNewNsProp(psNode, psNsXLink, BAD_CAST "href", BAD_CAST value);

  if (!value) {
    xmlAddSibling(psNode, xmlNewComment(BAD_CAST "WARNING: Optional metadata \"ows_service_onlineresource\" was missing for ows:ProviderSite/@xlink:href"));
  }

  psNode = xmlNewChild(psRootNode, psNsOws, BAD_CAST "ServiceContact", NULL);

  value = msOWSLookupMetadata(&(map->web.metadata), namespaces, "contactperson");

  psSubNode = xmlNewChild(psNode, psNsOws, BAD_CAST "IndividualName", BAD_CAST  value);

  if (!value) {
    xmlAddSibling(psSubNode, xmlNewComment(BAD_CAST "WARNING: Optional metadata \"ows_contactperson\" was missing for ows:IndividualName"));
  }

  value = msOWSLookupMetadata(&(map->web.metadata), namespaces, "contactposition");

  psSubNode = xmlNewChild(psNode, psNsOws, BAD_CAST "PositionName", BAD_CAST value);

  if (!value) {
    xmlAddSibling(psSubNode, xmlNewComment(BAD_CAST "WARNING: Optional metadata \"ows_contactposition\" was missing for ows:PositionName"));
  }

  psSubNode = xmlNewChild(psNode, psNsOws, BAD_CAST "ContactInfo", NULL);

  psSubSubNode = xmlNewChild(psSubNode, psNsOws, BAD_CAST "Phone", NULL);

  value = msOWSLookupMetadata(&(map->web.metadata), namespaces, "contactvoicetelephone");

  psSubSubSubNode = xmlNewChild(psSubSubNode, psNsOws, BAD_CAST "Voice", BAD_CAST value);

  if (!value) {
    xmlAddSibling(psSubSubSubNode, xmlNewComment(BAD_CAST "WARNING: Optional metadata \"ows_contactvoicetelephone\" was missing for ows:Voice"));
  }

  value = msOWSLookupMetadata(&(map->web.metadata), namespaces, "contactfacsimiletelephone");

  psSubSubSubNode = xmlNewChild(psSubSubNode, psNsOws, BAD_CAST "Facsimile", BAD_CAST value);

  if (!value) {
    xmlAddSibling(psSubSubSubNode, xmlNewComment(BAD_CAST "WARNING: Optional metadata \"ows_contactfacsimiletelephone\" was missing for ows:Facsimile"));
  }

  psSubSubNode = xmlNewChild(psSubNode, psNsOws, BAD_CAST "Address", NULL);

  value = msOWSLookupMetadata(&(map->web.metadata), namespaces, "address");

  psSubSubSubNode = xmlNewChild(psSubSubNode, psNsOws, BAD_CAST "DeliveryPoint", BAD_CAST value);

  if (!value) {
    xmlAddSibling(psSubSubSubNode, xmlNewComment(BAD_CAST "WARNING: Optional metadata \"ows_address\" was missing for ows:DeliveryPoint"));
  }

  value = msOWSLookupMetadata(&(map->web.metadata), namespaces, "city");

  psSubSubSubNode = xmlNewChild(psSubSubNode, psNsOws, BAD_CAST "City", BAD_CAST value);

  if (!value) {
    xmlAddSibling(psSubSubSubNode, xmlNewComment(BAD_CAST "WARNING: Optional metadata \"ows_city\" was missing for ows:City"));
  }

  value = msOWSLookupMetadata(&(map->web.metadata), namespaces, "stateorprovince");

  psSubSubSubNode = xmlNewChild(psSubSubNode, psNsOws, BAD_CAST "AdministrativeArea", BAD_CAST value);

  if (!value) {
    xmlAddSibling(psSubSubSubNode, xmlNewComment(BAD_CAST "WARNING: Optional metadata \"ows_stateorprovince\" was missing for ows:AdministrativeArea"));
  }

  value = msOWSLookupMetadata(&(map->web.metadata), namespaces, "postcode");

  psSubSubSubNode = xmlNewChild(psSubSubNode, psNsOws, BAD_CAST "PostalCode", BAD_CAST value);

  if (!value) {
    xmlAddSibling(psSubSubSubNode, xmlNewComment(BAD_CAST "WARNING: Optional metadata \"ows_postcode\" was missing for ows:PostalCode"));
  }

  value = msOWSLookupMetadata(&(map->web.metadata), namespaces, "country");

  psSubSubSubNode = xmlNewChild(psSubSubNode, psNsOws, BAD_CAST "Country", BAD_CAST value);

  if (!value) {
    xmlAddSibling(psSubSubSubNode, xmlNewComment(BAD_CAST "WARNING: Optional metadata \"ows_country\" was missing for ows:Country"));
  }

  value = msOWSLookupMetadata(&(map->web.metadata), namespaces, "contactelectronicmailaddress");

  psSubSubSubNode = xmlNewChild(psSubSubNode, psNsOws, BAD_CAST "ElectronicMailAddress", BAD_CAST value);

  if (!value) {
    xmlAddSibling(psSubSubSubNode, xmlNewComment(BAD_CAST "WARNING: Optional metadata \"ows_contactelectronicmailaddress\" was missing for ows:ElectronicMailAddress"));
  }

  psSubSubNode = xmlNewChild(psSubNode, psNsOws, BAD_CAST "OnlineResource", NULL);

  xmlNewNsProp(psSubSubNode, psNsXLink, BAD_CAST "type", BAD_CAST "simple");

  value = msOWSLookupMetadata(&(map->web.metadata), namespaces, "service_onlineresource");

  xmlNewNsProp(psSubSubNode, psNsXLink, BAD_CAST "href", BAD_CAST value);

  if (!value) {
    xmlAddSibling(psSubSubNode, xmlNewComment(BAD_CAST "WARNING: Optional metadata \"ows_service_onlineresource\" was missing for ows:OnlineResource/@xlink:href"));
  }

  value = msOWSLookupMetadata(&(map->web.metadata), namespaces, "hoursofservice");

  psSubSubNode = xmlNewChild(psSubNode, psNsOws, BAD_CAST "HoursOfService", BAD_CAST value);

  if (!value) {
    xmlAddSibling(psSubSubNode, xmlNewComment(BAD_CAST "WARNING: Optional metadata \"ows_hoursofservice\" was missing for ows:HoursOfService"));
  }

  value = msOWSLookupMetadata(&(map->web.metadata), namespaces, "contactinstructions");

  psSubSubNode = xmlNewChild(psSubNode, psNsOws, BAD_CAST "ContactInstructions", BAD_CAST value);

  if (!value) {
    xmlAddSibling(psSubSubNode, xmlNewComment(BAD_CAST "WARNING: Optional metadata \"ows_contactinstructions\" was missing for ows:ContactInstructions"));
  }

  value = msOWSLookupMetadata(&(map->web.metadata), namespaces, "role");

  psSubNode = xmlNewChild(psNode, psNsOws, BAD_CAST "Role", BAD_CAST value);

  if (!value) {
    xmlAddSibling(psSubNode, xmlNewComment(BAD_CAST "WARNING: Optional metadata \"ows_role\" was missing for ows:Role"));
  }

  return psRootNode;

}
예제 #22
0
파일: xupl.c 프로젝트: xupl/xupl
xupl* xupl_parse(xupl *xup) {

	xupl_*_ = (xupl_*) xup;
	FILE* in = _->in;
	off_t buffsize = _->buffsize;

	unsigned short bit = 0x0001;
	unsigned short WHITESPACE = bit;

	unsigned short DOUBLE_STRING = (bit <<= 1);
	unsigned short SINGLE_STRING = (bit <<= 1);
	unsigned short STRING = DOUBLE_STRING | SINGLE_STRING;

	unsigned short LINE_COMMENT = (bit <<= 1);
	unsigned short MULTI_COMMENT = (bit <<= 1);
	unsigned short COMMENT = LINE_COMMENT | MULTI_COMMENT;

	unsigned short _state = 0;

	const int default_tksize = 12;
	int tksize = default_tksize + 1;

	unsigned char *tk = NULL;
	int tkndx = 0;

	int chars_read;
	char* buf = malloc(buffsize + 1);

	xmlNodePtr xroot = NULL;
	xmlNodePtr xc = NULL;
	xmlAttrPtr xprop = NULL;

	const xmlChar* xuplAttr = (const xmlChar*) "data-xupl";
	const xmlChar* xuplClosed = (const xmlChar*) "closed";

	xmlDocPtr xdoc = xmlNewDoc((const unsigned char*) "1.1");
	//xmlNsPtr xuplNs = xmlNewGlobalNs(xdoc,"http://ns.xupl.org/1.1","xupl");

	while ((chars_read = fread(buf, 1, buffsize, in)) > 0) {

		for (int i = 0; i < chars_read; i++) {
			const char c = buf[i];

			switch (c) {

				case '\'':
				case '"':
					IF(COMMENT) break;

					IF(STR(c)) {
						DISABLE(STR(c));
					} else if (NOT(STRING)) {
						ALLOW(STR(c));
						break;
					}

				case '{':
				case '}':
				case ' ':
				case '\n':
				case '\r':
				case '\t':
				case '\f':
				case '\v':
				case ',':
				case '=':
				// Comment characters
				case '*':
				case '/':
				case '#':
				case '!':
					IF(STRING) break;

					switch (c) {
						case ',':
						case '{':
							xprop = NULL;
					}

					if (tk) {
						tk[tkndx] = 0;

						char p = 0;
						if (tkndx >= 1) p = tk[tkndx - 1];
						unsigned char* m = NULL;

						unsigned int tklen = tkndx + 1;
						unsigned char* t = tk;

						IF(COMMENT) {
							if ('\n' == c && IS(LINE_COMMENT)) {
								if (tkndx + 1 < tksize) {
									tk[tkndx++] = ' ';
									tk[tkndx] = 0;
								}
							} else if ('*' == p && '/' == c && IS(MULTI_COMMENT)) {
								tk[tkndx - 1] = 0;
							} else break;
							DISABLE(COMMENT);
							m = tk + 2;
						} else if ('/' == p && '*' == c) {
							ALLOW(MULTI_COMMENT);
							break;
						// Single-line comments can be #! #* #/ ##
						} else if ('#' == p && ('!' == c || '*' == c || '/' == c || '#' == c)) {
							ALLOW(LINE_COMMENT);
							break;
						// If these characters were in the token and not part of a comment,
						// then continue as if they are normal characters of a token.
						} else if ('!' == c || '/' == c || '*' == c || '#' == c) break;

						if (!xc) {
							if (m) {
								xroot = xmlNewDocComment(xdoc, m);
								xmlDocSetRootElement(xdoc, xroot);
							} else {
								xc = xmlNewNode(NULL, tk);
								xmlDocSetRootElement(xdoc, xc);
								if (!xroot) xroot = xc;
							}
						} else if (m) {
							xmlAddChild(xc, xmlNewComment(m));
						} else {
							char *attr = NULL;
							xmlAttrPtr closed = xmlHasProp(xc, xuplAttr);

							switch (tk[0]) {
								case '\'':
								case '"':
									t += 1;
									xmlAddChild(xc, xmlNewText(t));
									break;
									// TODO make this parameterized, characters and names.
								case '.': attr = "class";    break;
								case '#': attr = "id";       break;
								case '@': attr = "project";  break;
								case '/': attr = "href";     break;
								case '[': attr = "data";     break;
								case '~': attr = "duration"; break;
								case '=': attr = "location"; break;
								case '^': attr = "at";       break;
								case ':': attr = "type";     break;
								case '!': attr = "priority"; break;
								default:
								{
									regmatch_t pmatch[1];
									unsigned int isword = 0 == regexec(&re_word, (char*) tk, 1, pmatch, 0);
									if (closed) {
										if (isword) {
											xc = xmlNewChild(xc, NULL, tk, NULL);
										} else {
											xmlAddChild(xc, xmlNewText(tk));
										}
									} else {
										if (xprop) {
											xmlNewProp(xc, xprop->name, tk);
											xmlRemoveProp(xprop);
											xprop = NULL;
										} else if (isword) {
											xprop = xmlNewProp(xc, tk, (unsigned char*) "True");
										} else {
											xprop = xmlNewProp(xc, (unsigned char*) ".fake", tk);
										}
										switch (c) {
											case ',':
											case '{':
												xprop = NULL;
										}
									}
								}
									break;
							}

							if (attr) {
								if (closed) {
									xmlAddChild(xc, xmlNewText(t));
								} else {
									xmlNewProp(xc, (xmlChar*) attr, t);
								}
							}
						}

						free(tk);
						tk = NULL;
						if (tksize > default_tksize && tkndx < default_tksize) {
							tksize /= 2;
						}
						tkndx = 0;

						if (m) continue;
					}

				default:
					break;
			}

			switch (c) {
				case '{':
					xmlNewProp(xc, xuplAttr, xuplClosed);
					continue;
				case '}':
					if (xc) {
						xmlAttrPtr data = xmlHasProp(xc, xuplAttr);
						if (data) xmlRemoveProp(data);
						xc = xc->parent;
					}
					continue;
				default:
					break;
			}

			// Accumulate the tk.
			if (!tk || tkndx >= tksize) {
				// If the tk buffer is too small, double it.
				tk = realloc(tk, tksize *= 2);
			}
			tk[tkndx++] = c;
		}
예제 #23
0
xmlNodePtr msOWSCommonServiceIdentification(xmlNsPtr psNsOws, mapObj *map, const char *servicetype, const char *version, const char *namespaces)
{
  const char *value    = NULL;

  xmlNodePtr   psRootNode = NULL;
  xmlNodePtr   psNode     = NULL;

  if (_validateNamespace(psNsOws) == MS_FAILURE)
    psNsOws = xmlNewNs(psRootNode, BAD_CAST MS_OWSCOMMON_OWS_NAMESPACE_URI, BAD_CAST MS_OWSCOMMON_OWS_NAMESPACE_PREFIX);

  /* create element name */
  psRootNode = xmlNewNode(psNsOws, BAD_CAST "ServiceIdentification");

  /* add child elements */

  value = msOWSLookupMetadata(&(map->web.metadata), namespaces, "title");

  psNode = xmlNewChild(psRootNode, psNsOws, BAD_CAST "Title", BAD_CAST value);

  if (!value) {
    xmlAddSibling(psNode, xmlNewComment(BAD_CAST "WARNING: Optional metadata \"ows_title\" missing for ows:Title"));
  }

  value = msOWSLookupMetadata(&(map->web.metadata), namespaces, "abstract");

  psNode = xmlNewChild(psRootNode, psNsOws, BAD_CAST "Abstract", BAD_CAST value);

  if (!value) {
    xmlAddSibling(psNode, xmlNewComment(BAD_CAST "WARNING: Optional metadata \"ows_abstract\" was missing for ows:Abstract"));
  }

  value = msOWSLookupMetadata(&(map->web.metadata), namespaces, "keywordlist");

  if (value) {
    psNode = xmlNewChild(psRootNode, psNsOws, BAD_CAST "Keywords", NULL);
    msLibXml2GenerateList(psNode, psNsOws, "Keyword", value, ',');
  }

  else {
    xmlAddSibling(psNode, xmlNewComment(BAD_CAST "WARNING: Optional metadata \"ows_keywordlist\" was missing for ows:KeywordList"));
  }

  psNode = xmlNewChild(psRootNode, psNsOws, BAD_CAST "ServiceType", BAD_CAST servicetype);

  xmlNewProp(psNode, BAD_CAST "codeSpace", BAD_CAST MS_OWSCOMMON_OGC_CODESPACE);

  psNode = xmlNewChild(psRootNode, psNsOws, BAD_CAST "ServiceTypeVersion", BAD_CAST version);

  value = msOWSLookupMetadata(&(map->web.metadata), namespaces, "fees");

  psNode = xmlNewChild(psRootNode, psNsOws, BAD_CAST "Fees", BAD_CAST value);

  if (!value) {
    xmlAddSibling(psNode, xmlNewComment(BAD_CAST "WARNING: Optional metadata \"ows_fees\" was missing for ows:Fees"));
  }

  value = msOWSLookupMetadata(&(map->web.metadata), namespaces, "accessconstraints");

  psNode = xmlNewChild(psRootNode, psNsOws, BAD_CAST "AccessConstraints", BAD_CAST value);

  if (!value) {
    xmlAddSibling(psNode, xmlNewComment(BAD_CAST "WARNING: Optional metadata \"ows_accessconstraints\" was missing for ows:AccessConstraints"));
  }

  return psRootNode;
}
예제 #24
0
static int yaz_marc_write_xml_turbo_xml(yaz_marc_t mt, xmlNode **root_ptr,
                                        const char *ns,
                                        const char *format,
                                        const char *type)
{
    struct yaz_marc_node *n;
    int identifier_length;
    const char *leader = 0;
    xmlNode *record_ptr;
    xmlNsPtr ns_record;
    WRBUF wr_cdata = 0;

    for (n = mt->nodes; n; n = n->next)
        if (n->which == YAZ_MARC_LEADER)
        {
            leader = n->u.leader;
            break;
        }

    if (!leader)
        return -1;
    if (!atoi_n_check(leader+11, 1, &identifier_length))
        return -1;

    wr_cdata = wrbuf_alloc();

    record_ptr = xmlNewNode(0, BAD_CAST "r");
    *root_ptr = record_ptr;

    ns_record = xmlNewNs(record_ptr, BAD_CAST ns, 0);
    xmlSetNs(record_ptr, ns_record);

    if (format)
        xmlNewProp(record_ptr, BAD_CAST "format", BAD_CAST format);
    if (type)
        xmlNewProp(record_ptr, BAD_CAST "type", BAD_CAST type);
    for (n = mt->nodes; n; n = n->next)
    {
        xmlNode *ptr;

        char field[10];
        field[0] = 'c';
        field[4] = '\0';

        switch(n->which)
        {
        case YAZ_MARC_DATAFIELD:
            add_marc_datafield_turbo_xml(mt, n, record_ptr, ns_record, wr_cdata, identifier_length);
            break;
        case YAZ_MARC_CONTROLFIELD:
            wrbuf_rewind(wr_cdata);
            wrbuf_iconv_puts(wr_cdata, mt->iconv_cd, n->u.controlfield.data);
            marc_iconv_reset(mt, wr_cdata);

            strncpy(field + 1, n->u.controlfield.tag, 3);
            ptr = xmlNewTextChild(record_ptr, ns_record,
                                  BAD_CAST field,
                                  BAD_CAST wrbuf_cstr(wr_cdata));
            break;
        case YAZ_MARC_COMMENT:
            ptr = xmlNewComment(BAD_CAST n->u.comment);
            xmlAddChild(record_ptr, ptr);
            break;
        case YAZ_MARC_LEADER:
            xmlNewTextChild(record_ptr, ns_record, BAD_CAST "l",
                            BAD_CAST n->u.leader);
            break;
        }
    }
    wrbuf_destroy(wr_cdata);
    return 0;
}
예제 #25
0
int main(int argc, const char **argv) 
{
	struct ptbf *ret;
	int debugging = 0;
	xmlNodePtr root_node;
	xmlDocPtr doc;
	xmlNodePtr comment;
	xmlNodePtr fonts;
	xmlDtdPtr dtd;
	int c, i, musicxml = 0;
	int version = 0;
	const char *input = NULL;
	char *output = NULL;
	poptContext pc;
	int quiet = 0;
	int format_output = 1;
	struct poptOption options[] = {
		POPT_AUTOHELP
		{"debug", 'd', POPT_ARG_NONE, &debugging, 0, "Turn on debugging output" },
		{"outputfile", 'o', POPT_ARG_STRING, &output, 0, "Write to specified file", "FILE" },
		{"musicxml", 'm', POPT_ARG_NONE, &musicxml, 'm', "Output MusicXML" },
		{"no-format", 'f', POPT_ARG_NONE, &format_output, 0, "Don't format output" },
		{"quiet", 'q', POPT_ARG_NONE, &quiet, 1, "Be quiet (no output to stderr)" },
		{"version", 'v', POPT_ARG_NONE, &version, 'v', "Show version information" },
		POPT_TABLEEND
	};

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

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

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

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

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

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

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

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

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

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

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

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

	xmlFreeDoc(doc);

	xmlCleanupParser();

	return 0;
}