写网站论文怎么做的,学做网站卖东西去哪学,天津百度分公司,自己怎么设置会员网站相关链接
C —— Tinyxml2在Vs2017下相关使用1#xff08;附源码#xff09; tinyxml2简介 TinyXML2是一个简单#xff0c;小巧#xff0c;高效#xff0c;CXML解析器#xff0c;可以很容易地集成到其他程序中。TinyXML-2解析一个XML文档#xff0c;并从中构建一个 可以…相关链接
C —— Tinyxml2在Vs2017下相关使用1附源码 tinyxml2简介 TinyXML2是一个简单小巧高效CXML解析器可以很容易地集成到其他程序中。TinyXML-2解析一个XML文档并从中构建一个 可以读取、修改和保存的文档对象模型 DOM。XML代表“可扩展标记语言”。这是一个通用目的 用于描述任意数据的人类和机器可读标记语言。 为存储应用程序数据而创建的所有随机文件格式都可以 全部替换为 XML。一个解析器可以解决所有问题。 源码下载 Github - Tinyxml2源码下载地址 一般来说下载源码后无需编译仅将其中的tinyxml2.cpp、tinyxml2.h包含在自己的项目中就可以使用了。 若需构建库使用CMake构建源码然后利用Vs仅编译tinyxml2项目。 使用tinyxml2注意事项 TinyXML与实体
TinyXML认得预定义的特殊“字符实体”即: apos; ‘
这些在XML文档读取时都会被辨认出来并会被转化成等价的UTF-8字符。代码写入xml
?xml version1.0 encodingUTF-8?
Project DefaultTargetsBuild ToolsVersion15.0 xmlnshttp://schemas.microsoft.com/developer/msbuild/2003ItemGroup LabelProjectConfigurationsProjectConfigurations IncludeDebug|X64ConfigurationDebug/ConfigurationPlatformx64/Platform/ProjectConfigurationsProjectConfiguration IncludeRelease|X64ConfigurationRelease/ConfigurationPlatformx64/Platform/ProjectConfiguration/ItemGroupImport Project$(VCTargetsPath)\Microsoft.Cpp.Default.props/Import Project$(VCTargetsPath)\Microsoft.Cpp.props/ImportGroup ConditionExists(apos;$(QtMsBuild)\qt_defaults.propsapos;)Import Project$(QtMsBuild)\qt_defaults.props//ImportGroupPropertyGroup Conditionapos;$(Configuration)|$(Platform)apos; apos;Debug|x64apos; LabelQtSettingsQtInstall5.12.4(64)/QtInstallQtModulescore;gui;widgets;network;/QtModulesQtBuildConfigdebug/QtBuildConfig/PropertyGroupTarget NameQtMsBuildNotFound BeforeTargetsCustomBuild;ClCompile Condition!Exists(apos;$(QtMsBuild)\qt.targetsapos;) or !Exists(apos;$(QtMsBuild)\qt.propsapos;)Message ImportanceHigh TextQtMsBuild: could not locate qt.targets, qt.props; project may not build correctly.//TargetImportGroup LabelExtensionSettings/ImportGroup LabelShared/ImportGroup LabelPropertySheets Conditionapos;$(Configuration)|$(Platform)apos; apos;Debug|x64apos;Import Project$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props Conditionexists(apos;$(UserRootDir)\Microsoft.Cpp.$(Platform).user.propsapos;) LabelLocalAppDataPlatform/Import Project$(QtMsBuild)\Qt.props//ImportGroupItemDefinitionGroup Conditionapos;$(Configuration)|$(Platform)apos; apos;Release|x64apos; LabelConfigurationClCompileTreatWChar_tAsBuiltInTypetrue/TreatWChar_tAsBuiltInTypeMultiProcessorCompilationtrue/MultiProcessorCompilationDebugInformationFormatNone/DebugInformationFormatOptimizationMaxSpeed/Optimization/ClCompileLinkSubSystemConsole/SubSystemGenerateDebugInformationfalse/GenerateDebugInformation/Link/ItemDefinitionGroup
/Project#include iostream
#include tinyxml/tinyxml2.hint main()
{
#if 0 // 写入tinyxml2::XMLDocument xml;xml.Parse(?xml version\1.0\ encoding\UTF-8\?);tinyxml2::XMLElement* rootNode xml.NewElement(Project);rootNode-SetAttribute(DefaultTargets, Build);rootNode-SetAttribute(ToolsVersion, 15.0);rootNode-SetAttribute(xmlns, http://schemas.microsoft.com/developer/msbuild/2003);xml.InsertEndChild(rootNode);{tinyxml2::XMLElement *element_ItemGroup xml.NewElement(ItemGroup);element_ItemGroup-SetAttribute(Label, ProjectConfigurations);rootNode-InsertEndChild(element_ItemGroup);{tinyxml2::XMLElement *element_ProjectConfiguration xml.NewElement(ProjectConfigurations);element_ProjectConfiguration-SetAttribute(Include, Debug|X64);element_ItemGroup-InsertEndChild(element_ProjectConfiguration);{tinyxml2::XMLElement *element_ProjectConfiguration_Configuration xml.NewElement(Configuration);element_ProjectConfiguration_Configuration-InsertNewText(Debug);element_ProjectConfiguration-InsertEndChild(element_ProjectConfiguration_Configuration);}{tinyxml2::XMLElement *element_ProjectConfiguration_Platform xml.NewElement(Platform);element_ProjectConfiguration_Platform-InsertNewText(x64);element_ProjectConfiguration-InsertEndChild(element_ProjectConfiguration_Platform);}}{tinyxml2::XMLElement *element_ProjectConfiguration xml.NewElement(ProjectConfiguration);element_ProjectConfiguration-SetAttribute(Include, Release|X64);element_ItemGroup-InsertEndChild(element_ProjectConfiguration);{ tinyxml2::XMLElement *element_ProjectConfiguration_Configuration xml.NewElement(Configuration);element_ProjectConfiguration_Configuration-InsertNewText(Release);element_ProjectConfiguration-InsertEndChild(element_ProjectConfiguration_Configuration);}{tinyxml2::XMLElement *element_ProjectConfiguration_Platform xml.NewElement(Platform);element_ProjectConfiguration_Platform-InsertNewText(x64);element_ProjectConfiguration-InsertEndChild(element_ProjectConfiguration_Platform);}}}{tinyxml2::XMLElement *element_Import xml.NewElement(Import);element_Import-SetAttribute(Project, $(VCTargetsPath)\\Microsoft.Cpp.Default.props);rootNode-InsertEndChild(element_Import);}{tinyxml2::XMLElement *element_Import xml.NewElement(Import);element_Import-SetAttribute(Project, $(VCTargetsPath)\\Microsoft.Cpp.props);rootNode-InsertEndChild(element_Import);}{tinyxml2::XMLElement *element_ImportGroup xml.NewElement(ImportGroup);element_ImportGroup-SetAttribute(Condition, Exists($(QtMsBuild)\\qt_defaults.props));{tinyxml2::XMLElement *element_Import xml.NewElement(Import);element_Import-SetAttribute(Project, $(QtMsBuild)\\qt_defaults.props);element_ImportGroup-InsertEndChild(element_Import);}rootNode-InsertEndChild(element_ImportGroup);}{tinyxml2::XMLElement *element_PropertyGroup xml.NewElement(PropertyGroup);element_PropertyGroup-SetAttribute(Condition, $(Configuration)|$(Platform) Debug|x64);element_PropertyGroup-SetAttribute(Label, QtSettings);{{tinyxml2::XMLElement *element_QtInstall xml.NewElement(QtInstall);element_QtInstall-InsertNewText(5.12.4(64));element_PropertyGroup-InsertEndChild(element_QtInstall);}{tinyxml2::XMLElement *element_QtModules xml.NewElement(QtModules);element_QtModules-InsertNewText(core;gui;widgets;network;);element_PropertyGroup-InsertEndChild(element_QtModules);}{tinyxml2::XMLElement *element_QtBuildConfig xml.NewElement(QtBuildConfig);element_QtBuildConfig-InsertNewText(debug);element_PropertyGroup-InsertEndChild(element_QtBuildConfig);}}rootNode-InsertEndChild(element_PropertyGroup);}{tinyxml2::XMLElement *element_Target xml.NewElement(Target);element_Target-SetAttribute(Name, QtMsBuildNotFound);element_Target-SetAttribute(BeforeTargets, CustomBuild;ClCompile);element_Target-SetAttribute(Condition, !Exists($(QtMsBuild)\\qt.targets) or !Exists($(QtMsBuild)\\qt.props));{tinyxml2::XMLElement *element_Message xml.NewElement(Message);element_Message-SetAttribute(Importance, High);element_Message-SetAttribute(Text, QtMsBuild: could not locate qt.targets, qt.props; project may not build correctly.);element_Target-InsertEndChild(element_Message);}rootNode-InsertEndChild(element_Target);}{tinyxml2::XMLElement *element_ImportGroup xml.NewElement(ImportGroup);element_ImportGroup-SetAttribute(Label, ExtensionSettings);rootNode-InsertEndChild(element_ImportGroup);}{tinyxml2::XMLElement *element_ImportGroup xml.NewElement(ImportGroup);element_ImportGroup-SetAttribute(Label, Shared);rootNode-InsertEndChild(element_ImportGroup);}{tinyxml2::XMLElement *element_ImportGroup xml.NewElement(ImportGroup);element_ImportGroup-SetAttribute(Label, PropertySheets);element_ImportGroup-SetAttribute(Condition, $(Configuration)|$(Platform) Debug|x64);rootNode-InsertEndChild(element_ImportGroup);{tinyxml2::XMLElement *element_Import xml.NewElement(Import);element_Import-SetAttribute(Project, $(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props);element_Import-SetAttribute(Condition, exists($(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props));element_Import-SetAttribute(Label, LocalAppDataPlatform);element_ImportGroup-InsertEndChild(element_Import);}{tinyxml2::XMLElement *element_Import xml.NewElement(Import);element_Import-SetAttribute(Project, $(QtMsBuild)\\Qt.props);element_ImportGroup-InsertEndChild(element_Import);}}{tinyxml2::XMLElement *element_ItemDefinitionGroup xml.NewElement(ItemDefinitionGroup);element_ItemDefinitionGroup-SetAttribute(Condition, $(Configuration)|$(Platform) Release|x64);element_ItemDefinitionGroup-SetAttribute(Label, Configuration);{{tinyxml2::XMLElement *element_ClCompile xml.NewElement(ClCompile);element_ItemDefinitionGroup-InsertEndChild(element_ClCompile);{tinyxml2::XMLElement *element_TreatWChar_tAsBuiltInType xml.NewElement(TreatWChar_tAsBuiltInType);element_TreatWChar_tAsBuiltInType-InsertNewText(true);element_ClCompile-InsertEndChild(element_TreatWChar_tAsBuiltInType);}{tinyxml2::XMLElement *element_TreatWChar_MultiProcessorCompilation xml.NewElement(MultiProcessorCompilation);element_TreatWChar_MultiProcessorCompilation-InsertNewText(true);element_ClCompile-InsertEndChild(element_TreatWChar_MultiProcessorCompilation);}{tinyxml2::XMLElement *element_DebugInformationFormat xml.NewElement(DebugInformationFormat);element_DebugInformationFormat-InsertNewText(None);element_ClCompile-InsertEndChild(element_DebugInformationFormat);}{tinyxml2::XMLElement *element_Optimization xml.NewElement(Optimization);element_Optimization-InsertNewText(MaxSpeed);element_ClCompile-InsertEndChild(element_Optimization);}}{tinyxml2::XMLElement *element_Link xml.NewElement(Link);element_ItemDefinitionGroup-InsertEndChild(element_Link);{tinyxml2::XMLElement *element_SubSystem xml.NewElement(SubSystem);element_SubSystem-InsertNewText(Console);element_Link-InsertEndChild(element_SubSystem);}{tinyxml2::XMLElement *element_GenerateDebugInformation xml.NewElement(GenerateDebugInformation);element_GenerateDebugInformation-InsertNewText(false);element_Link-InsertEndChild(element_GenerateDebugInformation);}}}rootNode-InsertEndChild(element_ItemDefinitionGroup);}xml.SaveFile(./temp_behaviac.xml);xml.Clear();system(pause);return 0;
}代码读取xml int main()
{tinyxml2::XMLDocument xml;tinyxml2::XMLError errXml xml.LoadFile(./temp_behaviac.xml);if (tinyxml2::XML_SUCCESS errXml){tinyxml2::XMLElement* root xml.RootElement();if (root){std::cout root-Value() DefaultTargets root-Attribute(DefaultTargets) ToolsVersion root-Attribute(ToolsVersion) xmlns root-Attribute(xmlns) std::endl;tinyxml2::XMLElement *XMLElement_ItemGroup root-FirstChildElement();if (XMLElement_ItemGroup){std::cout \t XMLElement_ItemGroup-Value() Label XMLElement_ItemGroup-Attribute(Label) std::endl;{tinyxml2::XMLElement *XMLElement_ProjectConfigurations XMLElement_ItemGroup-FirstChildElement();if (!XMLElement_ProjectConfigurations) { return -1; }std::cout \t\t XMLElement_ProjectConfigurations-Value() Include XMLElement_ProjectConfigurations-Attribute(Include) std::endl;{tinyxml2::XMLElement *XMLElement_Configuration XMLElement_ProjectConfigurations-FirstChildElement();if (!XMLElement_Configuration) { return -1; }std::cout \t\t\t XMLElement_Configuration-Value() XMLElement_Configuration-GetText() std::endl;tinyxml2::XMLElement *XMLElement_Platform XMLElement_Configuration-NextSiblingElement();if (!XMLElement_Platform) { return -1; }std::cout \t\t\t XMLElement_Platform-Value() XMLElement_Platform-GetText() std::endl;}tinyxml2::XMLElement *XMLElement_ProjectConfiguration XMLElement_ProjectConfigurations-NextSiblingElement();if (!XMLElement_ProjectConfiguration) { return -1; }std::cout \t\t XMLElement_ProjectConfiguration-Value() Include XMLElement_ProjectConfiguration-Attribute(Include) std::endl;{tinyxml2::XMLElement *XMLElement_Configuration XMLElement_ProjectConfiguration-FirstChildElement();if (!XMLElement_Configuration) { return -1; }std::cout \t\t\t XMLElement_Configuration-Value() XMLElement_Configuration-GetText() std::endl;tinyxml2::XMLElement *XMLElement_Platform XMLElement_Configuration-NextSiblingElement();if (!XMLElement_Platform) { return -1; }std::cout \t\t\t XMLElement_Platform-Value() XMLElement_Platform-GetText() std::endl;}}tinyxml2::XMLElement *XMLElement_Import XMLElement_ItemGroup-NextSiblingElement();if (!XMLElement_Import) { return -1; }std::cout \t XMLElement_Import-Value() Project XMLElement_Import-Attribute(Project) std::endl;tinyxml2::XMLElement *XMLElement_Import2 XMLElement_Import-NextSiblingElement();if (!XMLElement_Import2) { return -1; }std::cout \t XMLElement_Import2-Value() Project XMLElement_Import2-Attribute(Project) std::endl;tinyxml2::XMLElement *XMLElement_ImportGroup XMLElement_Import2-NextSiblingElement();if (!XMLElement_ImportGroup) { return -1; }std::cout \t XMLElement_ImportGroup-Value() Condition XMLElement_ImportGroup-Attribute(Condition) std::endl;{tinyxml2::XMLElement *XMLElement_Import XMLElement_ImportGroup-FirstChildElement();if (!XMLElement_Import) { return -1; }std::cout \t\t XMLElement_Import-Value() Project XMLElement_Import-Attribute(Project) std::endl;}tinyxml2::XMLElement *XMLElement_PropertyGroup XMLElement_ImportGroup-NextSiblingElement();if (!XMLElement_PropertyGroup) { return -1; }std::cout \t XMLElement_PropertyGroup-Value() Condition XMLElement_PropertyGroup-Attribute(Condition) Label XMLElement_PropertyGroup-Attribute(Label) std::endl;{tinyxml2::XMLElement *XMLElement_QtInstall XMLElement_PropertyGroup-FirstChildElement();if (!XMLElement_QtInstall) { return -1; }std::cout \t\t XMLElement_QtInstall-Value() XMLElement_QtInstall-GetText() std::endl;tinyxml2::XMLElement *XMLElement_QtModules XMLElement_QtInstall-NextSiblingElement();if (!XMLElement_QtModules) { return -1; }std::cout \t\t XMLElement_QtModules-Value() XMLElement_QtModules-GetText() std::endl;tinyxml2::XMLElement *XMLElement_QtBuildConfig XMLElement_QtModules-NextSiblingElement();if (!XMLElement_QtBuildConfig) { return -1; }std::cout \t\t XMLElement_QtBuildConfig-Value() XMLElement_QtBuildConfig-GetText() std::endl;}tinyxml2::XMLElement *XMLElement_Target XMLElement_PropertyGroup-NextSiblingElement();if (!XMLElement_Target) { return -1; }std::cout \t XMLElement_Target-Value() Name XMLElement_Target-Attribute(Name) BeforeTargets XMLElement_Target-Attribute(BeforeTargets) Condition XMLElement_Target-Attribute(Condition) std::endl;{tinyxml2::XMLElement *XMLElement_Message XMLElement_Target-FirstChildElement();if (!XMLElement_Message) { return -1; }std::cout \t\t XMLElement_Message-Value() Importance XMLElement_Message-Attribute(Importance) Text XMLElement_Message-Attribute(Text) std::endl;}tinyxml2::XMLElement *XMLElement_ImportGroup1 XMLElement_Target-NextSiblingElement();if (!XMLElement_ImportGroup1) { return -1; }std::cout \t XMLElement_ImportGroup1-Value() Label XMLElement_ImportGroup1-Attribute(Label) std::endl;tinyxml2::XMLElement *XMLElement_ImportGroup2 XMLElement_ImportGroup1-NextSiblingElement();if (!XMLElement_ImportGroup2) { return -1; }std::cout \t XMLElement_ImportGroup2-Value() Label XMLElement_ImportGroup2-Attribute(Label) std::endl;tinyxml2::XMLElement *XMLElement_ImportGroup3 XMLElement_ImportGroup2-NextSiblingElement();if (!XMLElement_ImportGroup3) { return -1; }std::cout \t XMLElement_ImportGroup3-Value() Label XMLElement_ImportGroup3-Attribute(Label) Condition XMLElement_ImportGroup3-Attribute(Condition) std::endl;{tinyxml2::XMLElement *XMLElement_Import XMLElement_ImportGroup3-FirstChildElement();if (!XMLElement_Import) { return -1; }std::cout \t\t XMLElement_Import-Value() Project XMLElement_Import-Attribute(Project) Condition XMLElement_Import-Attribute(Condition) Label XMLElement_Import-Attribute(Label) std::endl;tinyxml2::XMLElement *XMLElement_Import2 XMLElement_Import-NextSiblingElement();if (!XMLElement_Import2) { return -1; }std::cout \t\t XMLElement_Import2-Value() Project XMLElement_Import2-Attribute(Project) std::endl;}tinyxml2::XMLElement *XMLElement_ItemDefinitionGroup XMLElement_ImportGroup3-NextSiblingElement();if (!XMLElement_ItemDefinitionGroup) { return -1; }std::cout \t XMLElement_ItemDefinitionGroup-Value() Condition XMLElement_ItemDefinitionGroup-Attribute(Condition) Label XMLElement_ItemDefinitionGroup-Attribute(Label) std::endl;{tinyxml2::XMLElement *XMLElement_ClCompile XMLElement_ItemDefinitionGroup-FirstChildElement();if (!XMLElement_ClCompile) { return -1; }std::cout \t XMLElement_ClCompile-Value() std::endl;{tinyxml2::XMLElement *XMLElement_TreatWChar_tAsBuiltInType XMLElement_ClCompile-FirstChildElement();if (!XMLElement_TreatWChar_tAsBuiltInType) { return -1; }std::cout \t\t XMLElement_TreatWChar_tAsBuiltInType-Value() XMLElement_TreatWChar_tAsBuiltInType-GetText() std::endl;tinyxml2::XMLElement *XMLElement_MultiProcessorCompilation XMLElement_TreatWChar_tAsBuiltInType-NextSiblingElement();if (!XMLElement_MultiProcessorCompilation) { return -1; }std::cout \t\t XMLElement_MultiProcessorCompilation-Value() XMLElement_MultiProcessorCompilation-GetText() std::endl;tinyxml2::XMLElement *XMLElement_DebugInformationFormat XMLElement_MultiProcessorCompilation-NextSiblingElement();if (!XMLElement_DebugInformationFormat) { return -1; }std::cout \t\t XMLElement_DebugInformationFormat-Value() XMLElement_DebugInformationFormat-GetText() std::endl;tinyxml2::XMLElement *XMLElement_Optimization XMLElement_DebugInformationFormat-NextSiblingElement();if (!XMLElement_Optimization) { return -1; }std::cout \t\t XMLElement_Optimization-Value() XMLElement_Optimization-GetText() std::endl;}tinyxml2::XMLElement *XMLElement_Link XMLElement_ClCompile-NextSiblingElement();if (!XMLElement_Link) { return -1; }std::cout \t XMLElement_Link-Value() std::endl;{tinyxml2::XMLElement *XMLElement_SubSystem XMLElement_Link-FirstChildElement();if (!XMLElement_SubSystem) { return -1; }std::cout \t\t XMLElement_SubSystem-Value() XMLElement_SubSystem-GetText() std::endl;tinyxml2::XMLElement *XMLElement_GenerateDebugInformation XMLElement_SubSystem-NextSiblingElement();if (!XMLElement_GenerateDebugInformation) { return -1; }std::cout \t\t XMLElement_GenerateDebugInformation-Value() XMLElement_GenerateDebugInformation-GetText() std::endl;}}}}root nullptr;}system(pause);return 0;
}笔者 笔者 - jxd