读书人

怎么读写指定的xml文件

发布时间: 2012-02-11 09:51:35 作者: rapoo

如何读写指定的xml文件
如何读写下面指定的xml文件:
我要的信息是:
NAME,ID,Version,ModifiedDate
帮忙分析一下下面的xml???
<?xml version='1.0' encoding='utf-8'?>
<express dateformat="yyyy/M/d H:mm:ss" >
<option>
<columnsetting>
<column width="300" id="title" name="Name" />
<column width="50" id="icon" name="" />
<column width="200" id="id" name="ID" />
<column width="200" id="dateproperties" name="Description Modified Date" />
<column width="200" id="datedocument" name="Attachment Modified Date" />
<column width="300" id="path" name="Path" />
</columnsetting>
<!--type:0 changerequest; type:1 requirement; type:2 feature-->
<pagesetting type="0" text="Change Request" >
<title label="Title" />
<description label="Description" />
<attachment label="File Attachment" />
</pagesetting>
<pagesetting type="1" text="Requirement" >
<title label="Title" />
<description label="Description" />
<attachment label="File Attachment" />
</pagesetting>
<companyinfo>
<name>techexcel</name>
<webserviceurl>http://localhost/KnowledgeWiseService/ClientService.asmx</webserviceurl>
<originaldate>2007/3/29 18:09:26</originaldate>
</companyinfo>
<othersetting>
<cannewfeature>1</cannewfeature>
<cannewrequirement>1</cannewrequirement>
</othersetting>
</option>
<data>
<changerequest id="1001" >
<title/>
<dateproperties/>
<datedocument/>
<path/>
<description>change request description</description>
<attachment/>
<feature id="1301" >
<title>Feature 266</title>
<path/>
<dateproperties>2007/11/5 18:39:09</dateproperties>
<datedocument>2007/3/29 18:09:26</datedocument>
<description></description>
<attachment version="3" hashcode="daa044554545" modifieddate="2007/3/29 18:09:26" id="1" name="attachment1.doc" file="attachment1.doc" modifiedby="JIJId" />
<requirement id="1501" >
<title>Requirement 1</title>
<path/>
<dateproperties>2007/11/5 18:39:09</dateproperties>
<datedocument>2007/3/29 18:09:26</datedocument>
<description></description>
<attachment version="3" hashcode="daa044554545" modifieddate="2007/3/29 18:09:26" id="1" name="attachment2.doc" file="attachment2.doc" modifiedby="JIJId" />


</requirement>
<requirement id="1502" >
<title>Requirement 2</title>
<path/>
<dateproperties>2007/11/5 18:39:09</dateproperties>
<datedocument>2007/1/29 18:09:26</datedocument>
<description></description>
<attachment version="3" hashcode="daa044554545" modifieddate="2007/2/29 18:09:26" id="1" name="attachment3.doc" file="attachment3.doc" modifiedby="JIJId" />
</requirement>
</feature>
<feature id="1302" >
<title>Feature 294</title>
<path/>
<dateproperties>2007/11/5 18:39:09</dateproperties>
<datedocument>1900/1/1 1:01:01</datedocument>
<description></description>
<attachment version="3" hashcode="daa044554545" modifieddate="2007/3/29 18:09:26" id="12" name="attachment5.doc" file="attachment5.doc" modifiedby="JIJId" />
<requirement id="1506" >
<title>Requirement 6</title>
<path/>
<dateproperties>2007/11/5 18:39:09</dateproperties>
<datedocument>2007/3/29 18:09:26</datedocument>
<description></description>
<attachment version="5" hashcode="daa044554545" modifieddate="2002/3/29 18:09:26" id="12" name="attachment6.doc" file="attachment6.doc" modifiedby="JIJId" />
</requirement>
</feature>
<requirement id="1562" >
<title>Requirement 62</title>
<path/>
<dateproperties>2007/11/5 18:39:09</dateproperties>
<datedocument>2007/3/29 8:09:26</datedocument>
<description></description>
<attachment version="5" hashcode="daa044554545" modifieddate="2007/3/9 1:09:26" id="13" name="attachment7.doc" file="attachment7.doc" modifiedby="JIJId" />
</requirement>
</changerequest>
</data>
</express>


[解决办法]
selectSingleNode("//name")
[解决办法]
http://www.polsnet.com/home/tech165_8727.html

参考一下,自己改改
[解决办法]
http://www.codeproject.com/dialog/WndFreePool.asp
[解决办法]
selectSingleNode((_bstr_t)"节点名");找单个节点;
selectNodes(((_bstr_t)"节点名");找具有相同名称的节点返回链表,nextNode()获取链表中的下一个;
selectSingleNode((_bstr_t)"节点名//@属性名"); 找某个节点下的某个属性点
selectNodes((_bstr_t)"节点名//@属性名"); nextNode()

分析一下你要提取的内容,这几个应该够用了

------解决方案--------------------


就以我上面写的为例:如果我要取得feature的节点名要怎样做???
[解决办法]
selectSingleNode((_bstr_t) "//feature "); 总是找不到啊
[解决办法]
一个找节点的完整的例子:

C/C++ code
_bstr_t strTemp;CString m_xmlPath = "C:\\Documents and Settings\\Administrator\\桌面\\XML\\myXml.xml";MSXML::IXMLDOMDocumentPtr pDoc = NULL;pDoc.CreateInstance(__uuidof(MSXML::DOMDocument));pDoc->load(_bstr_t(m_xmlPath));MSXML::IXMLDOMNodePtr pNode = pDoc->documentElement;  // 获取文档的根节点MSXML::IXMLDOMNodePtr pXmlNode = NULL;       // 用于接收selectSingleNode的返回节点                     pXmlNode = pNode->selectSingleNode((_bstr_t)"//yournodename");strTemp = pXmlNode->text;                    // 获取节点的值            AfxMessageBox(strTemp);MSXML::IXMLDOMNodeListPtr pNodeList = NULL;  // 用于接收selectNodes返回的节点列表 多个nodename重名pNodeList = pNode->selectNodes((_bstr_t)"//yournodename");pXmlNode = pNodeList->item[0];               // 获取返回节点列表的第一个节点strTemp = pXmlNode->text;                    // 获取节点的值AfxMessageBox(strTemp);pXmlNode = pNodeList->nextNode();            // 获取节点列表的下一个节点strTemp = pXmlNode->text;AfxMessageBox(strTemp);。。。//节点名//@属性名 也是一样的
[解决办法]
<?xml version="1.0" encoding="utf-8" ?>
-<express dateformat="yyyy/M/d H:mm::SS">
+<option>
+<data>
</express>
有主节点吗
[解决办法]
不好读呀,难
[解决办法]
很简单的

[解决办法]
CMarkup的话:

C/C++ code
CMarkup xml;    if ( xml.Load("D:\\MyXml.xml") )    {       //MessageBox("ok to load MyXml.xml");       xml.ResetMainPos();       if ( xml.FindChildElem("data") )    //查找data节点       {        //MessageBox("data found");        xml.IntoElem();                while ( xml.FindChildElem("changerequest") )        {            //MessageBox("changerequest found!");            xml.IntoElem();                        CString strChangeID = xml.GetAttrib("id")             MessageBox(strChangeID );            //xml.IntoElem();                                                while ( xml.FindChildElem("feature") )//进入layoutCategories的layouts节点            {                 //MessageBox("feature found!");                 xml.IntoElem();                 MessageBox(xml.GetAttrib("id")); //获得在这个模板下的所有页面版式的id                //通过这个id,再访问这个id同名的PageLayout节点,创建控件                 }            xml.OutOfElem();    //指针在LayoutCategory        }xml.OutOfElem();    }
[解决办法]
关注 接分

读书人网 >VC/MFC

热点推荐