Пример #1
0
void ProcessController::LoadXML()
{
	string filename = m_Filename+".xml";
	XML* xml = new XML(filename.c_str()); 
	XMLElement* e = xml->GetRootElement();
	LoadXML(e);
}
Пример #2
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;
}
Пример #3
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;
}
Пример #4
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;

}
Пример #5
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;
}
Пример #6
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;
}
Пример #7
0
int main()
 {
 OleInitialize(0);
 char* f1 = "http://www.turboirc.com/xml/sample1.xml";
 char* f2 = ".\\sample2.xml";

 XML* x = 0;

 // Load from file or url
 FILE* fp = fopen(f1,"rb");
 if (fp)
	 {
	 // Load from file
	 fclose(fp);
	 x = new XML(f1);
	 }
 else
	 {
	 // Load from url
	 x = new XML(f1,XML_LOAD_MODE_URL);
	 }

 // Parse status check
 int iPS = x->ParseStatus(); // 0 OK , 1 Header warning (not fatal) , 2 Error in parse (fatal)
 bool iTT = x->IntegrityTest(); // TRUE OK
 if (iPS == 2 || iTT == false)
	 {
	 fprintf(stderr,"Error: XML file %s is corrupt (or not a XML file).\r\n\r\n",f1);
	 delete x;
	 return 0;
	 }

 // Sample export to stdout
 x->Export(stdout,XML_SAVE_MODE_ZERO);


 // Sample XML functions
 fprintf(stdout,"\r\n\r\n---------- XML test ----------\r\n");
 XML_VERSION_INFO xI = {0};
 x->Version(&xI);
 fprintf(stdout,"XML version: %u.%u (%s)\r\n",xI.VersionHigh,xI.VersionLow,xI.RDate);
 int m1 = x->MemoryUsage();
 x->CompressMemory();
 int m2 = x->MemoryUsage();
 fprintf(stdout,"Memory used before/after compression: %u / %u bytes.\r\n",m1,m2);
 fprintf(stdout,"XML header: %s\r\n",x->GetHeader()->operator const char *());

 // Sample XMLElement functions
 fprintf(stdout,"\r\n\r\n---------- XMLElement test ----------\r\n");
 XMLElement* r = x->GetRootElement();
 int nC = r->GetChildrenNum();
 fprintf(stdout,"Root element has %u children.\r\n",nC);
 for(int i = 0 ; i < nC ; i++)
	 {
	 XMLElement* ch = r->GetChildren()[i];
	 int nV = ch->GetVariableNum();
	 int nMaxElName = ch->GetElementName(0);
	 char* n = new char[nMaxElName + 1];
	 ch->GetElementName(n);

	 fprintf(stdout,"\t Child %u: Variables: %u , Name: %s\r\n",i,nV,n);
	 delete[] n;
	 }
 // Add a children to the end
 r->AddElement(new XMLElement(r,(char*)"<testel x=\"1\" />"));

 // Find this element by name
 XMLElement* el = r->FindElementZ("testel");
 if (!el)
	 fprintf(stderr,"Error, element not found!\r\n");
 else
	 {
	 // Add some variables
	 el->AddVariable(new XMLVariable("somename","somevalue"));
	 // Note that the new XMLVariable we added is now owned by el

	 // Export only this element
	 el->Export(stdout,1,XML_SAVE_MODE_ZERO); // this prints <testel somename="somevalue"/>
	 }

 // Find an element that may not exist, get its variable X that may not exist, get 
 // a default value of 0
 int v = r->FindElementZ("elx",true)->FindVariableZ("varx",true)->GetValueInt();
 // Set it to 5, set some more
 r->FindElementZ("elx",true)->FindVariableZ("varx",true)->SetValueInt(5);
 r->FindElementZ("elx",true)->FindVariableZ("varx2",true)->SetValueInt(10);
 // Printout it
 // This would print: <elx varx="5" varx2="10"/>
 r->FindElementZ("elx",true)->Export(stdout,1,XML_SAVE_MODE_ZERO);

 // Remove the var we just added
 int ix = r->FindElement("elx");
 if (ix != -1)
	 r->RemoveVariable(ix);

 // Other XMLElement functions
 r->Copy(); // Copy entire thing to windows clipboard

 XMLElement* nP = XML::Paste();
 if (nP)
	 {
	 fprintf(stdout,"Successfully copy/paste from clipboard.\r\n");
	 delete nP; // This nP is not owned by x, so we must delete it!
	 }

 // Get a duplicate
 XMLElement* dup = r->Duplicate();
 if (dup)
	 delete dup;

 // Add a comment to the root element
 int nComments = r->AddComment(new XMLComment(0,0,"Nice comment"),0); 

 // Add same comment to the header
 x->GetHeader()->AddComment(x->GetRootElement()->GetComments()[nComments - 1]->Duplicate(),0);

 // Use XMLSetString, XMLSetBinaryData
 XMLSetString("El1\\El2\\El3","var1","x",0,x);

 RECT rc = {0};
 GetWindowRect(GetDesktopWindow(),&rc);
 XMLSetBinaryData("El1\\El2\\El3","var2",(char*)&rc,sizeof(rc),0,x);

 // Get again
 RECT rc2 = {0};
 XMLGetBinaryData("El1\\El2\\El3","var2",(char*)&rc2,(char*)&rc2,sizeof(rc2),0,x);
 if (memcmp(&rc,&rc2,sizeof(rc)) != 0)
	 fprintf(stderr,"Error in binary data transfer!\r\n");
 else
	 fprintf(stdout,"Binary data transfer OK!\r\n");

 // Import database in cdrom.mdb
 // Careful; not tested with ACCESS 2007
 /*IMPORTDBPARAMS dbp = {0};
 char f[300] = {0};
 GetCurrentDirectory(300,f);
 strcat(f,"\\cdrom.mdb");
 dbp.dbname = f;
 dbp.nTables = 1;
 dbp.provstr = 0; // use default
 IMPORTDBTABLEDATA tbl = {0};
 strcpy(tbl.name,"Collection"); // Table name in MDB
 strcpy(tbl.itemname,"v");  // Default name for out elements
 tbl.nVariables = 4; // ID , CD , Name , Comments
 char* v1[] = {"ID","CD","Name","Comments"};
 char* v2[] = {"ID","CD","Name","Comments"};
 tbl.Variables = v1;
 tbl.ReplaceVariables = v2; // In case we want different name
 dbp.Tables = &tbl;
 XMLElement* d = 0;
 d = XML::ImportDB(&dbp); 
 if (d && d->IntegrityTest())
	 {
	 d->Export(stdout,1,0);
	 delete d;
	 }
*/

 // XML object save
 // Manipulate export format
 XMLEXPORTFORMAT xf = {0};
 xf.UseSpace = true;
 xf.nId = 2;
 x->SetExportFormatting(&xf);
 if (x->Save(f2) == 1)
	fprintf(stdout,"%s saved.\r\n",f2);

 // XML object bye bye
 delete x;
    std::cin.get();
 }
Пример #8
0
bool XMLfile::importFromXML ()
{

	//Ejemplo: <importfrom xml="eutibot.xml" element="euitibot" name="Robot1">
	string name;

	if (root->FindElementZ("importfrom"))
	{
		XMLElement* import=root->FindElementZ("importfrom");
		if (import->FindVariableZ("xml"))
		{
			name=XMLAux::GetValueCadena(import->FindVariableZ("xml"));
			XML* xmlImport = new XML(name.c_str());
			XMLElement* rootImport = xmlImport->GetRootElement();


			if (import->FindVariableZ("element"))
			{
				name=string();
				name=XMLAux::GetValueCadena(import->FindVariableZ("element"));

				if (rootImport->FindElementZ(name.c_str()))
				{
					imported=rootImport->FindElementZ(name.c_str())->Duplicate();
					if (import->FindVariableZ("name"))
					{
						name=string();
						name=XMLAux::GetValueCadena(import->FindVariableZ("name"));

						if (imported->FindVariableZ("name"))
							imported->FindVariableZ("name")->SetValue(name.c_str());
						else
						{
							XMLVariable* _name=new XMLVariable ("name",name.c_str());
							imported->AddVariable(_name);
						}
					}
					return true;
				}

				else //search the XMLElement in another deep just in case
				{
					int num=rootImport->GetAllChildrenNum();
					XMLElement** childsImport=new XMLElement*[num];
					rootImport->GetAllChildren(childsImport);
					for (int i=0;i<num;i++)
					{
						if (childsImport[i]->FindElementZ(name.c_str()))
						{
							imported=childsImport[i]->FindElementZ(name.c_str())->Duplicate();

							if (import->FindVariableZ("name"))
							{
								name=string();
								name=XMLAux::GetValueCadena(import->FindVariableZ("name"));

								if (imported->FindVariableZ("name"))
									imported->FindVariableZ("name")->SetValue(name.c_str());
								else
								{
									XMLVariable* _name=new XMLVariable ("name",name.c_str());
									imported->AddVariable(_name);
								}
							}
							return true;
						}
					}


				}


			}

		}


	}

	return false;
}