-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ADD_SUBDIRECTORY(src) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
AUX_SOURCE_DIRECTORY(. XMLTRAN_SRC) | ||
ADD_EXECUTABLE(xmltran ${XMLTRAN_SRC}) | ||
ADD_DEPENDENCIES(xmltran mir2x_3rds) | ||
|
||
TARGET_INCLUDE_DIRECTORIES(xmltran PRIVATE ${MIR2X_COMMON_SOURCE_DIR}) | ||
TARGET_INCLUDE_DIRECTORIES(xmltran PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) | ||
TARGET_INCLUDE_DIRECTORIES(xmltran PRIVATE ${CMAKE_CURRENT_LIST_DIR}) | ||
|
||
TARGET_LINK_LIBRARIES(xmltran common) | ||
TARGET_LINK_LIBRARIES(xmltran ${TINYXML2_LIBRARIES} ) | ||
|
||
INSTALL(TARGETS xmltran DESTINATION tools/xmltran) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// from: https://gist.github.com/Lee-swifter/d9cd651b093f0d32b65a2bce47b0ad91 | ||
#include <iostream> | ||
#include "tinyxml2.h" | ||
|
||
using namespace std; | ||
using namespace tinyxml2; | ||
|
||
void xmlTran(tinyxml2::XMLNode* node) { | ||
if(node == nullptr) | ||
return; | ||
|
||
if(node->ToDeclaration()) { | ||
auto declaration = dynamic_cast<tinyxml2::XMLDeclaration*>(node); | ||
cout << "XML 声明,value=" << declaration->Value() << endl; | ||
} | ||
if(node->ToElement()) { | ||
auto element = dynamic_cast<tinyxml2::XMLElement*>(node); | ||
cout << "XML 元素,name=" << element->Name() << ", value=" << element->Value() << endl; | ||
const tinyxml2::XMLAttribute* attribute = element->FirstAttribute(); | ||
while (attribute != nullptr) { | ||
cout << "\t属性 " << attribute->Name() << "=" << attribute->Value() << endl; | ||
attribute = attribute->Next(); | ||
} | ||
} | ||
if(node->ToText()) { | ||
auto text = dynamic_cast<tinyxml2::XMLText*>(node); | ||
cout << "XML 文本:" << text->Value() << endl; | ||
} | ||
if(node->ToComment()) { | ||
auto comment = dynamic_cast<tinyxml2::XMLComment*>(node); | ||
cout << "XML 注释:" << comment->Value() << endl; | ||
} | ||
if(node->ToUnknown()) { | ||
auto unknown = dynamic_cast<tinyxml2::XMLUnknown*>(node); | ||
cout << "XML 未知:" << unknown->Value() << endl; | ||
} | ||
if(node->ToDocument()) { | ||
auto document = dynamic_cast<tinyxml2::XMLDocument*>(node); | ||
cout << "XML 文档:" << document->ErrorName() << endl; | ||
} | ||
|
||
if(node->NoChildren()) { | ||
return; | ||
} | ||
|
||
tinyxml2::XMLNode* child = node->FirstChild(); | ||
while(child != nullptr) { | ||
xmlTran(child); | ||
child = child->NextSibling(); | ||
} | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
if(argc == 2){ | ||
tinyxml2::XMLDocument xmlDoc; | ||
tinyxml2::XMLError error = xmlDoc.LoadFile(argv[1]); | ||
if(error != tinyxml2::XML_SUCCESS) { | ||
std::cout << "Failed to read XML: " << xmlDoc.ErrorStr() << endl; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
xmlTran(&xmlDoc); | ||
return EXIT_SUCCESS; | ||
} | ||
else{ | ||
std::cout << "Usage: xmltran <input.xml>" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
} |