#include <irrlicht.h>
//los namespace para definir funciones de irrlicht
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#endif
int main()
{
//define un device para la pantalla
IrrlichtDevice *device = createDevice(EDT_NULL, dimension2d<u32>(0, 0), 16, false);
//en caso de error
if (!device)
return 1;
//Para ponerle un titulo a la ventana
device->setWindowCaption(L"Escribiendo datos a un archivo XML en Irrlicht");
//Creamos el archivo
IFileSystem *fileSystem = device->getFileSystem();
//Creo objeto Writer para escribir en el archivo xml
IXMLWriter *xml = fileSystem->createXMLWriter("guardar.xml");
//Declaro mis cadenas para enviar a mi xml
stringw nombreJugador = "depredador1220";
stringw nivel = "100";
stringw salud = "50";
stringw exp = "30";
stringw mensaje = "Apoya al sitio dandole clic a la publicidad";
// se escribira la cabecera con esta funcion <?xml version="1.0"?>
xml->writeXMLHeader();
//Escribimos el elemento del jugador que a su vez contendra el nombre
xml->writeElement(L"jugador", false, L"nombre", nombreJugador.c_str());
xml->writeLineBreak();
//Ahora escribimos los siguientes elementos
//Nivel
xml->writeElement(L"nivel");
xml->writeText(nivel.c_str());
xml->writeClosingTag(L"nivel");
xml->writeLineBreak();
//Salud
xml->writeElement(L"salud");
xml->writeText(salud.c_str());
xml->writeClosingTag(L"salud");
xml->writeLineBreak();
//Exp
xml->writeElement(L"exp");
xml->writeText(exp.c_str());
xml->writeClosingTag(L"exp");
xml->writeLineBreak();
//Mensaje
xml->writeElement(L"mensaje");
xml->writeText(mensaje.c_str());
xml->writeClosingTag(L"mensaje");
xml->writeLineBreak();
//Ahora cerraremos el Tag de Jugador
xml->writeClosingTag(L"jugador");
//elimino de la memoria mi xml creado
delete xml;
//cerrar device
device->drop();
system("pause");
return 0;
}
Herramientas Para el Desarrollo de Videojuegos y Lenguajes de Programación en Español
domingo, 26 de abril de 2015
Escribiendo datos a un archivo XML en Irrlicht
Suscribirse a:
Enviar comentarios (Atom)

No hay comentarios:
Publicar un comentario