TiXmlElement* Transform::GenerateOverridesXML( TiXmlElement* pResourceNode ) const { TiXmlElement* pRetXMLNode = ENG_NEW TiXmlElement( "Transform" ); TiXmlElement* pPosition = GetToWorldPosition().GenerateOverridesXML( pResourceNode->FirstChildElement( "Position" ) ); pPosition->SetValue( "Position" ); pRetXMLNode->LinkEndChild( pPosition ); TiXmlElement* pRotation = GetPitchYawRollDeg().GenerateOverridesXML( pResourceNode->FirstChildElement( "PitchYawRoll" ) ); pRotation->SetValue( "PitchYawRoll" ); pRetXMLNode->LinkEndChild( pRotation ); TiXmlElement* pScale = GetScale().GenerateOverridesXML( pResourceNode->FirstChildElement( "Scale" ) ); pScale->SetValue( "Scale" ); pRetXMLNode->LinkEndChild( pScale ); return pRetXMLNode; }
TiXmlElement* Transform::GenerateXML( void ) const { TiXmlElement* pRetXMLNode = ENG_NEW TiXmlElement( "Transform" ); TiXmlElement* pPosition = GetToWorldPosition().GernerateXML(); pPosition->SetValue( "Position" ); pRetXMLNode->LinkEndChild( pPosition ); TiXmlElement* pRotation = GetPitchYawRollDeg().GernerateXML(); pRotation->SetValue( "PitchYawRoll" ); pRetXMLNode->LinkEndChild( pRotation ); TiXmlElement* pScale = GetScale().GernerateXML(); pScale->SetValue( "Scale" ); pRetXMLNode->LinkEndChild( pScale ); return pRetXMLNode; }
TiXmlElement * Node::ToTiXmlElement() { string name = isLeaf ? "leaf":"node"; string valueType = isLeaf?"value":"threshold"; string posAtrValue = int2str(position); TiXmlElement *element = new TiXmlElement(""); element->SetValue(name.c_str()); element->SetAttribute("position",posAtrValue.c_str()); element->SetAttribute(valueType.c_str(),value.c_str()); return element; }
void wxsVersionConverter::ConvertOldWxsFile(const wxString& FileName,bool UsingXrc) const { TiXmlDocument Doc; if ( !TinyXML::LoadDocument(FileName,&Doc) ) return; TiXmlElement* Smith = Doc.FirstChildElement("resource"); if ( Smith ) { Smith->SetValue("wxsmith"); } if ( UsingXrc && Smith ) { // Need to extract extra data from any resource's item and put into <resource_extra> node TiXmlElement* Resource = Smith->FirstChildElement("object"); TiXmlElement* Extra = Smith->InsertEndChild(TiXmlElement("resource_extra"))->ToElement(); GatherExtraFromOldResourceReq(Resource,Extra,true); } TinyXML::SaveDocument(FileName,&Doc); }
void readSchoolXml() { using namespace std; const char *xmlFile = "conf/school.xml"; TiXmlDocument doc; if (!doc.LoadFile(xmlFile)) { cout << "Load xml file failed.\t" << xmlFile << endl; return; } cout << "Load xml file OK." << endl; TiXmlDeclaration *decl = doc.FirstChild()->ToDeclaration(); if (!decl) { cout << "decl is null.\n" << endl; return; } cout << decl->Encoding(); cout << decl->Version(); cout << decl->Standalone() << endl; TiXmlHandle docHandle(&doc); TiXmlElement *child = docHandle.FirstChild("School").FirstChild("Class").Child("Student", 0).ToElement(); for ( ; child != NULL; child = child->NextSiblingElement()) { TiXmlAttribute *attr = child->FirstAttribute(); for (; attr != NULL; attr = attr->Next()) { cout << attr->Name() << " : " << attr->Value() << endl; } TiXmlElement *ct = child->FirstChildElement(); for (; ct != NULL; ct = ct->NextSiblingElement()) { char buf[1024] = {0}; u2g(ct->GetText(), strlen(ct->GetText()), buf, sizeof(buf)); cout << ct->Value() << " : " << buf << endl; } cout << "=====================================" << endl; } TiXmlElement *schl = doc.RootElement(); const char *value_t =schl->Attribute("name"); char buf[1024] = {0}; if ( u2g(value_t, strlen(value_t), buf, sizeof(buf)) == -1) { return; } cout << "Root Element value: " << buf << endl; schl->RemoveAttribute("name"); schl->SetValue("NewSchool"); cout << "Save file: " << (doc.SaveFile("conf/new.xml") ? "Ok" : "Failed") << endl; return ; TiXmlElement *rootElement = doc.RootElement(); TiXmlElement *classElement = rootElement->FirstChildElement(); TiXmlElement *studentElement = classElement->FirstChildElement(); // N 个 Student 节点 for ( ; studentElement!= NULL; studentElement = studentElement->NextSiblingElement()) { // 获得student TiXmlAttribute *stuAttribute = studentElement->FirstAttribute(); for (; stuAttribute != NULL; stuAttribute = stuAttribute->Next()) { cout << stuAttribute->Name() << " : " << stuAttribute->Value() << endl; } // 获得student的第一个联系方式 TiXmlElement *contact = studentElement->FirstChildElement(); for (; contact != NULL; contact = contact->NextSiblingElement()) { const char *text = contact->GetText(); char buf[1024] = {0}; if ( u2g(text, strlen(text), buf, sizeof(buf)) == -1) { continue; } cout << contact->Value() << " : " << buf << endl; } } }