TiXmlNode* TiXmlNode::InsertEndChild( const TiXmlNode& addThis ) { if ( addThis.Type() == TiXmlNode::TINYXML_DOCUMENT ) { if ( GetDocument() ) GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); return 0; } TiXmlNode* node = addThis.Clone(); if ( !node ) return 0; return LinkEndChild( node ); }
CNodeData* CNodeData::AddNode(unsigned long uIndex, const std::string& name) { CNodeData* pNode = new CNodeData(); LinkEndChild(pNode); for (unsigned long i=0; i<=uIndex; ++i) { CNodeData* pNode = indexChild(i, name); if (pNode) { } } pNode->SetName(name); return pNode; }
GpxRteElement::GpxRteElement(const wxString &name, const wxString &cmt, const wxString &desc, const wxString &src, ListOfGpxLinks *links, int number, const wxString &type, GpxExtensionsElement *extensions, ListOfGpxWpts *waypoints) : TiXmlElement("rte") { if (!name.IsEmpty()) SetProperty(wxString(_T("name")), name); if (!cmt.IsEmpty()) SetProperty(wxString(_T("cmt")), cmt); if (!desc.IsEmpty()) SetProperty(wxString(_T("desc")), desc); if (!src.IsEmpty()) SetProperty(wxString(_T("src")), src); if (links) { wxListOfGpxLinksNode *link = links->GetFirst(); while (link) { LinkEndChild(link->GetData()); link = link->GetNext(); } } if (number != -1) SetProperty(wxString(_T("number")), wxString::Format(_T("%u"), number)); if (!type.IsEmpty()) SetProperty(wxString(_T("type")), type); if (extensions) LinkEndChild(extensions); if (waypoints) { wxListOfGpxWptsNode *wpt = waypoints->GetFirst(); while (wpt) { //TODO: Here we should check whether the waypoint is a *rtept* AppendRtePoint(wpt->GetData()); wpt = wpt->GetNext(); } } }
GpxTrkElement::GpxTrkElement(const wxString &name, const wxString &cmt, const wxString &desc, const wxString &src, ListOfGpxLinks *links, int number, const wxString &type, GpxExtensionsElement *extensions, ListOfGpxTrksegs *segments) : TiXmlElement("trk") { if (!name.IsEmpty()) SetProperty(wxString(_T("name")), name); if (!cmt.IsEmpty()) SetProperty(wxString(_T("cmt")), cmt); if (!desc.IsEmpty()) SetProperty(wxString(_T("desc")), desc); if (!src.IsEmpty()) SetProperty(wxString(_T("src")), src); if (links) { wxListOfGpxLinksNode *link = links->GetFirst(); while (link) { LinkEndChild(link->GetData()); link = link->GetNext(); } } if (number != -1) SetProperty(wxString(_T("number")), wxString::Format(_T("%u"), number)); if (!type.IsEmpty()) SetProperty(wxString(_T("type")), type); if (extensions) LinkEndChild(extensions); if (segments) { wxListOfGpxTrksegsNode *seg = segments->GetFirst(); while (seg) { AppendTrkSegment(seg->GetData()); seg = seg->GetNext(); } } }
void GpxRootElement::SetExtensions(GpxExtensionsElement *extensions) { if (!extensions) RemoveExtensions(); else { if(!my_extensions) my_extensions = (GpxExtensionsElement *)LinkEndChild(extensions); else { my_extensions = (GpxExtensionsElement *)ReplaceChild(my_extensions, *extensions); extensions->Clear(); delete extensions; } } }
TiXmlElement *PowerLawWidgetManager::serializeToXml() { auto root = new TiXmlElement("PowerLaws"); for (auto &widget : m_Widgets) { auto params = widget->getPowerLawParameters(); auto law = new TiXmlElement("PowerLawParameters"); law->SetDoubleAttribute("factor", params.factor); law->SetDoubleAttribute("exponent", params.exponent); law->SetDoubleAttribute("offset", params.offset); law->SetDoubleAttribute("rangeMin", widget->getMin()); law->SetDoubleAttribute("rangeMax", widget->getMax()); root->LinkEndChild(law); } return root; }
/** * @brief * Copy operator */ XmlElement &XmlElement::operator =(const XmlElement &cSource) { ClearThis(); m_sValue = cSource.m_sValue; m_pUserData = cSource.m_pUserData; m_cCursor = cSource.m_cCursor; // Clone the attributes for (const XmlAttribute *pAttribute=cSource.m_cAttributeSet.GetFirst(); pAttribute; pAttribute=pAttribute->GetNext()) SetAttribute(pAttribute->GetName(), pAttribute->GetValue()); // Clone the children for (const XmlNode *pNode=cSource.GetFirstChild(); pNode; pNode=pNode->GetNextSibling()) { XmlNode *pClone = pNode->Clone(); if (pClone) LinkEndChild(*pClone); } // Return a reference to this instance return *this; }
const char* TiXmlDocument::Parse( const char* p ) { // Parse away, at the document level. Since a document // contains nothing but other tags, most of what happens // here is skipping white space. // // In this variant (as opposed to stream and Parse) we // read everything we can. if ( !p || !*p ) { SetError( TIXML_ERROR_DOCUMENT_EMPTY ); return false; } p = SkipWhiteSpace( p ); if ( !p ) { SetError( TIXML_ERROR_DOCUMENT_EMPTY ); return false; } while ( p && *p ) { TiXmlNode* node = Identify( p ); if ( node ) { p = node->Parse( p ); LinkEndChild( node ); } else { break; } p = SkipWhiteSpace( p ); } // All is well. return p; }
void GpxTrkElement::SetProperty(const wxString &name, const wxString &value) { //FIXME: doesn't care about order so it can be absolutely wrong, have to redo this code if it has to be used by something else than the constructor //then it can be made public //FIXME: can be reused for route and track GpxSimpleElement *element = new GpxSimpleElement(name, value); TiXmlElement *curelement = FirstChildElement(); bool found = false; while(curelement) { if((const char *)curelement->Value() == (const char *)name.ToUTF8()) { ReplaceChild(curelement, *element); element->Clear(); delete element; break; } curelement = curelement->NextSiblingElement(); } if (!found) LinkEndChild(element); }
void GpxTrkElement::AppendTrkSegment(GpxTrksegElement *trkseg) { //FIXME: can be reused for route and track segment LinkEndChild(trkseg); }
const bool _toXMLImpl(std::ifstream& pInput, TiXmlDocument* pOutput) { if (!pInput) return false; auto spellsElement = static_cast<TiXmlElement*>(pOutput->LinkEndChild(new TiXmlElement("spells"))); String line; auto c = 0; while (std::getline(pInput, line)) { if (c >= 100) break; c++; Spell s; spellLineSplit(line, s); auto spellElement = static_cast<TiXmlElement*>(spellsElement->LinkEndChild(new TiXmlElement("spell"))); spellElement->SetAttribute("id", s[FieldIndex::ID].c_str()); spellElement->SetAttribute("name", s[FieldIndex::Name].c_str()); spellElement->SetAttribute("mana", s[FieldIndex::ManaCost].c_str()); spellElement->SetAttribute("target", s[FieldIndex::TargetType].c_str()); spellElement->SetAttribute("range", s[FieldIndex::Range].c_str()); if (s[FieldIndex::ResistType] != "0") spellElement->SetAttribute("resist", s[FieldIndex::ResistType].c_str()); //spellElement->SetAttribute("zone", s[FieldIndex::ZoneType].c_str()); //spellElement->SetAttribute("env", s[FieldIndex::EnvironmentType].c_str()); // Classes. auto classesElement = static_cast<TiXmlElement*>(spellElement->LinkEndChild(new TiXmlElement("classes"))); for (auto i = 0; i < NumClasses; i++) { if (s[FieldIndex::WAR_Level + i] == "255") continue; classesElement->SetAttribute(Classes[i].c_str(), s[FieldIndex::WAR_Level + i].c_str()); } // Effects. auto effectsElement = static_cast<TiXmlElement*>(spellElement->LinkEndChild(new TiXmlElement("effects"))); for (auto i = 0; i < NumEffects; i++) { if (s[FieldIndex::EffectID1 + i] == "254") continue; auto effectElement = static_cast<TiXmlElement*>(effectsElement->LinkEndChild(new TiXmlElement("effect"))); // ID effectElement->SetAttribute("type", s[FieldIndex::EffectID1 + i].c_str()); // Formula effectElement->SetAttribute("formula", s[FieldIndex::EffectFormula1 + i].c_str()); // Base effectElement->SetAttribute("base", s[FieldIndex::EffectBase1 + i].c_str()); // Limit effectElement->SetAttribute("limit", s[FieldIndex::EffectLimit1 + i].c_str()); // Max effectElement->SetAttribute("max", s[FieldIndex::EffectMax1 + i].c_str()); } // Strip element if the spell has no effects. if (effectsElement->NoChildren()) spellElement->RemoveChild(effectsElement); } return true; //if (!pInput) { return false; } //auto spellsElement = static_cast<TiXmlElement*>(pOutput->LinkEndChild(new TiXmlElement("spells"))); //static const std::list<std::pair<int, int>> ignore = { // { FieldIndex::EffectBase1, FieldIndex::EffectMax12 }, // { FieldIndex::ComponentID_1, FieldIndex::ComponentCount_4 }, // { FieldIndex::EffectFormula1, FieldIndex::EffectFormula12 }, // { FieldIndex::EffectID1, FieldIndex::EffectID12 }, //}; //auto inIgnored = [=](const int pFieldID){ // for (auto i : ignore) { // if (pFieldID >= i.first && pFieldID <= i.second) // return true; // } // return false; //}; //// Iterate lines //String line; //auto count = 1; //while (std::getline(pInput, line)) { // if (count >= 1000) break; // std::cout << count << std::endl; // auto spellElement = static_cast<TiXmlElement*>(spellsElement->LinkEndChild(new TiXmlElement("spell"))); // auto field = 0; // std::vector<String> values = split(line, '^'); // for (auto i : values) { // if (inIgnored(field)) { field++; continue; } // if (i.empty()) { field++; continue; } // spellElement->SetAttribute(FieldNames[field].c_str(), i.c_str()); // field++; // } // // Write effects. // auto effectsElement = new TiXmlElement("effects"); // auto effectCount = 0; // for (auto i = 0; i < 12; i++) { // // Check for non 254 effect ID. // if (values[FieldIndex::EffectID1 + i] == "254") continue; // effectCount++; // auto effectElement = static_cast<TiXmlElement*>(effectsElement->LinkEndChild(new TiXmlElement("effect"))); // // ID // effectElement->SetAttribute("id", values[FieldIndex::EffectID1 + i].c_str()); // // Formula // effectElement->SetAttribute("formula", values[FieldIndex::EffectFormula1 + i].c_str()); // // Base // effectElement->SetAttribute("base", values[FieldIndex::EffectBase1 + i].c_str()); // // Limit // effectElement->SetAttribute("limit", values[FieldIndex::EffectLimit1 + i].c_str()); // // Max // effectElement->SetAttribute("max", values[FieldIndex::EffectMax1 + i].c_str()); // } // if (effectCount) // spellElement->LinkEndChild(effectsElement); // else // delete effectsElement; // // Write Components. // auto componentsElement = new TiXmlElement("components"); // auto componentCount = 0; // for (auto i = 0; i < 4; i++) { // // Check for non -1 component item ID. // if (values[FieldIndex::ComponentID_1 + i] == "-1") continue; // componentCount++; // auto componentElement = static_cast<TiXmlElement*>(componentsElement->LinkEndChild(new TiXmlElement("component"))); // // Item ID. // componentElement->SetAttribute("id", values[FieldIndex::ComponentID_1 + i].c_str()); // // Item count. // componentElement->SetAttribute("count", values[FieldIndex::ComponentCount_1 + i].c_str()); // } // if (componentCount) // spellElement->LinkEndChild(componentsElement); // else // delete componentsElement; // line.clear(); // count++; //} return true; }
void mitk::PlanarFigureWriter::GenerateData() { m_Success = false; if (!m_WriteToMemory && m_FileName.empty()) { MITK_ERROR << "Could not write planar figures. File name is invalid"; throw std::invalid_argument("file name is empty"); } TiXmlDocument document; auto decl = new TiXmlDeclaration( "1.0", "", "" ); // TODO what to write here? encoding? etc.... document.LinkEndChild( decl ); auto version = new TiXmlElement("Version"); version->SetAttribute("Writer", __FILE__ ); version->SetAttribute("CVSRevision", "$Revision: 17055 $" ); version->SetAttribute("FileVersion", 1 ); document.LinkEndChild(version); /* create xml element for each input */ for ( unsigned int i = 0 ; i < this->GetNumberOfInputs(); ++i ) { // Create root element for this PlanarFigure InputType::Pointer pf = this->GetInput( i ); if (pf.IsNull()) continue; auto pfElement = new TiXmlElement("PlanarFigure"); pfElement->SetAttribute("type", pf->GetNameOfClass()); document.LinkEndChild(pfElement); if ( pf->GetNumberOfControlPoints() == 0 ) continue; //PlanarFigure::VertexContainerType* vertices = pf->GetControlPoints(); //if (vertices == NULL) // continue; // Serialize property list of PlanarFigure mitk::PropertyList::Pointer propertyList = pf->GetPropertyList(); mitk::PropertyList::PropertyMap::const_iterator it; for ( it = propertyList->GetMap()->begin(); it != propertyList->GetMap()->end(); ++it ) { // Create seralizer for this property const mitk::BaseProperty* prop = it->second; std::string serializerName = std::string( prop->GetNameOfClass() ) + "Serializer"; std::list< itk::LightObject::Pointer > allSerializers = itk::ObjectFactoryBase::CreateAllInstance( serializerName.c_str() ); if ( allSerializers.size() != 1 ) { // No or too many serializer(s) found, skip this property continue; } mitk::BasePropertySerializer* serializer = dynamic_cast< mitk::BasePropertySerializer* >( allSerializers.begin()->GetPointer() ); if ( serializer == nullptr ) { // Serializer not valid; skip this property } auto keyElement = new TiXmlElement( "property" ); keyElement->SetAttribute( "key", it->first ); keyElement->SetAttribute( "type", prop->GetNameOfClass() ); serializer->SetProperty( prop ); TiXmlElement* valueElement = nullptr; try { valueElement = serializer->Serialize(); } catch (...) { } if ( valueElement == nullptr ) { // Serialization failed; skip this property continue; } // Add value to property element keyElement->LinkEndChild( valueElement ); // Append serialized property to property list pfElement->LinkEndChild( keyElement ); } // Serialize control points of PlanarFigure auto controlPointsElement = new TiXmlElement("ControlPoints"); pfElement->LinkEndChild(controlPointsElement); for (unsigned int i = 0; i < pf->GetNumberOfControlPoints(); i++) { auto vElement = new TiXmlElement("Vertex"); vElement->SetAttribute("id", i); vElement->SetDoubleAttribute("x", pf->GetControlPoint(i)[0]); vElement->SetDoubleAttribute("y", pf->GetControlPoint(i)[1]); controlPointsElement->LinkEndChild(vElement); } auto geoElement = new TiXmlElement("Geometry"); const PlaneGeometry* planeGeo = dynamic_cast<const PlaneGeometry*>(pf->GetPlaneGeometry()); if (planeGeo != nullptr) { // Write parameters of IndexToWorldTransform of the PlaneGeometry typedef mitk::Geometry3D::TransformType TransformType; const TransformType* affineGeometry = planeGeo->GetIndexToWorldTransform(); const TransformType::ParametersType& parameters = affineGeometry->GetParameters(); auto vElement = new TiXmlElement( "transformParam" ); for ( unsigned int i = 0; i < affineGeometry->GetNumberOfParameters(); ++i ) { std::stringstream paramName; paramName << "param" << i; vElement->SetDoubleAttribute( paramName.str().c_str(), parameters.GetElement( i ) ); } geoElement->LinkEndChild( vElement ); // Write bounds of the PlaneGeometry typedef mitk::Geometry3D::BoundsArrayType BoundsArrayType; const BoundsArrayType& bounds = planeGeo->GetBounds(); vElement = new TiXmlElement( "boundsParam" ); for ( unsigned int i = 0; i < 6; ++i ) { std::stringstream boundName; boundName << "bound" << i; vElement->SetDoubleAttribute( boundName.str().c_str(), bounds.GetElement( i ) ); } geoElement->LinkEndChild( vElement ); // Write spacing and origin of the PlaneGeometry Vector3D spacing = planeGeo->GetSpacing(); Point3D origin = planeGeo->GetOrigin(); geoElement->LinkEndChild(this->CreateXMLVectorElement("Spacing", spacing)); geoElement->LinkEndChild(this->CreateXMLVectorElement("Origin", origin)); pfElement->LinkEndChild(geoElement); } } if(m_WriteToMemory) { // Declare a printer TiXmlPrinter printer; // attach it to the document you want to convert in to a std::string document.Accept(&printer); // Create memory buffer and print tinyxmldocument there... m_MemoryBufferSize = printer.Size() + 1; m_MemoryBuffer = new char[m_MemoryBufferSize]; strcpy(m_MemoryBuffer,printer.CStr()); } else { if (document.SaveFile( m_FileName) == false) { MITK_ERROR << "Could not write planar figures to " << m_FileName << "\nTinyXML reports '" << document.ErrorDesc() << "'"; throw std::ios_base::failure("Error during writing of planar figure xml file."); } } m_Success = true; }
const char* TiXmlElement::ReadValue( const char* p ) { TiXmlDocument* document = GetDocument(); // Read in text and elements in any order. p = SkipWhiteSpace( p ); while ( p && *p ) { const char* start = p; while ( *p && *p != '<' ) p++; if ( !*p ) { if ( document ) document->SetError( TIXML_ERROR_READING_ELEMENT_VALUE ); return 0; } if ( p != start ) { // Take what we have, make a text element. TiXmlText* text = new TiXmlText(); if ( !text ) { if ( document ) document->SetError( TIXML_ERROR_OUT_OF_MEMORY ); return 0; } text->Parse( start ); if ( !text->Blank() ) LinkEndChild( text ); else delete text; } else { // We hit a '<' // Have we hit a new element or an end tag? if ( *(p+1) == '/' ) { return p; // end tag } else { // TiXmlElement* element = new TiXmlElement( "" ); // // if ( element ) // { // p = element->Parse( p+1 ); // if ( p ) // LinkEndChild( element ); // } // else // { // if ( document ) document->SetError( ERROR_OUT_OF_MEMORY ); // return 0; // } TiXmlNode* node = IdentifyAndParse( &p ); if ( node ) { LinkEndChild( node ); } else { return 0; } } } } return 0; }
bool FileProcess::CreateStructXML(std::string strFile, std::string strFileName) { std::cout << strFile << std::endl; // 打开excel MiniExcelReader::ExcelFile* x = new MiniExcelReader::ExcelFile(); if (!x->open(strFile.c_str())) { printf("can't open %s\n", strFile.c_str()); return false; } // PropertyName // cpp std::string strHPPPropertyInfo = ""; std::string strHppRecordInfo = ""; std::string strHppEnumInfo = ""; strHPPPropertyInfo = strHPPPropertyInfo + "class " + strFileName + "\n{\npublic:\n"; strHPPPropertyInfo = strHPPPropertyInfo + "\t//Class name\n\tstatic const std::string& ThisName(){ static std::string x" + strFileName + " = \"" + strFileName + "\";" + " return x" + strFileName + "; }\n" + "\t// IObject\n" + strHppIObjectInfo + "\t// Property\n"; // java std::string strJavaPropertyInfo = ""; std::string strJavaRecordInfo = ""; std::string strJavaEnumInfo = ""; strJavaPropertyInfo = strJavaPropertyInfo + "public class " + strFileName + " {\n"; strJavaPropertyInfo = strJavaPropertyInfo + "\t//Class name\n\tpublic static final String ThisName = \"" + strFileName + "\";\n\t// IObject\n" + strJavaIObjectInfo + "\t// Property\n"; // C# std::string strCSPropertyInfo = ""; std::string strCSRecordInfo = ""; std::string strCSEnumInfo = ""; strCSPropertyInfo = strCSPropertyInfo + "public class " + strFileName + "\n{\n"; strCSPropertyInfo = strCSPropertyInfo + "\t//Class name\n\tpublic static readonly string ThisName = \"" + strFileName + "\";\n\t// IObject\n" + strCSIObjectInfo + "\t// Property\n"; // 开始创建xml tinyxml2::XMLDocument* structDoc = new tinyxml2::XMLDocument(); if (NULL == structDoc) { return false; } //xml声明 tinyxml2::XMLDeclaration *pDel = structDoc->NewDeclaration("xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\""); if (NULL == pDel) { return false; } structDoc->LinkEndChild(pDel); // 写入XML root标签 tinyxml2::XMLElement* root = structDoc->NewElement("XML"); structDoc->LinkEndChild(root); // 写入Propertys标签 tinyxml2::XMLElement* propertyNodes = structDoc->NewElement("Propertys"); root->LinkEndChild(propertyNodes); // 写入Records标签 tinyxml2::XMLElement* recordNodes = structDoc->NewElement("Records"); root->LinkEndChild(recordNodes); // 写入components的处理 tinyxml2::XMLElement* componentNodes = structDoc->NewElement("Components"); root->LinkEndChild(componentNodes); // 读取excel中每一个sheet std::vector<MiniExcelReader::Sheet>& sheets = x->sheets(); for (MiniExcelReader::Sheet& sh : sheets) { std::string strSheetName = sh.getName(); const MiniExcelReader::Range& dim = sh.getDimension(); std::string strUpperSheetName = strSheetName.substr(0, 8); transform(strUpperSheetName.begin(), strUpperSheetName.end(), strUpperSheetName.begin(), ::tolower); if (strUpperSheetName == "property") { std::vector<std::string> colNames; for (int r = dim.firstRow; r <= dim.firstRow + 7; r++) { MiniExcelReader::Cell* cell = sh.getCell(r, dim.firstCol); if (cell) { colNames.push_back(cell->value); } } for (int c = dim.firstCol + 1; c <= dim.lastCol; c++) { std::string testValue = ""; MiniExcelReader::Cell* cell = sh.getCell(dim.firstRow, c); if (cell) { testValue = cell->value; } if (testValue == "") { continue; } auto propertyNode = structDoc->NewElement("Property"); propertyNodes->LinkEndChild(propertyNode); std::string strType = ""; for (int r = dim.firstRow; r <= dim.firstRow + 7; r++) { std::string name = colNames[r - 1]; std::string value = ""; MiniExcelReader::Cell* cell = sh.getCell(r, c); if (cell) { std::string valueCell = cell->value; transform(valueCell.begin(), valueCell.end(), valueCell.begin(), ::toupper); if (valueCell == "TRUE" || valueCell == "FALSE") { value = valueCell == "TRUE" ? 1 : 0; } else { value = cell->value; } if (name == "Type") { strType = value; } } propertyNode->SetAttribute(name.c_str(), value.c_str()); } strHPPPropertyInfo = strHPPPropertyInfo + "\tstatic const std::string& " + testValue + "(){ static std::string x" + testValue + " = \"" + testValue + "\";" + " return x" + testValue + "; } // " + strType + "\n"; strJavaPropertyInfo = strJavaPropertyInfo + "\tpublic static final String " + testValue + " = \"" + testValue + "\"; // " + strType + "\n"; strCSPropertyInfo = strCSPropertyInfo + "\tpublic static readonly String " + testValue + " = \"" + testValue + "\"; // " + strType + "\n"; if (strFileName == "IObject") { strHppIObjectInfo += "\tstatic const std::string& " + testValue + "(){ static std::string x" + testValue + " = \"" + testValue + "\";" + " return x" + testValue + "; } // " + strType + "\n"; strJavaIObjectInfo += "\tpublic static final String " + testValue + " = \"" + testValue + "\"; // " + strType + "\n"; strCSIObjectInfo += "\tpublic static readonly String " + testValue + " = \"" + testValue + "\"; // " + strType + "\n"; } } } else if (strUpperSheetName == "componen") { std::vector<std::string> colNames; for (int c = dim.firstCol; c <= dim.lastCol; c++) { MiniExcelReader::Cell* cell = sh.getCell(dim.firstRow, c); if (cell) { colNames.push_back(cell->value); } } for (int r = dim.firstRow + 1; r <= dim.lastRow; r++) { std::string testValue = ""; MiniExcelReader::Cell* cell = sh.getCell(r, dim.firstCol); if (cell) { testValue = cell->value; } if (testValue == "") { continue; } auto componentNode = structDoc->NewElement("Component"); componentNodes->LinkEndChild(componentNode); std::string strType = ""; for (int c = dim.firstCol; c <= dim.lastCol; c++) { std::string name = colNames[c - 1]; std::string value = ""; MiniExcelReader::Cell* cell = sh.getCell(r, c); if (cell) { std::string valueCell = cell->value; transform(valueCell.begin(), valueCell.end(), valueCell.begin(), ::toupper); if (valueCell == "TRUE" || valueCell == "FALSE") { value = valueCell == "TRUE" ? 1 : 0; } else { value = cell->value; } if (name == "Type") { strType = value; } } componentNode->SetAttribute(name.c_str(), value.c_str()); } } } else { const int nRowsCount = dim.lastRow - dim.firstRow + 1; const int nRecordCount = nRowsCount / 10; if (nRowsCount != nRecordCount * 10) { printf("This Excel[%s]'s Record is something wrong, Sheet[%s] Total Rows is %d lines, Not 10*N\n", strFile.c_str(), strSheetName.c_str(), nRowsCount); printf("Generate faild!\n"); printf("Press [Enter] key to exit!\n"); std::cin.ignore(); exit(1); } for (int nCurrentRecord = 1; nCurrentRecord <= nRecordCount; nCurrentRecord++) { std::string strRecordName = ""; std::string strRow = ""; std::string strCol = ""; std::string strPublic = ""; std::string strPrivate = ""; std::string strSave = ""; std::string strCache = ""; std::string strDesc = ""; MiniExcelReader::Cell* cell = sh.getCell((nCurrentRecord - 1) * 10 + 1, 2); if (cell) { strRecordName = cell->value; } cell = nullptr; cell = sh.getCell((nCurrentRecord - 1) * 10 + 2, 2); if (cell) { strRow = cell->value; } cell = nullptr; cell = sh.getCell((nCurrentRecord - 1) * 10 + 3, 2); if (cell) { strCol = cell->value; } cell = nullptr; cell = sh.getCell((nCurrentRecord - 1) * 10 + 4, 2); if (cell) { if (cell->value == "TRUE" || cell->value == "FALSE") { strPublic = cell->value == "TRUE" ? 1 : 0; } else { strPublic = cell->value; } } cell = nullptr; cell = sh.getCell((nCurrentRecord - 1) * 10 + 5, 2); if (cell) { if (cell->value == "TRUE" || cell->value == "FALSE") { strPrivate = cell->value == "TRUE" ? 1 : 0; } else { strPrivate = cell->value; } } cell = nullptr; cell = sh.getCell((nCurrentRecord - 1) * 10 + 6, 2); if (cell) { if (cell->value == "TRUE" || cell->value == "FALSE") { strSave = cell->value == "TRUE" ? 1 : 0; } else { strSave = cell->value; } } cell = nullptr; cell = sh.getCell((nCurrentRecord - 1) * 10 + 7, 2); if (cell) { if (cell->value == "TRUE" || cell->value == "FALSE") { strCache = cell->value == "TRUE" ? 1 : 0; } else { strCache = cell->value; } } cell = nullptr; cell = sh.getCell((nCurrentRecord - 1) * 10 + 10, 2); if (cell) { strDesc = cell->value; } cell = nullptr; const int nExcelCols = atoi(strCol.c_str()); int nRealCols = 0; auto recordNode = structDoc->NewElement("Record"); recordNodes->LinkEndChild(recordNode); recordNode->SetAttribute("Id", strRecordName.c_str()); recordNode->SetAttribute("Row", strRow.c_str()); recordNode->SetAttribute("Col", strCol.c_str()); recordNode->SetAttribute("Public", strPublic.c_str()); recordNode->SetAttribute("Private", strPublic.c_str()); recordNode->SetAttribute("Save", strSave.c_str()); recordNode->SetAttribute("Cache", strCache.c_str()); recordNode->SetAttribute("Desc", strDesc.c_str()); strHppRecordInfo = strHppRecordInfo + "\tstatic const std::string& R_" + strRecordName + "(){ static std::string x" + strRecordName + " = \"" + strRecordName + "\";" + " return x" + strRecordName + ";}\n"; strHppEnumInfo = strHppEnumInfo + "\n\tenum " + strRecordName + "\n\t{\n"; strJavaRecordInfo = strJavaRecordInfo + "\tpublic static final String R_" + strRecordName + " = \"" + strRecordName + "\";\n"; strJavaEnumInfo = strJavaEnumInfo + "\n\tpublic enum " + strRecordName + "\n\t{\n"; strCSRecordInfo = strCSRecordInfo + "\tpublic static readonly String R_" + strRecordName + " = \"" + strRecordName + "\";\n"; strCSEnumInfo = strCSEnumInfo + "\n\tpublic enum " + strRecordName + "\n\t{\n"; std::string toWrite = "enum " + strRecordName + "\n{\n"; fwrite(toWrite.c_str(), toWrite.length(), 1, protoWriter); for (int nRecordCol = dim.firstCol;nRecordCol <= dim.lastCol;nRecordCol++) { std::string strType = ""; std::string strTag = ""; cell = sh.getCell((nCurrentRecord - 1) * 10 + 8, nRecordCol); if (cell) { strTag = cell->value; } else { break; } cell = nullptr; cell = sh.getCell((nCurrentRecord - 1) * 10 + 9, nRecordCol); if (cell) { strType = cell->value; } else { break; } cell = nullptr; auto colNode = structDoc->NewElement("Col"); recordNode->LinkEndChild(colNode); colNode->SetAttribute("Type", strType.c_str()); colNode->SetAttribute("Tag", strTag.c_str()); toWrite = "\t" + strTag + "\t\t= " + std::to_string(nRecordCol - 1) + "; // " + strTag + " -- " + strType + "\n"; fwrite(toWrite.c_str(), toWrite.length(), 1, protoWriter); strHppEnumInfo += "\t\t" + strRecordName + "_" + strTag + "\t\t= " + std::to_string(nRecordCol - 1) + ", // " + strTag + " -- " + strType + "\n"; strJavaEnumInfo += "\t\t" + strTag + "\t\t= " + std::to_string(nRecordCol - 1) + ", // " + strTag + " -- " + strType + "\n"; strCSEnumInfo += "\t\t" + strTag + "\t\t= " + std::to_string(nRecordCol - 1) + ", // " + strTag + " -- " + strType + "\n"; nRealCols++; } if (nExcelCols != nRealCols) { printf("This Excel[%s]'s format is something wrong, Record[%s] field \"col\"==%d not equal the real cols==%d!\n", strFile.c_str(), strRecordName.c_str(), nExcelCols, nRealCols); printf("Press [Enter] key to exit!"); std::cin.ignore(); exit(1); } fwrite("}\n", 2, 1, protoWriter); strHppEnumInfo += "\n\t};\n"; strJavaEnumInfo += "\n\t};\n"; strCSEnumInfo += "\n\t};\n"; } } } // cpp strHPPPropertyInfo += "\t// Record\n" + strHppRecordInfo + strHppEnumInfo + "\n};\n\n"; fwrite(strHPPPropertyInfo.c_str(), strHPPPropertyInfo.length(), 1, hppWriter); // java strJavaPropertyInfo += "\t// Record\n" + strJavaRecordInfo + strJavaEnumInfo + "\n}\n\n"; fwrite(strJavaPropertyInfo.c_str(), strJavaPropertyInfo.length(), 1, javaWriter); // C# strCSPropertyInfo += "\t// Record\n" + strCSRecordInfo + strCSEnumInfo + "\n}\n\n"; fwrite(strCSPropertyInfo.c_str(), strCSPropertyInfo.length(), 1, csWriter); //////////////////////////////////////////////////////////////////////////// // 保存文件 std::string strFilePath(strFile); int nLastPoint = strFilePath.find_last_of(".") + 1; int nLastSlash = strFilePath.find_last_of("/") + 1; std::string strFileExt = strFilePath.substr(nLastPoint, strFilePath.length() - nLastPoint); std::string strXMLFile = strToolBasePath + strXMLStructPath + strFileName; if (nCipher > 0) { strXMLFile += ".NF"; } else { strXMLFile += ".xml"; } structDoc->SetBOM(false); structDoc->SaveFile(strXMLFile.c_str()); delete structDoc; delete x; return true; }
/** * @brief * Reads the "value" of the element -- another element, or text */ const char *XmlElement::ReadValue(const char *pszData, XmlParsingData *pData, EEncoding nEncoding) { // Read in text and elements in any order const char *pWithWhiteSpace = pszData; pszData = SkipWhiteSpace(pszData, nEncoding); while (pszData && *pszData) { if (*pszData != '<') { // Take what we have, make a text element XmlText *pTextNode = new XmlText(""); if (IsWhiteSpaceCondensed()) pszData = pTextNode->Parse(pszData, pData, nEncoding); else { // Special case: we want to keep the white space so that leading spaces aren't removed pszData = pTextNode->Parse(pWithWhiteSpace, pData, nEncoding); } // Does the text value only contain white spaces? bool bIsBlank = true; { const String sValue = pTextNode->GetValue(); for (uint32 i=0; i<sValue.GetLength(); i++) { if (!IsWhiteSpace(sValue[i])) { bIsBlank = false; break; } } } if (bIsBlank) delete pTextNode; else LinkEndChild(*pTextNode); } else { // We hit a '<' // Have we hit a new element or an end tag? This could also be a XmlText in the "CDATA" style if (StringEqual(pszData, "</", false, nEncoding)) return pszData; else { XmlNode *pNode = Identify(pszData, nEncoding); if (pNode) { pszData = pNode->Parse(pszData, pData, nEncoding); LinkEndChild(*pNode); } else { return nullptr; } } } pWithWhiteSpace = pszData; pszData = SkipWhiteSpace(pszData, nEncoding); } if (!pszData) { // Set error code XmlDocument *pDocument = GetDocument(); if (pDocument) pDocument->SetError(ErrorReadingElementValue, 0, 0, nEncoding); } // Done return pszData; }
const char* TiXmlDocument::Parse ( const char* p, TiXmlParsingData* prevData, TiXmlEncoding encoding ) { ClearError(); // Parse away, at the document level. Since a document // contains nothing but other tags, most of what happens // here is skipping white space. // sherm 100319: I changed this so that untagged top-level text is // parsed as a Text node rather than a parsing error. CDATA text was // already allowed at the top level so this seems more consistent. if ( !p || !*p ) { SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); return 0; } // Note that, for a document, this needs to come // before the while space skip, so that parsing // starts from the pointer we are given. location.Clear(); if ( prevData ) { location.row = prevData->cursor.row; location.col = prevData->cursor.col; } else { location.row = 0; location.col = 0; } TiXmlParsingData data( p, TabSize(), location.row, location.col ); location = data.Cursor(); if ( encoding == TIXML_ENCODING_UNKNOWN ) { // Check for the Microsoft UTF-8 lead bytes. const unsigned char* pU = (const unsigned char*)p; if ( *(pU+0) && *(pU+0) == TIXML_UTF_LEAD_0 && *(pU+1) && *(pU+1) == TIXML_UTF_LEAD_1 && *(pU+2) && *(pU+2) == TIXML_UTF_LEAD_2 ) { encoding = TIXML_ENCODING_UTF8; useMicrosoftBOM = true; } } // Remember the start of white space in case we end up reading a text // element in a "keep white space" mode. const char* pWithWhiteSpace = p; p = SkipWhiteSpace( p, encoding ); if ( !p ) { SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); return 0; } // sherm 100319: ignore all but the first Declaration bool haveSeenDeclaration = false; while ( p && *p ) { TiXmlNode* node = 0; if ( *p != '<' ) { // sherm 100319: I added this case by stealing the code from // Element parsing; see above comment. // Take what we have, make a text element. TiXmlText* textNode = new TiXmlText( "" ); if ( !textNode ) { SetError( TIXML_ERROR_OUT_OF_MEMORY, 0, 0, encoding ); return 0; } if ( TiXmlBase::IsWhiteSpaceCondensed() ) { p = textNode->Parse( p, &data, encoding ); } else { // Special case: we want to keep the white space // so that leading spaces aren't removed. p = textNode->Parse( pWithWhiteSpace, &data, encoding ); } if ( !textNode->Blank() ) { LinkEndChild( textNode ); node = textNode; } else delete textNode; } else // We saw a '<', now identify what kind of tag it is. { TiXmlNode* node = Identify( p, encoding ); if ( node ) { p = node->Parse( p, &data, encoding ); if (node->ToDeclaration()) { if (haveSeenDeclaration) { delete node; node=0; // ignore duplicate Declaration } else haveSeenDeclaration = true; } if (node) LinkEndChild( node ); } else { // If Identify fails then no further parsing is possible. break; } } // Did we get encoding info? if ( encoding == TIXML_ENCODING_UNKNOWN && node && node->ToDeclaration() ) { TiXmlDeclaration* dec = node->ToDeclaration(); const char* enc = dec->Encoding(); assert( enc ); if ( *enc == 0 ) encoding = TIXML_ENCODING_UTF8; else if ( StringEqual( enc, "UTF-8", true, TIXML_ENCODING_UNKNOWN ) ) encoding = TIXML_ENCODING_UTF8; else if ( StringEqual( enc, "UTF8", true, TIXML_ENCODING_UNKNOWN ) ) encoding = TIXML_ENCODING_UTF8; // incorrect, but be nice else encoding = TIXML_ENCODING_LEGACY; } pWithWhiteSpace = p; p = SkipWhiteSpace( p, encoding ); } // Was this empty? if ( !firstChild ) { SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, encoding ); return 0; } // All is well. return p; }
GpxSimpleElement::GpxSimpleElement(const wxString &element_name, const wxString &element_value) : TiXmlElement(element_name.ToUTF8()) { TiXmlText * value = new TiXmlText(element_value.ToUTF8()); LinkEndChild(value); }
TiXmlElement* mitk::TransferFunctionPropertySerializer::Serialize() { if (const TransferFunctionProperty* prop = dynamic_cast<const TransferFunctionProperty*>(mitk::BasePropertySerializer::m_Property.GetPointer())) { LocaleSwitch localeSwitch("C"); TransferFunction* transferfunction = prop->GetValue(); if (!transferfunction) return nullptr; auto element = new TiXmlElement("TransferFunction"); // serialize scalar opacity function auto scalarOpacityPointlist = new TiXmlElement( "ScalarOpacity" ); TransferFunction::ControlPoints scalarOpacityPoints = transferfunction->GetScalarOpacityPoints(); for ( auto iter = scalarOpacityPoints.begin(); iter != scalarOpacityPoints.end(); ++iter ) { auto pointel = new TiXmlElement("point"); pointel->SetAttribute("x", boost::lexical_cast<std::string>(iter->first)); pointel->SetAttribute("y", boost::lexical_cast<std::string>(iter->second)); scalarOpacityPointlist->LinkEndChild( pointel ); } element->LinkEndChild( scalarOpacityPointlist ); // serialize gradient opacity function auto gradientOpacityPointlist = new TiXmlElement( "GradientOpacity" ); TransferFunction::ControlPoints gradientOpacityPoints = transferfunction->GetGradientOpacityPoints(); for ( auto iter = gradientOpacityPoints.begin(); iter != gradientOpacityPoints.end(); ++iter ) { auto pointel = new TiXmlElement("point"); pointel->SetAttribute("x", boost::lexical_cast<std::string>(iter->first)); pointel->SetAttribute("y", boost::lexical_cast<std::string>(iter->second)); gradientOpacityPointlist->LinkEndChild( pointel ); } element->LinkEndChild( gradientOpacityPointlist ); // serialize color function vtkColorTransferFunction* ctf = transferfunction->GetColorTransferFunction(); if (ctf == nullptr) return nullptr; auto pointlist = new TiXmlElement("Color"); for (int i = 0; i < ctf->GetSize(); i++ ) { double myVal[6]; ctf->GetNodeValue(i, myVal); auto pointel = new TiXmlElement("point"); pointel->SetAttribute("x", boost::lexical_cast<std::string>(myVal[0])); pointel->SetAttribute("r", boost::lexical_cast<std::string>(myVal[1])); pointel->SetAttribute("g", boost::lexical_cast<std::string>(myVal[2])); pointel->SetAttribute("b", boost::lexical_cast<std::string>(myVal[3])); pointel->SetAttribute("midpoint", boost::lexical_cast<std::string>(myVal[4])); pointel->SetAttribute("sharpness", boost::lexical_cast<std::string>(myVal[5])); pointlist->LinkEndChild( pointel ); } element->LinkEndChild( pointlist ); return element; } else return nullptr; }
const char* TiXmlElement::ReadValue( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ) { TiXmlDocument* document = GetDocument(); // Read in text and elements in any order. const char* pWithWhiteSpace = p; p = SkipWhiteSpace( p, encoding ); while ( p && *p ) { if ( *p != '<' ) { // Take what we have, make a text element. TiXmlText* textNode = new TiXmlText( "" ); if ( !textNode ) { return 0; } if ( TiXmlBase::IsWhiteSpaceCondensed() ) { p = textNode->Parse( p, data, encoding ); } else { // Special case: we want to keep the white space // so that leading spaces aren't removed. p = textNode->Parse( pWithWhiteSpace, data, encoding ); } if ( !textNode->Blank() ) LinkEndChild( textNode ); else delete textNode; } else { // We hit a '<' // Have we hit a new element or an end tag? This could also be // a TiXmlText in the "CDATA" style. if ( StringEqual( p, "</", false, encoding ) ) { return p; } else { TiXmlNode* node = Identify( p, encoding ); if ( node ) { p = node->Parse( p, data, encoding ); LinkEndChild( node ); } else { return 0; } } } pWithWhiteSpace = p; p = SkipWhiteSpace( p, encoding ); } if ( !p ) { if ( document ) document->SetError( TIXML_ERROR_READING_ELEMENT_VALUE, 0, 0, encoding ); } return p; }
void GpxTrksegElement::AppendTrkPoint(GpxWptElement *trkpt) { //FIXME: can be reused for route and track segment LinkEndChild(trkpt); }
void GpxRteElement::AppendRtePoint(GpxWptElement *rtept) { //FIXME: doesn't care about order so it can be absolutely wrong, have to redo this code if it has to be used by something else than the constructor //FIXME: can be reused for route and track segment LinkEndChild(rtept); }
const char* TiXmlDocument::Parse( const char* p, TiXmlParsingData* prevData, TiXmlEncoding encoding ) { ClearError(); // Parse away, at the document level. Since a document // contains nothing but other tags, most of what happens // here is skipping white space. if ( !p || !*p ) { SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); return 0; } // Note that, for a document, this needs to come // before the while space skip, so that parsing // starts from the pointer we are given. location.Clear(); if ( prevData ) { location.row = prevData->cursor.row; location.col = prevData->cursor.col; } else { location.row = 0; location.col = 0; } TiXmlParsingData data( p, TabSize(), location.row, location.col ); location = data.Cursor(); if ( encoding == TIXML_ENCODING_UNKNOWN ) { // Check for the Microsoft UTF-8 lead bytes. const unsigned char* pU = (const unsigned char*)p; if ( *(pU+0) && *(pU+0) == TIXML_UTF_LEAD_0 && *(pU+1) && *(pU+1) == TIXML_UTF_LEAD_1 && *(pU+2) && *(pU+2) == TIXML_UTF_LEAD_2 ) { encoding = TIXML_ENCODING_UTF8; useMicrosoftBOM = true; } } p = SkipWhiteSpace( p, encoding ); if ( !p ) { SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); return 0; } while ( p && *p ) { TiXmlNode* node = Identify( p, encoding ); if ( node ) { p = node->Parse( p, &data, encoding ); LinkEndChild( node ); } else { break; } // Did we get encoding info? if ( encoding == TIXML_ENCODING_UNKNOWN && node->ToDeclaration() ) { TiXmlDeclaration* dec = node->ToDeclaration(); const char* enc = dec->Encoding(); assert( enc ); if ( *enc == 0 ) encoding = TIXML_ENCODING_UTF8; else if ( StringEqual( enc, "UTF-8", true, TIXML_ENCODING_UNKNOWN ) ) encoding = TIXML_ENCODING_UTF8; else if ( StringEqual( enc, "UTF8", true, TIXML_ENCODING_UNKNOWN ) ) encoding = TIXML_ENCODING_UTF8; // incorrect, but be nice else encoding = TIXML_ENCODING_LEGACY; } p = SkipWhiteSpace( p, encoding ); } // Was this empty? if ( !firstChild ) { SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, encoding ); return 0; } // All is well. return p; }
void SoapServerInternal::GenerateWsdl() { tinyxml2::XMLDocument doc; auto root = doc.NewElement("wsdl:definitions"); root->SetAttribute("name", "BGSService"); root->SetAttribute("targetNamespace", "http://battle.net"); int x = 0; while (s_Namespaces[x]) { root->SetAttribute(s_Namespaces[x], s_Namespaces[x + 1]); x += 2; }; doc.LinkEndChild(root); auto types = doc.NewElement("wsdl:types"); auto schema = doc.NewElement("xs:schema"); schema->SetAttribute("elementFormDefault", "qualified"); schema->SetAttribute("targetNamespace", "http://battle.net/types"); schema->SetAttribute("xmlns:tns", "http://battle.net"); schema->SetAttribute("xmlns:xs", "http://www.w3.org/2001/XMLSchema"); map<string, ClassBinding>::iterator it = m_classBindings.begin(); for (; it != m_classBindings.end(); ++it) { vector<tinyxml2::XMLElement*> nodes = it->second.GenerateWsdl(&doc); for (size_t y = 0; y < nodes.size(); ++y) { schema->LinkEndChild(nodes[y]); } } map<string, ServiceBinding>::iterator sit = m_soapMappings.begin(); for (; sit != m_soapMappings.end(); ++sit) { vector<tinyxml2::XMLElement*> nodes = sit->second.GenerateWsdlElements(&doc); for (size_t y = 0; y < nodes.size(); ++y) { schema->LinkEndChild(nodes[y]); } } types->LinkEndChild(schema); root->LinkEndChild(types); sit = m_soapMappings.begin(); tinyxml2::XMLElement* portType = doc.NewElement("wsdl:portType"); portType->SetAttribute("name", "IBGSService"); tinyxml2::XMLElement* binding = doc.NewElement("wsdl:binding"); binding->SetAttribute("name", "BGSService"); binding->SetAttribute("type", "tns:IBGSService"); tinyxml2::XMLElement* transport = doc.NewElement("soap:binding"); transport->SetAttribute("transport", "http://schemas.microsoft.com/soap/tcp"); binding->LinkEndChild(transport); tinyxml2::XMLElement* service = doc.NewElement("wsdl:service"); service->SetAttribute("name", "BGSService"); for (; sit != m_soapMappings.end(); ++sit) { auto r = sit->second.GenerateWsdl(&doc); for (size_t y = 0; y < r.size(); ++y) { root->LinkEndChild(r[y]); } r = sit->second.GenerateWsdlPortTypeOperations(&doc); for (size_t y = 0; y < r.size(); ++y) { portType->LinkEndChild(r[y]); } r = sit->second.GenerateWsdlBindingOperations(&doc); for (size_t y = 0; y < r.size(); ++y) { binding->LinkEndChild(r[y]); } } root->LinkEndChild(portType); root->LinkEndChild(binding); tinyxml2::XMLElement* port = doc.NewElement("wsdl:port"); port->SetAttribute("name", "BGSService"); port->SetAttribute("binding", "tns:BGSService"); tinyxml2::XMLElement* address = doc.NewElement("soap:address"); address->SetAttribute("location", "net.tcp://localhost:666/battlenet/BGSService"); port->LinkEndChild(address); service->LinkEndChild(port); root->LinkEndChild(service); doc.SaveFile(m_wsdlPath.c_str()); }