我正在用 C++ 创建 xml 文件 我写的代码就像在 C++ 中创建编写 xml 文件一样,如下所示
const char* assign =
"<?xml version=\"1.0\" standalone='no' >\n"
"<office>"
"<work>file created</work>"
"</office>";
TiXmlDocument doc( "vls.xml" );
doc.Parse( assign );
if ( doc.Error() )
{
printf( "Error in %s: %s\n", doc.Value(), doc.ErrorDesc() );
exit( 1 );
}
doc.SaveFile();
bool loadOkay = doc.LoadFile();
if ( !loadOkay )
{
printf( "Could not load test file 'vls.xml'. Error='%s'. Exiting.\n", doc.ErrorDesc() );
exit( 1 );
}
else
printf(" 'vls.xml' loaded successfully");
但现在我只需要 XMl 文件中的数据而不是标签 伙计们请帮助我。
最佳答案
我建议阅读 TinyXml documentation ,更具体地说 TiXmlElement documentation .
对于你的特殊情况,我会说它看起来像这样:
TiXmlElement * office = doc.FirstChildElement( "office" );
if( office )
{
TiXmlElement *work = office.FirstChildElement( "work" );
if( work )
{
printf("Work text: %s\n", work.GetText());
}
}
虽然我不是 TinyXml 专家。
仅供引用:
- StackOverflow search function
- Some - Answers - You - should have - considered ....
在问这些琐碎的问题之前,请搜索 Google 和 StackOverflow。
关于c++ - 使用 tinyxml 在 C++ 中解析 xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6531896/