Tinyxml - 如何导出多个文件
Tinyxml - How to export multiple file
大家好 :) 我开发了导出 .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];
它比硬编码更好,但我希望有更好的方法。
大家好 :) 我开发了导出 .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];
它比硬编码更好,但我希望有更好的方法。