Example #1
0
int main(int argc, char * argv[])
{
  genxWriter w = genxNew(NULL, NULL, NULL);
  genxNamespace ns1, ns2;
  
  genxStartDocFile(w, stdout);
  genxStartElementLiteral(w, WIDE("http://example.org/1"), WIDE("greeting"));
  genxAddAttributeLiteral(w, WIDE("http://example.com/zot"), WIDE("type"), WIDE("well-formed"));
  genxAddText(w, WIDE("\nHello world!"));
  genxEndElement(w);
  genxEndDocument(w);
}
Example #2
0
int main(int argc, char * argv[])
{
  genxWriter w = genxNew(NULL, NULL, NULL);
  genxElement dates, date;
  genxAttribute yyyy, mm;
  genxNamespace ns;
  genxStatus status;
  int i;
  char year[100], month[100];

  if (!(ns = genxDeclareNamespace(w, "http://example.org/dd", "dd", &status)))
    oops(w);
  if (!(dates = genxDeclareElement(w, ns, "dates", &status)))
    oops(w);
  if (!(date = genxDeclareElement(w, NULL, "date", &status)))
    oops(w);
  if (!(yyyy = genxDeclareAttribute(w, NULL, "yyyy", &status)))
    oops(w);
  if (!(mm = genxDeclareAttribute(w, NULL, "mm", &status)))
    oops(w);

  if (genxStartDocFile(w, stdout) ||
      genxStartElement(dates) ||
      genxAddText(w, "\n"))
    oops(w);
  for (i = 0; i < 1000000; i++)
  {
    sprintf(year, "%d", 1900 + (random() % 100));
    sprintf(month, "%02d", 1 + (random() % 12));
    if (genxStartElement(date) ||
	genxAddAttribute(yyyy, year) ||
	genxAddAttribute(mm, month) ||
	genxEndElement(w) ||
	genxAddText(w, "\n "))
      oops(w);
  }
  if (genxEndElement(w))
    oops(w);
  if (genxEndDocument(w))
    oops(w);
}
Example #3
0
static void WriteXML( void )
{
	TEXTCHAR tmpname[256];
	FILE *file;
	if( !ffl.writer.w )
		InitGenX();

	snprintf( tmpname, 256, "%s/Crack the Code Game State.xml", ffl.path );
	file = fopen( tmpname, "wt" );
	genxStartDocFile( ffl.writer.w, file );
	genxPI( ffl.writer.w, "xml", "version=\"1.0\" encoding=\"utf-8\"" );
	//genxAddText(ffl.writer.w, (constUtf8)"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" );

	genxStartElement( ffl.writer.game );
	genxAddText(ffl.writer.w, (constUtf8)"\n  ");
	genxStartElement( ffl.writer.prizeGroups );
	genxAddText(ffl.writer.w, (constUtf8)"\n    ");
	genxStartElement( ffl.writer.prizeGroup );
	genxAddText(ffl.writer.w, (constUtf8)"\n      ");
	genxStartElement( ffl.writer.prizes );
	{
		INDEX idx;
		struct loaded_prize *prize;
		LIST_FORALL( ffl.loaded_prizes, idx, struct loaded_prize *, prize )
		{
			genxAddText(ffl.writer.w, (constUtf8)"\n        ");
			genxStartElement( ffl.writer.prize );
			genxAddText(ffl.writer.w, (constUtf8)"\n          ");
			genxStartElement( ffl.writer.remaining );
			genxAddText(ffl.writer.w, (constUtf8)prize->remaining);
			genxEndElement( ffl.writer.w );
			genxAddText(ffl.writer.w, (constUtf8)"\n          ");
			genxStartElement( ffl.writer.value );
			genxAddText(ffl.writer.w, (constUtf8)prize->value);
			genxEndElement( ffl.writer.w );
			genxAddText(ffl.writer.w, (constUtf8)"\n          ");

			genxStartElement( ffl.writer.desc );
			//genxAddText(ffl.writer.w, (constUtf8));
			genxEndElement( ffl.writer.w );
			genxAddText(ffl.writer.w, (constUtf8)"\n        ");
			genxEndElement( ffl.writer.w );
			Release( prize->remaining );
			Release( prize->value );
			if( prize->desc )
				Release( prize->desc );
			Release( prize );
		}
		DeleteList( &ffl.loaded_prizes );
	}
	genxAddText(ffl.writer.w, (constUtf8)"\n      ");
	genxEndElement( ffl.writer.w );
	genxAddText(ffl.writer.w, (constUtf8)"\n    ");
	genxEndElement( ffl.writer.w );
	genxAddText(ffl.writer.w, (constUtf8)"\n  ");
	genxEndElement( ffl.writer.w );
	genxAddText(ffl.writer.w, (constUtf8)"\n  ");

	genxStartElement( ffl.writer.extraPrizes );
	genxAddText(ffl.writer.w, (constUtf8)"0");
	genxEndElement( ffl.writer.w );
	genxAddText(ffl.writer.w, (constUtf8)"\n  ");

	genxStartElement( ffl.writer.playerLog );

	{
		INDEX idx;
		LOGICAL big_prize_claimed = FALSE;
		struct loaded_player *player;
		LIST_FORALL( ffl.xml_players, idx, struct loaded_player *, player )
		{
			if( !player->timestamp
				|| big_prize_claimed 
				|| StrCmp( player->prizeNum, "1000000" ) != 0 )
			{
				Release( player->cardNum );
				Release( player->playerName );
				Release( player->prizeDesc );
				Release( player->prizeNum );
				Release( player->timestamp );
				Release( player );
				continue;
			}
			big_prize_claimed = TRUE;
			genxAddText(ffl.writer.w, (constUtf8)"\n    ");

			genxStartElement( ffl.writer.player );
			genxAddText(ffl.writer.w, (constUtf8)"\n      ");

			genxStartElement( ffl.writer.timestamp );
			genxAddText(ffl.writer.w, (constUtf8)player->timestamp);
			genxEndElement( ffl.writer.w );
			genxAddText(ffl.writer.w, (constUtf8)"\n      ");

			genxStartElement( ffl.writer.cardNum );
			genxAddText(ffl.writer.w, (constUtf8)player->cardNum);
			genxEndElement( ffl.writer.w );
			genxAddText(ffl.writer.w, (constUtf8)"\n      ");

			genxStartElement( ffl.writer.playerName );
			genxAddText(ffl.writer.w, (constUtf8)player->playerName);
			genxEndElement( ffl.writer.w );
			genxAddText(ffl.writer.w, (constUtf8)"\n      ");

			genxStartElement( ffl.writer.prizeNum );
			genxAddText(ffl.writer.w, (constUtf8)player->prizeNum);
			genxEndElement( ffl.writer.w );
			genxAddText(ffl.writer.w, (constUtf8)"\n      ");

			genxStartElement( ffl.writer.prizeDesc );
			genxAddText(ffl.writer.w, (constUtf8)player->prizeDesc);
			genxEndElement( ffl.writer.w );
			genxAddText(ffl.writer.w, (constUtf8)"\n    ");

			genxEndElement( ffl.writer.w );
			Release( player->cardNum );
			Release( player->playerName );
			Release( player->prizeDesc );
			Release( player->prizeNum );
			Release( player->timestamp );
			Release( player );
		}
		DeleteList( &ffl.xml_players );
	}
	genxAddText(ffl.writer.w, (constUtf8)"\n  ");
	genxEndElement( ffl.writer.w );
	genxAddText(ffl.writer.w, (constUtf8)"\n");
	genxEndElement( ffl.writer.w );

	genxEndDocument( ffl.writer.w );

	fclose( file );
}