前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >tinyxml怎么找到第二个子节点(有名字一样的节点)

tinyxml怎么找到第二个子节点(有名字一样的节点)

作者头像
用户3519280
发布2023-07-06 15:15:27
2290
发布2023-07-06 15:15:27
举报
文章被收录于专栏:c++ 学习分享c++ 学习分享
代码语言:javascript
复制
void CXmlTestDlg::OnBnClickedOk()
{
    TCHAR appPath[MAX_PATH+1];
    GetModuleFileName(NULL,appPath,MAX_PATH);
    CString str_Path=appPath;
    int pos = str_Path.ReverseFind('\\');
    CString m_File = str_Path.Left(pos+1)+_T("config.xml");

    char xmlFile[256];
    wcstombs(xmlFile,m_File,256);
    TiXmlDocument doc(xmlFile);
    bool loadOkay = doc.LoadFile();
    if (!loadOkay)
    {
        AfxMessageBox(_T("Load failed!"));
        return;
    }
    setlocale( LC_CTYPE, "chs" );

    CharsChange strChange;
    TiXmlNode* node = 0;
    TiXmlNode*nextnode=0;
    TiXmlElement* todoElement = 0;
    node = doc.FirstChild( "system" );
    if (0==node)
        return;
    if (nextnode=node->FirstChild("fontname"))
    {
        todoElement=nextnode->ToElement();
        CString strGet=strChange.doChange(todoElement->GetText()).c_str();
        TRACE(strGet);
    }
    if (nextnode=node->FirstChild("tinyfontsize"))
    {
        todoElement=nextnode->ToElement();
        //    sysEntry.tinyfontsize=8;
        int x;
        todoElement->QueryIntAttribute("size",&x);
        CString strX;
        strX.Format(L"%d",x);
        TRACE(strX);
    }
    if (nextnode=node->FirstChild("backfile"))
    {
        todoElement=nextnode->ToElement();
        CString strGet=strChange.doChange(todoElement->GetText()).c_str();
        TRACE(strGet);
        /*    sysEntry.background=new ImageWrap;
            if(false==sysEntry.background->loadFile(strChange.doChange(todoElement->GetText()).c_str()))
            {
                delete sysEntry.background;
                sysEntry.background=0;
            }*/
    }
    if (nextnode=node->FirstChild("window"))
    {
        todoElement=nextnode->ToElement();
        //    sysEntry.minWindowSize.cx=640;
        //sysEntry.minWindowSize.cy=480;
        int value;
        todoElement->QueryIntAttribute("minWidth",&value);
        //    sysEntry.minWindowSize.cx=value;
        todoElement->QueryIntAttribute("minHeight",&value);
        //sysEntry.minWindowSize.cy=value;
    }
    if (nextnode=node->FirstChild("adjuststatic"))
    {
        TiXmlNode* childNode=0;
        CString strValue;
        if (childNode=nextnode->FirstChild("static"))
        {
            todoElement=childNode->ToElement();
            //    int value;
            std::string value;
            todoElement->QueryValueAttribute("name",&value);
            strValue=strChange.doChange(value).c_str();
            AfxMessageBox(strValue);

            todoElement->QueryValueAttribute("bmplogo",&value);
            strValue=strChange.doChange(value).c_str();
            AfxMessageBox(strValue);
        }
        if (childNode=nextnode->NextSibling("static"))//这里得不到第二个static?????????????????????????????
        {
            todoElement=childNode->ToElement();
            //    int value;
            std::string value;
            todoElement->QueryValueAttribute("name",&value);
            strValue=strChange.doChange(value).c_str();
            AfxMessageBox(strValue);

            todoElement->QueryValueAttribute("bmplogo",&value);
            strValue=strChange.doChange(value).c_str();
            AfxMessageBox(strValue);
        }
    }

}

tinyxml里FirstChild是返回被选节点的第一个子节点,如nextnode->FirstChild("static")),就找到了<static>,如果要找到第二个<static>,要怎么写?

NextSibling方法。

试试childNode->NextSibling("static")

谢谢大家,解决了! 不过遇到难题了,在wince下,2006年版的tinyxml出现错误,提示找不到FirstChild等函数

wince下重新编译后,出现的问题是 1>.\tinyxml.cpp(43)?:?error?C3861:?'fopen_s':?identifier?not?found 1>.\tinyxml.cpp(115)?:?error?C3861:?'_snprintf_s':?identifier?not?found 1>.\tinyxml.cpp(688)?:?error?C3861:?'_snprintf_s':?identifier?not?found 1>.\tinyxml.cpp(710)?:?error?C3861:?'_snprintf_s':?identifier?not?found 1>.\tinyxml.cpp(1243)?:?error?C3861:?'sscanf_s':?identifier?not?found 1>.\tinyxml.cpp(1250)?:?error?C3861:?'sscanf_s':?identifier?not?found 1>.\tinyxml.cpp(1259)?:?error?C3861:?'_snprintf_s':?identifier?not?found 1>.\tinyxml.cpp(1270)?:?error?C3861:?'_snprintf_s':?identifier?not?found 哪位高手知道,要怎么解决啊?

引用?8?楼?arabicsara?的回复:

wince下重新编译后,出现的问题是 1>.\tinyxml.cpp(43)?:?error?C3861:?'fopen_s':?identifier?not?found 1>.\tinyxml.cpp(115)?:?error?C3861:?'_snprintf_s':?identifier?not?found 1>.\tinyxml.cpp(688)?:?error?C3861:?'_……

include <stdio.h>?and?<wchar.h>

如果XML文件不大的话,可以考虑纯文本?正则字符串处理

引用?8?楼?arabicsara?的回复:

wince下重新编译后,出现的问题是 1>.\tinyxml.cpp(43)?:?error?C3861:?'fopen_s':?identifier?not?found 1>.\tinyxml.cpp(115)?:?error?C3861:?'_snprintf_s':?identifier?not?found 1>.\tinyxml.cpp(688)?:?error?C3861:?'_……

解决方法: 1.?在工程->属性->C++->Preprocessor->Preprocessor?Definition里面添加"_LIB;" 如果想用STL的TinyXML的话,添加上TIXML_USE_STL 2.?在tinystr.h和tinyxml.h里面第一行添加: #define?_MSC_VER????????1 这样TinyXML就会调用C标准库了,不会使用CRT.?

本文参与?腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-10-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客?前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与?腾讯云自媒体同步曝光计划? ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
http://www.vxiaotou.com