int CXmlBase::GetAttrsOfNode(map<CString, CComBSTR>& mapAttrs, MSXML2::IXMLDOMNodePtr pNode)
{
	MSXML2::IXMLDOMNamedNodeMapPtr pAttrs;
	MSXML2::IXMLDOMNodePtr pAttr;
	HRESULT hr;
	CComBSTR bstrText;
	CString str;
	long lAttrCount = 0;

	mapAttrs.clear();
	
    if (NULL == pNode)
	{
		//WRITELOG("END, pNode为空");
		return 0;
	}

	pAttrs = pNode->Getattributes();
	if (pAttrs == NULL)
	{
		//WRITELOG("END, 取得节点属性集合失败");
		return 0;
	}

	lAttrCount = pAttrs->Getlength();
	for (int i=0; i<lAttrCount; i++)
	{
		pAttr = pAttrs->Getitem(i);
		if (pAttr == NULL)
		{
			//WRITELOG("取得第[%d]个属性为空", i); 
			continue;
		}

		hr = pAttr->get_nodeName(&bstrText);
		if (FAILED(hr))
		{
			//WRITELOG("取得第[%d]个属性名为空", i); 
			continue;
		}
		if (!ConvertBSTR2CString(str, bstrText.m_str))
		{
			//WRITELOG("转换第[%d]个属性名 失败", i); 
			continue;
		}
		hr = pAttr->get_text(&bstrText);
		if (FAILED(hr))
		{
			//WRITELOG("取得第[%d]个属性值 失败,属性[%s]", i, str); 
			continue;
		}
		mapAttrs.insert(make_pair(str, bstrText));
	}
	
	return (int)mapAttrs.size();
}
XMLAttribute XMLElement::getFirstAttribute() const {
    XMLAttribute attr;
    MSXML2::IXMLDOMNamedNodeMapPtr attrs;
    if (nodePtr) {
        if ((nodePtr->get_attributes(&attrs)) == S_OK) {
            if (attrs->Getlength() > 0) {
                attr.attrPtr = attrs->Getitem(0);
            }
        }
    }
    return attr;
}
	CString CXmlNodeWrapper::GetAttribName(int index)
	{
		if (IsValid())
		{
			MSXML2::IXMLDOMNamedNodeMapPtr attribs = m_xmlnode->Getattributes();
			if (attribs)
			{
				MSXML2::IXMLDOMAttributePtr attrib = attribs->Getitem(index);
				if (attrib)
					return (LPCTSTR)attrib->Getname();
			}
		}

		return _T("");
	}
void XmlParser::_parseNodeGetAttributes(MSXML2::IXMLDOMNode *pIDOMNode, XmlNode& node)
{
	MSXML2::IXMLDOMNamedNodeMapPtr attributes = pIDOMNode->attributes;
	BSTR attrName;

	for (int i = 0; i < attributes->Getlength(); i++)
	{
		MSXML2::IXMLDOMNodePtr atrr = attributes->Getitem(i);

		atrr->get_nodeName(&attrName);
		_variant_t val = atrr->GetnodeValue();
		
		wstring name(attrName);
		BSTR b = val.bstrVal;
		wstring value(b);

		XmlAttribute attribute(name, value);
		node.AddAttribute(attribute);
	}
}