MSXML2::IXMLDOMDocument2Ptr pXMLDocument;
HRESULT hr_ConInitialize;
hr_ConInitialize = CoInitialize(NULL);
if(FAILED(hr_ConInitialize))
{
return 0;
} HRESULT hr= pXMLDocument.CreateInstance(__uuidof(MSXML2::DOMDocument40));
if (!SUCCEEDED(hr))
{
return 0;
}
pXMLDocument->load("news_100701_9.mpf");
MSXML2::IXMLDOMElementPtr pRootNode = pXMLDocument->documentElement;
MSXML2::IXMLDOMNodeListPtr pPersonNodes = pRootNode->selectNodes("Attachments");
CString s;
long size = pPersonNodes->length;
for (i = 0; i<size; i++)
{
MSXML2::IXMLDOMNodePtr pPersonNode = pPersonNodes->item[i];
s.Format("%s",(LPCTSTR)pPersonNode->text);
MessageBox(NULL,s,"XML",MB_OK);
} 从网上找的相似代码该的,还是报异常。
我的
。。下面是XML中的内容,我想获取其中的C:\Documents and Settings\Administrator\桌面\素材\0913R1.files\images\0913R1_c_1.jpg <Attachments>
<Attachment RelPath="C:\Documents and Settings\Administrator\桌面\素材\0913R1.files\images\0913R1_c_1.jpg"/>
<Attachment RelPath="C:\Documents and Settings\Administrator\桌面\素材\0913R1.files\images\0913R1_c_2.jpg"/>
<Attachment RelPath="C:\Documents and Settings\Administrator\桌面\素材\0913R1.files\images\0913R1_c_3.jpg"/>
<Attachment RelPath="images\thumb_01.jpg"/>
<Attachment RelPath="contents.txt"/>
</Attachments>
问题是报的异常在红色部分那里
HRESULT hr_ConInitialize;
hr_ConInitialize = CoInitialize(NULL);
if(FAILED(hr_ConInitialize))
{
return 0;
} HRESULT hr= pXMLDocument.CreateInstance(__uuidof(MSXML2::DOMDocument40));
if (!SUCCEEDED(hr))
{
return 0;
}
pXMLDocument->load("news_100701_9.mpf");
MSXML2::IXMLDOMElementPtr pRootNode = pXMLDocument->documentElement;
MSXML2::IXMLDOMNodeListPtr pPersonNodes = pRootNode->selectNodes("Attachments");
CString s;
long size = pPersonNodes->length;
for (i = 0; i<size; i++)
{
MSXML2::IXMLDOMNodePtr pPersonNode = pPersonNodes->item[i];
s.Format("%s",(LPCTSTR)pPersonNode->text);
MessageBox(NULL,s,"XML",MB_OK);
} 从网上找的相似代码该的,还是报异常。
我的
。。下面是XML中的内容,我想获取其中的C:\Documents and Settings\Administrator\桌面\素材\0913R1.files\images\0913R1_c_1.jpg <Attachments>
<Attachment RelPath="C:\Documents and Settings\Administrator\桌面\素材\0913R1.files\images\0913R1_c_1.jpg"/>
<Attachment RelPath="C:\Documents and Settings\Administrator\桌面\素材\0913R1.files\images\0913R1_c_2.jpg"/>
<Attachment RelPath="C:\Documents and Settings\Administrator\桌面\素材\0913R1.files\images\0913R1_c_3.jpg"/>
<Attachment RelPath="images\thumb_01.jpg"/>
<Attachment RelPath="contents.txt"/>
</Attachments>
问题是报的异常在红色部分那里
MSXML2::IXMLDOMNodeListPtr pPersonNodes = pRootNode->selectNodes("Attachments");
那就帮你顶一下等高手帮你解决了,没用过你这个XML解析类,为了代码能在Windows和Linux用,我一般用的是tinyxml
int err =getlasterror();看下
我习惯用CMark类解析xml文件。很方便的。
// PRootNode即Attachments
CString s;
long size = pRootNode ->length;
for (i = 0; i<size; i++)
{
MSXML2::IXMLDOMNodePtr pPersonNode = pRootNode ->item[i];
s.Format("%s",(LPCTSTR)pPersonNode->text);
MessageBox(NULL,s,"XML",MB_OK);
}
这个类费做爱的劲,享受作孽的滋味。去看一下 c类 超级好用。
费作孽的劲,享受做爱的感受。
昨天晚上刚接触tinyxml,看这很强大,没有在程序中实战过。。