- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
大家好:)我开发了导出.xml
文件(Android dimens文件)的程序。我的程序将导出 dimens_ldpi.xml
、dimens_mdpi.xml
、dimens_hdpi.xml
和 dimens_xhdpi.xml
。说起来容易,我想导出多个相同结构的文件。但我不知道如何轻松导出多个文件。
当前我的来源如下:
//xml type declaration
TiXmlDocument ldpi_doc, mdpi_doc, hdpi_doc, xhdpi_doc;
TiXmlDeclaration* ldpi_pDec1 = new TiXmlDeclaration("1.0", "utf-8", "");
TiXmlDeclaration* mdpi_pDec1 = new TiXmlDeclaration("1.0", "utf-8", "");
TiXmlDeclaration* hdpi_pDec1 = new TiXmlDeclaration("1.0", "utf-8", "");
TiXmlDeclaration* xhdpi_pDec1 = new TiXmlDeclaration("1.0", "utf-8", "");
ldpi_doc.LinkEndChild(ldpi_pDec1);
mdpi_doc.LinkEndChild(mdpi_pDec1);
hdpi_doc.LinkEndChild(hdpi_pDec1);
xhdpi_doc.LinkEndChild(xhdpi_pDec1);
//Root add node
TiXmlElement* ldpi_pRoot = new TiXmlElement("resources");
TiXmlElement* mdpi_pRoot = new TiXmlElement("resources");
TiXmlElement* hdpi_pRoot = new TiXmlElement("resources");
TiXmlElement* xhdpi_pRoot = new TiXmlElement("resources");
ldpi_doc.LinkEndChild(ldpi_pRoot);
mdpi_doc.LinkEndChild(mdpi_pRoot);
hdpi_doc.LinkEndChild(hdpi_pRoot);
xhdpi_doc.LinkEndChild(xhdpi_pRoot);
//Add sub node
TiXmlElement* ldpi_pElem;
TiXmlElement* mdpi_pElem;
TiXmlElement* hdpi_pElem;
TiXmlElement* xhdpi_pElem;
[ SKIP ]
如您所见,这确实是硬编码,但我不想硬编码。有什么方法可以导出到多个文件吗?预先感谢:)
最佳答案
我尝试搜索,但tinyXml
不支持多重导出。所以我使用数组解决了它。 (我不满意,但比原来的好)
我的代码:
#define RESOLUTION_TYPE 4
#define ENCODING new TiXmlDeclaration("1.0", "utf-8", "") //encoding
#define FIRST_NODE new TiXmlElement("resources") //first common node
//xml type declaration
TiXmlDocument doc[RESOLUTION_TYPE];
TiXmlDeclaration* dec[RESOLUTION_TYPE] = { ENCODING, ENCODING, ENCODING, ENCODING };
for (int i = 0; i < RESOLUTION_TYPE; i++){
doc[i].LinkEndChild(dec[i]);
}
//Root add node
TiXmlElement* pRoot[RESOLUTION_TYPE] = { FIRST_NODE, FIRST_NODE, FIRST_NODE, FIRST_NODE };
for (int i = 0; i < RESOLUTION_TYPE; i++) {
doc[i].LinkEndChild(pRoot[i]);
}
//Add sub node
TiXmlElement* pElement[RESOLUTION_TYPE];
它比硬编码更好,但我希望更好的方法在某个地方。
关于c - Tinyxml - 如何导出多个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30576697/
我正在为我的应用程序使用 TinyXml 库,但 TiXmlDocument 对象只能加载 Xml 文件。它如何从字符串加载 Xml。你能告诉我如何做到这一点吗?非常感谢 涂。 最佳答案 您可以使用
有没有人有代码来遍历 TinyXML 中的子树的节点? IE:给定一个父级,遍历它的所有子级和所有子级的子级? 最佳答案 Begemoth 的回答对我来说听起来不错。 这是 TiXmlElement
大家好:)我开发了导出.xml文件(Android dimens文件)的程序。我的程序将导出 dimens_ldpi.xml、dimens_mdpi.xml、dimens_hdpi.xml 和 dim
我想在 xml 文件中添加元素。谁能帮我做到这一点? 以下是我的代码试用。 1.79639 0.430521 2.06832 0.652695
我不知道我做错了什么。我正在用 C++ 编写一个简单的程序来使用 TinyXml 编辑 xml 配置文件。 这是我的配置文件:
你好, 我有以下内容: class pers { public: pers(); std::string name; long favourite_numb
我正在尝试创建一个 XML 签名机制。我的 XML 可以像下面这样: ... ... 事实上,它对 Main 节点下的数据类型是不可知的。我只想计算包含在 Main 节点中的数据的
我有一个看起来像这样的 xml 文件 我正在尝试使用 TinyXML 在最后一个记录元素(具有最高 ID 的那个)之后插入
bool win::checkIfFScreen(sf::RenderWindow &window) { TiXmlDocument doc; TiXmlElement * fulls
我有一个这样的 xml 文件: 我想使用 tinyxml 根据条目名称(例如 (LengthFocalPointToISOCenter))检索所有值(例如 558)。这是我的代码,还没
试图编译 TinyXml++ tutorial使用 CodeBlocks (16.01) 和使用 VS2013,我在以下行遇到相同的错误: ticpp::Element* pElem = doc.Fi
我正在尝试将文件指针 popen 的输出连接到 TinyXML 的输入。 根据主页,最好的方法是使用解析方法: C style input: * based on FILE* * th
我正在尝试使用 TinyXML (c++) 从 xml 文件加载数据。 int height = rootElem->attrib("height", 480); rootElem 是加载的 xml
我正在尝试使用 TinyXml 从属性值中获取 std::string 。我唯一能得到的是 const char * val,而且我找不到任何方法从 const char * 转换为 std::str
我最近开始使用 tinyXML。问题是当我运行我的程序来读取 xml 时,它返回一个访问冲突。一条共同的线是: doc.FirstChildElement("Map")->FirstChildElem
我有一个 XML 文件,其中包含如下几行: B) ?(?&) ?(?E)"> 我在 C++ 中使用 TinyXML 库来解析此 XML 文件,但是当我尝试获取此类行的“pat”属性时,TinyXML
我有一个无法修复的 TinyXML 问题。我已经使用 C++ 扩展了一个 MFC 应用程序来工作。该应用程序进行自动化测试。完成后,它将所有数据保存在一个 XML 文件中。在我的 DOM 树的开头下方
当我尝试执行代码时遇到段错误,它编译时没有错误/警告,但在执行时给出错误段错误。下面是代码片段。 XMLElement *pStartTimeStamp = pRoot->FirstChildElem
我正在使用 tinyxml 来保存来自文本 ctrl 的输入。用户可以将他们喜欢的任何内容复制到文本框中,然后将其写入 xml 文件。我发现新行没有保存,& 字符也没有保存。奇怪的是 tinyxml
我有一个 xml 文件,程序的每个新线程 (BHO) 都使用同一个 Tinyxml 文件。 每次在程序中打开一个新窗口时,它都会运行这段代码: const char * xmlFileName = "
我是一名优秀的程序员,十分优秀!