Esempio n. 1
0
TEST(DOMParserTest, ParsesASimpleString) {
    string input = "<html><head><title>Hello, World!</title></head><body>This is the body. </body></html>";
    char *copy = strdup(input.c_str());
    DOMNode *node = DOMNode::create();

    XML h;
    DOMNode *pNode = h.parse(copy, node);
    ASSERT_TRUE(pNode != 0);

    DOMNode *htmlNode = pNode->child();
    ASSERT_STREQ(htmlNode->name(), "html");

    ASSERT_STREQ(htmlNode->child()->name(), "head");
    ASSERT_STREQ(htmlNode->last()->name(), "body");

    DOMNode *headNode = htmlNode->child();
    ASSERT_EQ(headNode->child(), headNode->last());
    ASSERT_EQ(headNode->child()->type(), DOMNode::ELEMENT);
    ASSERT_STREQ(headNode->child()->name(), "title");
    ASSERT_STREQ(headNode->child()->child()->content(), "Hello, World!");

    DOMNode *bodyNode = headNode->next();
    ASSERT_STREQ(bodyNode->name(), "body");
    ASSERT_EQ(bodyNode->child(), bodyNode->last());
    ASSERT_EQ(bodyNode->child()->type(), DOMNode::TEXT);
    ASSERT_STREQ(bodyNode->child()->content(), "This is the body. ");

    free(copy);
}
Esempio n. 2
0
// Retrieves a list with available module ids
// static
StringList ModuleFactory::getModuleIDs()
{
    StringList list;

    boost::filesystem::path folder(dir::SHARE);
    folder /= "modules";
    // default construction yields past-the-end
    boost::filesystem::directory_iterator end_itr;
    for (boost::filesystem::directory_iterator itr(folder);
         itr != end_itr; itr++)
    {
        if (!boost::filesystem::is_regular_file(itr->status()))
            continue; // ignore directories
        // process only files with .xml extension
        boost::filesystem::path file(itr->path());
        if (file.extension() != ".xml")
            continue;

        XML xml;
        try
        {
            xml.parseFromFile(file.string());
        }
        catch(const std::exception& err)
        {
            klk_log(KLKLOG_ERROR, "Failed to get module info from '%s': %s",
                    file.string().c_str(), err.what());
            continue;
        }

        const std::string id = xml.getValue("/klkdata/module/id");
        list.push_back(id);
    }
    return list;
}
Esempio n. 3
0
void ProcessController::LoadXML()
{
	string filename = m_Filename+".xml";
	XML* xml = new XML(filename.c_str()); 
	XMLElement* e = xml->GetRootElement();
	LoadXML(e);
}
Esempio n. 4
0
void Level::parseXMLFile(const char *uri)
{
	// Initialize COM library.
	OleInitialize(0);

	XML* xmlDoc = 0;
	
	// Load from file or URL.
	FILE* fp = fopen(uri, "rb");
	if (fp) {
		// Load from file.
		fclose(fp);
		xmlDoc = new XML(uri);
	} else {
		// Load from URL.
		xmlDoc = new XML(uri, XML_LOAD_MODE_LOCAL_FILE);
	}

	// Check parse status and do integrity test. 0 OK , 1 Header warning (not fatal) , 2 Error in parse (fatal)
	if (xmlDoc->ParseStatus() == 2 || !xmlDoc->IntegrityTest()) {
		debug("Error: XML file %s is corrupt (or not a XML file).", uri);
		delete xmlDoc;
		return;
	}

	// Compress level XML in memory.
	xmlDoc->CompressMemory();

	XMLElement *rootNode = xmlDoc->GetRootElement();

	this->parseElement(rootNode);

	delete xmlDoc;
}
Esempio n. 5
0
void XML::read()
{
	// read until EOF or end token
	
	for (;;) {
		std::string token;
		token = read_token();
		if (token == "(0)" || (!strncmp(token.c_str(), "</", 2))) {
			return;
		}
		if (token.c_str()[0] == '<') {
#ifdef DEBUG_XML
			std::cout << "Reading sub tag\n";
#endif
			std::string name = get_token_name(token);
#ifdef DEBUG_XML
			std::cout << "Token is " << name.c_str() << "\n";
#endif
			XML* newdata = new XML(name, file);
			newdata->read();
			nodes.push_back(newdata);
		}
		else {
			value += token.c_str();
		}
	}
}
Esempio n. 6
0
//-------------------------------------------------------------------------------------	
void Config::writeAccountName(const char* name)
{
	if(!useLastAccountName_)
		return;

	TiXmlNode* rootNode = NULL;
	XML* xml = new XML(Resmgr::getSingleton().matchRes(fileName_).c_str());

	if(!xml->isGood())
	{
		ERROR_MSG(fmt::format("Config::writeAccountName: load {} is failed!\n",
			fileName_.c_str()));

		SAFE_RELEASE(xml);
		return;
	}

	rootNode = xml->getRootNode("accountName");
	if(rootNode != NULL)
	{
		rootNode->SetValue(name);
	}

	xml->getTxdoc()->SaveFile(fileName_.c_str());
	SAFE_RELEASE(xml);
}
Esempio n. 7
0
void XML_Helpers::handle_min_max_tag(XML *xml, int32_t &min, int32_t &max)
{
	min = 0;
	max = 0;

	XML *min_xml = xml->find("min");
	XML *max_xml = xml->find("max");

	if (min_xml == 0 || max_xml == 0) {
		return;
	}

	XML *x = min_xml->find("rand");
	if (x == 0) {
		min = handle_numeric_tag(min_xml);
	}
	else {
		x = XML_Helpers::handle_rand_tag(x);
		min = atoi(x->get_value().c_str());
	}

	x = max_xml->find("rand");
	if (x == 0) {
		max = handle_numeric_tag(max_xml);
	}
	else {
		x = XML_Helpers::handle_rand_tag(x);
		max = atoi(x->get_value().c_str());
	}
}
Esempio n. 8
0
void SBookWidget::menuImport(void)
{
    QFileDialog fd(QString::null,0,this,"Import",true);

    fd.setMode(QFileDialog::ExistingFile);
    fd.setCaption("Import");
    fd.setSelection(QDir::currentDirPath());
    fd.setFilters((const char **)ifilters);

    if(fd.exec()==QDialog::Accepted){
	QString filter    = fd.selectedFilter();
	QString fn = fd.selectedFile();

	if(access(fn.latin1(),04)){
	    if(QMessageBox::warning(0,"Cannot Read",
				    "The file "
				    + fn
				    + " cannot be opened for reading:"
				    + sys_errlist[errno],
				    "OK",QString::null,QString::null)==1){
	    }
	    return;				  // aborted
	}

	int count=0;

	if(filter.compare(ifilters[FILTER_XML])==0){
	    XML xml;

	    statusStack->raiseWidget(progressBar);
	    count = xml.readFile(fn,&data,0,progressBar);
	    statusStack->raiseWidget(statusBar);
	    if(count == -1){
		QMessageBox::warning(0,"Cannot Read",
				     "The file " + fn + " appears to be corrupt. Sorry!",
				     "OK");
		return;
	    }
	}
	

	if(filter.compare(ifilters[FILTER_SBOOK_ASCII])==0){
	    count = data.ImportSBookASCII(fn);
	}
	if(filter.compare(ifilters[FILTER_TAB])==0){
	    count = data.ImportDelimited(fn,TAB_DELIM);
	}
	if(filter.compare(ifilters[FILTER_CSV])==0){
	    count = data.ImportDelimited(fn,CSV_DELIM);
	}
	if(filter.compare(ifilters[FILTER_IG])==0){
	    count = data.ImportIG(fn);
	}
	redisplay();
	char buf[1024];
	sprintf(buf,"Imported %d %s",count,count==1 ? "entry" : "entries");
	emit alert(buf);
    }
}
Esempio n. 9
0
static int loadxml(lua_State *state)
{
	const char *path = luaL_checkstring(state, -1);
	assert(path);
	XML obj;
	obj.Load(path);
	return 0;
}
Esempio n. 10
0
void PlayerDetails::fromXml(XML& xml){
	mMesh = xml.getString("ship", "mesh");
	mDll = xml.getString("ship", "dll");
	mShield = xml.getFloat("ship", "shield");
	mShieldRegen = xml.getFloat("ship", "shield_regen");
	mArmour = xml.getFloat("ship", "armour");
	mEnergy = xml.getFloat("ship", "energy");
	mEnergyRegen = xml.getFloat("ship", "energy_regen");
	mAmmo = xml.getInt("ship", "ammo");
	mSpeed = xml.getFloat("ship", "speed");
	mDeathFX = xml.getString("death_fx");
	if (xml.getError() != XML_OK){
		mDeathFX = "";
	}

	{
		XMLIterator it(&xml);
		it.setElemName("ship>weaponchain");
		it.gotoZero();
		while(it.gotoNext()==true){
			WeaponChain wc(it.getElem());
			mWeaponChain.push_back(wc);
		}
	}{
		XMLIterator it(&xml);
		it.setElemName("ship>reactor");
		it.gotoZero();
		while(it.gotoNext()==true){
			mReactorNodes.push_back(it.getElem().getString("childName"));
		}
	}


/*
	XMLIterator it(&xml);
	it.setElemName("");
	it.gotoZero();
	it.gotoNext();
	XML elem;

	if (it.gotoNext() == false){
		throw("Ship Definition File Missing 3 Weapon Chain");
	}
	elem = it.getElem();

	if (it.gotoNext() == false){
		throw("Ship Definition File Missing 2 Weapon Chain");
	}
	elem = it.getElem();
	mSecondaryWeapon.fromXml(elem);

	if (it.gotoNext() == false){
		throw("Ship Definition File Missing 1 Weapon Chain");
	}
	elem = it.getElem();
	mSuperWeapon.fromXml(elem);*/
	int g=0;
}
Esempio n. 11
0
	void Cell::createFromXml(XML* xml){
		/*mOverlay = mOverlayManager.create(getId());
		mOverlay->setZOrder(xml->getFloat("z"));
		mOverlay->show();*/

		//mZOrder = xml->getFloat("z");

		//mTrack = new RefinedTrack(xml, false);
		mX = new RefinedNumericTrack(xml, "posx");
		mY = new RefinedNumericTrack(xml, "posy");
		mAlpha = new RefinedNumericTrack(xml, "alpha");
		mScaleX = new RefinedNumericTrack(xml, "sclx");
		mScaleY = new RefinedNumericTrack(xml, "scly");

		//mAngle = new RefinedNumericTrack(xml, "angle");

		mPos.x = xml->getFloat("posx");
		mPos.y = xml->getFloat("posy");

		XMLIterator xmlIt(xml);


		/*xmlIt.setElemName("cell");
		xmlIt.gotoZero();
		while(xmlIt.gotoNext()==true){
			mElement.push_back(new Cell(&(xmlIt.getElem())));
		}*/
		xmlIt.setElemName("cell>image");
		xmlIt.gotoZero();
		
		while(xmlIt.gotoNext()==true){
			Image* img = new Image();
			img->init(&(xmlIt.getElem()));
			mElement.push_back(img);
			img->setDelta(Ogre::Vector2(-1, -1));
			img->moveTimes(getTimeOn());
		}
		xmlIt.setElemName("cell>textzone");
		xmlIt.gotoZero();
		while(xmlIt.gotoNext()==true){
			XML xml = xmlIt.getElem();
			string txttype = xml.getString("type");
			Text* txt;
			if (txttype == "rolling"){
				txt = new RollingText();
			}else if (txttype == "static"){
				txt = new StaticText();
			}else{
				txt = new StaticText();
			}
			txt->init(&(xmlIt.getElem()));
			txt->setFontStyle(FontStyleManager::getSingleton()->requestFontStyle(xmlIt.getElem().getString("style")));
			mElement.push_back(txt);
			txt->setDelta(Ogre::Vector2(-1, -1));
			txt->moveTimes(getTimeOn());
		}
	}
Esempio n. 12
0
static XML::XMLNode_SPtr createXMLTree1()
{
    using XML::XMLNode;
    using XML::XMLNode_SPtr;
    XMLNode_SPtr root(new XMLNode("ROOT"));
    root->children.push_back(XMLNode_SPtr(new XMLNode("CHILD1")));
    root->children.push_back(XMLNode_SPtr(new XMLNode("CHILD2")));
    return root;
}
Esempio n. 13
0
void KeyboardManager::load (std::string s)
{
    XML plik;
    plik.load(s);
    keys.clear();
    for(auto& xml : plik.iter(""))
    {
        keys[xml->get<std::string>(":name")] = (xml->get<int>(":keycode"));
    }
}
Esempio n. 14
0
WSAddNodePacket::WSAddNodePacket(std::string data) throw(InvalidXMLError) : WSPacket()
{
    XML XMLParser;

    xercesc::DOMDocument * doc = XMLParser.parseToDom(data);

    char * temp;

    xercesc::DOMElement * docElement = doc->getDocumentElement();
    //if(docElement == NULL)
     //   throw InvalidXMLError();

    xercesc::DOMElement * nextElement;
    nextElement = docElement->getFirstElementChild();

    XMLCh * installationIDString = xercesc::XMLString::transcode("installationID");
    XMLCh * sensorGroupIDString = xercesc::XMLString::transcode("sensorGroupID");
    XMLCh * zigbeeAddressString = xercesc::XMLString::transcode("zigbeeAddress");
    while(nextElement != NULL)
    {
        if(xercesc::XMLString::compareIString(nextElement->getTagName(), installationIDString) == 0)
        {
            temp = xercesc::XMLString::transcode(nextElement->getTextContent());
            installationID = boost::lexical_cast<int> (std::string(temp));
            xercesc::XMLString::release(&temp);

        }
        else if(xercesc::XMLString::compareIString(nextElement->getTagName(), sensorGroupIDString) == 0)
        {
            temp = xercesc::XMLString::transcode(nextElement->getTextContent());
            sensorGroupID = boost::lexical_cast<int> (std::string(temp));
            xercesc::XMLString::release(&temp);

        }
        else if(xercesc::XMLString::compareIString(nextElement->getTagName(), zigbeeAddressString) == 0)
        {
            temp = xercesc::XMLString::transcode(nextElement->getTextContent());
            zigbeeAddress64Bit = std::string(temp);
            xercesc::XMLString::release(&temp);
        }
        else
        {
            std::cerr << "invalid XML: " << std::endl;
            std::cerr << "textContent of invalid xml: " << std::string(xercesc::XMLString::transcode(nextElement->getTextContent())) << std::endl;
            std::cerr << "tagname of invalid XML: " << std::string(xercesc::XMLString::transcode(nextElement->getTagName())) << std::endl;
            throw InvalidWSXML();
        }

        nextElement = nextElement->getNextElementSibling();
    }

    xercesc::XMLString::release( &installationIDString );
    xercesc::XMLString::release( &sensorGroupIDString );
    xercesc::XMLString::release( &zigbeeAddressString );
}
Esempio n. 15
0
void ProcessController::SaveXML()
{
	string filename = m_Filename+".xml";

	XML* xml = new XML(filename.c_str()); 
	XMLElement* e = xml->GetRootElement();
	SaveXML(e);
	if (xml->IntegrityTest())
		xml->Save(); // Saves back to file
	delete xml;
}
Esempio n. 16
0
void ListFunctionDef::SetDefaultValues()
{
		SetProperty("Values","");

String xml( "<CryList />\
");
	xml.Replace("\\\"","\"");// replace \" with "  
XML x;
	x.LoadFrom(xml);
	x.SaveTo(*this);
}
Esempio n. 17
0
void XML::write(SDL_RWops *out, int tabs = 0)
{
	char buf[1000];

	if (value == "") {
		for (int i = 0; i < tabs; i++) {
			snprintf(buf, 200, "\t");
			SDL_fputs(buf, out);
		}

		snprintf(buf, 200, "<%s>\n", name.c_str());
		SDL_fputs(buf, out);

		std::list<XML*>::iterator it = nodes.begin();

		while (it != nodes.end()) {
			XML* node = dynamic_cast<XML*>(*it);
			node->write(out, tabs+1);
			it++;
		}

		for (int i = 0; i < tabs; i++) {
			snprintf(buf, 200, "\t");
			SDL_fputs(buf, out);
		}

		snprintf(buf, 200, "</%s>\n", name.c_str());
		SDL_fputs(buf, out);
	}
	else {
		for (int i = 0; i < tabs; i++) {
			snprintf(buf, 200, "\t");
			SDL_fputs(buf, out);
		}

		snprintf(buf, 200, "<%s>", name.c_str());
		SDL_fputs(buf, out);
	
		snprintf(buf, 200, "%s", value.c_str());
		SDL_fputs(buf, out);
		
		std::list<XML*>::iterator it = nodes.begin();

		while (it != nodes.end()) {
			XML* node = dynamic_cast<XML*>(*it);
			node->write(out, tabs+1);
			it++;
		}
		
		snprintf(buf, 200, "</%s>\n", name.c_str());
		SDL_fputs(buf, out);
	}
}
Esempio n. 18
0
void BuilderFunctionDef::SetDefaultValues()
{
		Return = "void";
		Param = "();\n";
		SetProperty("Value","");

String xml( "<CryString Value=\"\" />\
");
	xml.Replace("\\\"","\"");// replace \" with "  
XML x;
	x.LoadFrom(xml);
	x.SaveTo(*this);
}
Esempio n. 19
0
Handle<Value> loadXML(const v8::Arguments& args) {
	if(!args.IsConstructCall()) {
		return v8::ThrowException(String::New("Cannot call constructor as a function"));
	}
/*	if (args.Length() != 1) {
		return v8::ThrowException(v8::String::New("Bad parameters"));
	} */
	HandleScope scope;	
	
	Shell *shell = Shell::Instance();
	Context::Scope context_scope(shell->globalContext);
	XML *newXML = new XML();
	return(scope.Close(newXML->registerObject()));
}
Esempio n. 20
0
string ConfigurationManager::getLocation(){
    XML xml;
    char* pPath;
     pPath = getenv ("HOME");
     QString path(pPath);
     if (pPath!=NULL){
         path = path +QString(xml.getValue(xml.N_USRDESTDIR).c_str());
         QDir dir(path);
         if (!dir.exists()) {
             dir.mkpath(".");
         }
     }
    return path.toStdString();
}
Esempio n. 21
0
	WeaponDBE* WeaponDB::get(string id){
		for (list<WeaponDBE*>::iterator it = mEntry.begin();it!=mEntry.end();it++){
			if ((*it)->getId() == id){
				return (*it);
			};
		}
		File f(id+".xml", "media\\weapons\\weapons");
		XML* xml;
		if (f.error() != FILE_OK){
			throw("Error accessing file : "+id+" in context weapons\\weapons");
			xml = NULL;
		}else{
			xml = new XML(f.getStrContent());
		}
		string type = xml->getString("weapon","type");
		if (xml->getError() != XML_OK){
			throw("Error : Weapon requires type");
		}
		
		WeaponDBE* rv;
		if (type == "dll"){
			rv = new DLLWeaponDBE(id, *xml);
		}else if (type == "internal"){
			string subtype = xml->getString("weapon","subtype");
			if (xml->getError() != XML_OK){
				throw("Error : Weapon requires subtype");
			}
			if (subtype == "ammo"){
				rv = new AmmoWeaponDBE(id, *xml);
			}else if (subtype == "beam"){
				rv = new BeamWeaponDBE(id, *xml);
			}else{
				throw("Subtype : "+subtype+" not recognized");
			}
		}else{
			throw("Type : "+type+" not recognized");
		}
		//rv->setMount(launcher, mMount);
		delete xml;
		mEntry.push_back(rv);
		return rv;

	}
Esempio n. 22
0
bool XMLfile::save(Object* pObj,const char *file) //saves the XML file created with the object
{
		// Create the XML FILE or if it already exists, it will be overwritten

	XML* xml = new XML(file);
	XMLElement* root = xml->GetRootElement();

	string className = pObj->getClassName();
	XMLElement* obj_xml=new XMLElement (root,className.c_str());

	pObj->writeToXML(obj_xml);//execute the writing process XML
	pElem.push_back(obj_xml);//save every XMLElements_Objects in pElem

	root->AddElement(obj_xml);
	xml->Save();

	return true;

}
Esempio n. 23
0
		void XML::ParseTinyXmlElement(const tinyxml2::XMLElement& element)
		{
			//Parse this
			const char* text = element.GetText();
			if(text)
				m_data = text;

			//Parse attributes
			for(const tinyxml2::XMLAttribute* attribute = element.FirstAttribute(); attribute; attribute = attribute->Next())
			{
				m_attributes.insert(std::make_pair(string::ToLower(attribute->Name()), std::string(attribute->Value())));
			}

			//Parse children
			for(const tinyxml2::XMLElement* childElement = element.FirstChildElement(); childElement; childElement = childElement->NextSiblingElement())
			{
				XML* childNode = AddChild(childElement->Name());
				childNode->ParseTinyXmlElement(*childElement);
			}
		}
Esempio n. 24
0
XML *XML_Helpers::handle_rand_tag(XML *xml)
{
	std::list<XML *> &nodes = xml->get_nodes();

	std::list<XML *>::iterator it;

	int total_percent = 0;
	std::vector< std::pair<int, XML *> > values;

	for (it = nodes.begin(); it != nodes.end(); it++) {
		int percent;
		XML *x = *it;
		XML *value = x->find("value");
		if (value == 0) {
			continue;
		}
		XML *percent_xml = x->find("percent");
		if (percent_xml) {
			percent = atoi(percent_xml->get_value().c_str());
		}
		else {
			percent = 100;
		}
		total_percent += percent;
		values.push_back(std::pair<int, XML *>(percent, value));
	}

	int r = rand() % total_percent;
	int percent = 0;

	for (size_t i = 0; i < values.size(); i++) {
		std::pair<int, XML *> &p = values[i];
		percent += p.first;
		if (r < percent) {
			return *(p.second->get_nodes().begin());
		}
	}

	return 0;
}
Esempio n. 25
0
void TerrainDefaults::Load (const std::string & file, TextureRegistry & texReg) throw (std::runtime_error) {
	XML xml;
	xml.Load(file);
	xml.SelectSection("map");
	std::string defName = xml.GetValue("default");
	DefaultId = texReg.GetTextureId(defName);
	xml.SelectNode("terrain-types");
	for (bool res = xml.SelectNode("ttype"); res; res = xml.SelectNextNode ("ttype")) {
		Elements.push_back(Record());
		Elements.back().Name = xml.GetAttribute("name");
		Elements.back().Element.Load(xml, texReg);
	}
	Loaded = true;
}
Esempio n. 26
0
int OpenXML(const char* XMLFile, char *attribute)
{
	XML* xml = new XML(XMLFile);
	XMLElement* root = xml->GetRootElement();
	unsigned int nodeCount = root->GetChildrenNum();
	XMLElement** node = root->GetChildren();

	for (unsigned int i = 0; i < nodeCount; i++) {
        unsigned int leafCount = node[i]->GetChildrenNum();
        XMLElement** leaf = node[i]->GetChildren();

        for (unsigned int j = 0; j < leafCount; j++) {
            XMLVariable* Att = leaf[j]->FindVariableZ(attribute);
            if (Att) {
                char Buf[255];
                Att->GetValue(Buf);
                printf("Attribute %s has value %s\n", attribute, Buf);
            }
        }
	}
	delete xml;
	return 0;
}
Esempio n. 27
0
void Test_XML::test_Parser()
{
    AddSection("XML Parser");

    using XML::XMLNode_SPtr;
    using XML::parseXML;

    XMLNode_SPtr root=createXMLTree1();
    {
        std::stringbuf b("<ROOT><CHILD1></CHILD1><CHILD2></CHILD2></ROOT>");
        XMLNode_SPtr root2 = parseXML(b);
        ASSERTERROR(root->equals(root2),"Parser Tree (1) should be identical");
    }
}
Esempio n. 28
0
void WeaponChain::fromXml(XML& xml){
	mTimeBetweenShots = xml.getFloat("time_between_shots");
	XMLIterator it(&xml);
	it.setElemName("weaponchain>weapon");
	it.gotoZero();
	while(it.gotoNext()==true){
		WeaponInfo wi(&it.getElem());
		/*wd.DLL = it.getElem().getString("dll");
		wd.XML = it.getElem().getString("xml");
		wd.mount = it.getElem().getString("mount");
		mWeapon.push_back(wd);*/
		mWeapon.push_back(wi);

	}
}
Esempio n. 29
0
void EUITIbotSim::loadFromXMLText(char *XmlText)
{
	XML x;
	readFromXML(x.Paste(XmlText));
}
Esempio n. 30
0
int main()
{
    FILE *rFile = fopen("Parsefile.txt", "w");
    FILE *bFile = fopen("Samplefile.bin", "rb");
    field fd = parseFieldStructure();

    fseek (bFile, 0, SEEK_END);
    long fSize = ftell (bFile);
    fseek (bFile, 0, SEEK_SET);
	BYTE *buffer = new BYTE[fSize];
	fread(buffer, fSize, 1, bFile);

	int numRec = fSize / fd.totBytes;
    int fieldIdx = 0, fieldIncIdx = 0, intPosIdx = 0, strIdx = 0;
    int fInt = 0;
    char fStr[255];
    bool typeInt = false;

    XML* xml = new XML();
	xml->LoadText("<data></data>");
    XMLElement* root = xml->GetRootElement();
	XMLElement* record[numRec];
	XMLElement* fields[115 * numRec];

    for (int recIdx = 0; recIdx < numRec; recIdx++) {
        record[recIdx] = new XMLElement(root, "record");
        root->InsertElement(recIdx, record[recIdx]);
        bytesToIntger(fStr, recIdx + 1);
        record[recIdx]->AddVariable("id", fStr);

        for (int xmlIdx = 115 * recIdx; xmlIdx < (1 + recIdx) * 115; xmlIdx++) {
            fields[xmlIdx] = new XMLElement(record[recIdx], "field");
            record[recIdx]->InsertElement(xmlIdx, fields[xmlIdx]);
        }
    }

    int xmlIdx = 0;

    for (int idx = 0; idx <= fSize - 1; idx++)
    {
        if(idx >= fieldIncIdx) {

            if(typeInt) {
                bytesToIntger(fStr, fInt);
            } else {
                bytesToStr(fStr, strIdx);
            }

            if(fieldIdx > 0) {
                fields[xmlIdx - 1]->AddVariable(fd.name[fieldIdx - 1], fStr);
            }
            else if(idx != 0) {
                fields[xmlIdx - 1]->AddVariable(fd.name[114], fStr);
            }

            xmlIdx++;
            typeInt = fd.type[fieldIdx] == 'I';

            fprintf(rFile, "%s", fStr);
            fprintf(rFile, "\t");

            fieldIncIdx += fd.bytes[fieldIdx];
            fieldIdx = fieldIdx < 114 ? fieldIdx + 1 : 0;
            if (fieldIdx == 0)
                fprintf(rFile, "\n");
        }

        if(buffer[idx] == 0xe9) {
            fieldIncIdx++;
        } else if(typeInt) {
            fInt <<= 8;
            fInt = (fInt | buffer[idx]);
        } else if (buffer[idx] > 0x1f && buffer[idx] < 0x7f) {
            fStr[strIdx++] = buffer[idx];
        }
    }

    xml->Save("XMLfile.xml");
    fclose(rFile);
    fclose(bFile);

    /* And now we can search for a attrinute
       like subscriber_no in our xml-file. */

    OpenXML("XMLfile.xml", "subscriber_no");

    return 0;
}