0
我有下面的XML:如何讀取屬性和元素值
<?xml version="1.0" encoding="utf-8" ?>
<lastconnectedServers>
<Server ip="172.24.18.240" domain="MyDomain">
<SharedFolder name="MyShared" type="FTP"/>
<SharedFolder name="Share1" type ="CIFS"/>
<SharedFolder name="Share2" type ="both"/>
</Server>
</lastconnectedServer>
我需要閱讀屬性和節點值。我能夠得到的子節點的數量,但不知道該如何得到的值:
CComPtr<IXMLDOMDocument> pIxmlDOC = NULL;
CComPtr<IXMLDOMParseError> pIxmlDOM = NULL;
CComPtr<IXMLDOMElement> pIxmlServerElement;
CComPtr<IXMLDOMNode> pIxmlServerNode,pIxmlLastConnectedServerNode;
CComPtr<IXMLDOMNodeList> pIXmlNodeChildList = NULL;
IXMLDOMNode* pInsertedNode;
BSTR bstrXML = NULL;
VARIANT vXMLSource;
VARIANT_BOOL bIsSuccess;
HRESULT hr = CoInitialize(NULL);
LONG lChildCount = 0;
CHK_HR(CreateAndInitDOM(&pIxmlDOC));
VariantFromString(L"stocks.xml",vXMLSource);
pIxmlDOC->load(vXMLSource,&bIsSuccess);
pIxmlDOC->get_childNodes(&pIXmlNodeChildList);
pIXmlNodeChildList->get_length(&lChildCount);
for(int i = 0; i < lChildCount; i++)
{
CComPtr<IXMLDOMNamedNodeMap> pIXMLNodeMap;
CComPtr<IXMLDOMNode> pIXMLChildNode;
pIXmlNodeChildList->get_item(i,&pIXMLChildNode);
pIXMLChildNode->get_attributes(&pIXMLNodeMap);
}
您使用哪個庫? – Baltasarq 2010-11-22 11:28:09
@Baltasarq,我正在使用MSXML6 – Simsons 2010-11-22 11:28:59