XML解析过程中出现<和>怎么办 VC

ladfkjsoj 2013-05-05 02:07:53

问题如图
其中是使用CMarkup解析的
...全文
1458 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
aaseh 2013-06-07
  • 打赏
  • 举报
回复
替换,亲。 .
贪玩的老鼠 2013-05-06
  • 打赏
  • 举报
回复
CString CXMLFile::DescodeName(LPCSTR sz) { CString strDescode=sz; strDescode.Replace("_&"," "); strDescode.Replace(""","\""); // strDescode.Replace("&","&"); strDescode.Replace("<","<"); strDescode.Replace(">",">"); return strDescode; }
  • 打赏
  • 举报
回复
你有CMarkup的源代码吗?如果有的话,直接在里面添加下<相应的解析,那块代码前些日子我刚改过。
void CMarkup::_ParseMetaChar(LPTSTR& pstrText, LPTSTR& pstrDest)
{
    if( pstrText[0] == _T('a') && pstrText[1] == _T('m') && pstrText[2] == _T('p') && pstrText[3] == _T(';') ) {
        *pstrDest++ = _T('&');
        pstrText += 4;
    }
    else if( pstrText[0] == _T('l') && pstrText[1] == _T('t') && pstrText[2] == _T(';') ) {
        *pstrDest++ = _T('<');
        pstrText += 3;
    }
    else if( pstrText[0] == _T('g') && pstrText[1] == _T('t') && pstrText[2] == _T(';') ) {
        *pstrDest++ = _T('>');
        pstrText += 3;
    }
    else if( pstrText[0] == _T('q') && pstrText[1] == _T('u') && pstrText[2] == _T('o') && pstrText[3] == _T('t') && pstrText[4] == _T(';') ) {
        *pstrDest++ = _T('\"');
        pstrText += 5;
    }
    else if( pstrText[0] == _T('a') && pstrText[1] == _T('p') && pstrText[2] == _T('o') && pstrText[3] == _T('s') && pstrText[4] == _T(';') ) {
        *pstrDest++ = _T('\'');
        pstrText += 5;
    }
    else {
        *pstrDest++ = _T('&');
    }
}
VC解析XML--使用CMarkup类解析XML (一) 先讲一下XML的物殊字符,手动填写时注意一下。 字符 字符实体 & &或&#38; ' '或' > &gt;或> < &lt;或&< " "或" (二) CMarkup类的源代码。 这是目前的最新版本; 取出里面的Markup.cpp和Markup.h,导入你的工程里面,CMarkup类就可以用了; (三) 创建一个XML文档。 CMarkup xml; xml.AddElem( "ORDER" ); xml.AddChildElem( "ITEM" ); xml.IntoElem(); xml.AddChildElem( "SN", "132487A-J" ); xml.AddChildElem( "NAME", "crank casing" ); xml.AddChildElem( "QTY", "1" ); xml.Save("c:\\UserInfo.xml"); 效果如下: 132487A-J crank casing 1 (四) 浏览特定元素CMarkup xml; xml.Load("UserInfo.xml");while ( xml.FindChildElem("ITEM") ) { xml.IntoElem(); xml.FindChildElem( "SN" ); CString csSN = xml.GetChildData(); xml.FindChildElem( "QTY" ); int nQty = atoi( xml.GetChildData() ); xml.OutOfElem(); }(五)增加元素和属性添加在最后面,使用的是AddElem;添加在最前面,使用InsertElem。CMarkup xml;xml.Load("c:\\UserInfo.xml"); xml.AddElem( "ORDER" ); xml.IntoElem(); // 进入 ORDER xml.AddElem( "ITEM" ); xml.IntoElem(); // 进入 ITEM xml.AddElem( "SN", "4238764-A" ); //添加元素 xml.AddElem( "NAME", "bearing" );//添加元素 xml.AddElem( "QTY", "15" );//添加元素 xml.OutOfElem(); // 退出 ITEM xml.AddElem( "SHIPMENT" ); xml.IntoElem(); // 进入 SHIPMENT xml.AddElem( "POC" );//添加元素 xml.SetAttrib( "type", "non-emergency");//添加属性 xml.IntoElem(); // 进入 POC xml.AddElem( "NAME", "John Smith");//添加元素 xml.AddElem( "TEL", "555-1234");//添加元素 xml.Save("c:\\UserInfo.xml"); 效果如下: 132487A-J crank casing 1 4238764-A bearing 15 John Smith 555-1234 (六) 修改元素和属性 如将POC的属性type改成:change; 元素TEL改成:123456789 CMarkup xml; if (xml.Load("UserInfo.xml")) { CString strUserID = _T(""); xml.ResetMainPos(); if (xml.FindChildElem("SHIPMENT")) { xml.IntoElem(); if (xml.FindChildElem("POC")) { xml.IntoElem(); CString str_type=xml.GetAttrib("type"); MessageBox(str_type); xml.SetAttrib("type","change"); strUserID = xml.GetData(); if (xml.FindChildElem("TEL")) { xml.IntoElem(); xml.SetData("123456789"); xml.Save("UserInfo.xml"); return; } } } } (七)删除元素: 删除SN=132487A-J的项目。 CMarkup xml; if (xml.Load("UserInfo.xml")) { CString strUserID = _T(""); xml.ResetMainPos(); if (xml.FindChildElem("ITEM")) { xml.IntoElem(); CString str_sn; xml.FindChildElem("SN"); str_sn=xml.GetChildData(); if(str_sn=="132487A-J") { xml.RemoveElem(); xml.Save("UserInfo.xml"); } } }

3,055

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC HTML/XML
社区管理员
  • HTML/XML社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧