Ejemplo n.º 1
0
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();
}
Ejemplo n.º 2
0
bool XMLElement::hasAttributes() const {
    bool found = false;
    MSXML2::IXMLDOMNamedNodeMapPtr attrs;
    if (nodePtr) {
        if ((nodePtr->get_attributes(&attrs)) == S_OK) {
            if (attrs->Getlength() > 0) found = true;
        }
    }
    return found;
}
Ejemplo n.º 3
0
	int CXmlNodeWrapper::NumAttributes()
	{
		if (IsValid())
		{
			MSXML2::IXMLDOMNamedNodeMapPtr attribs = m_xmlnode->Getattributes();
			if (attribs)
				return attribs->Getlength();
		}

		return 0;
	}
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
BOOL WXmlParse::readObject(ExternalObject *objRet, MSXML2::IXMLDOMNodePtr &xmlSubNode)
{
	MSXML2::IXMLDOMNamedNodeMapPtr elementAttributes;
	MSXML2::IXMLDOMNodeListPtr subElementNodes; 
	MSXML2::IXMLDOMNodeListPtr subSubElementNodes; 
	MSXML2::IXMLDOMNodePtr xmlNodeTmp; 
	xmlSubNode->get_attributes(&elementAttributes);

	LONG attrLength;
	attrLength = elementAttributes->Getlength();
	MSXML2::IXMLDOMNodePtr nameNode = elementAttributes->getNamedItem("name");
	MSXML2::IXMLDOMNodePtr clsNode = elementAttributes->getNamedItem("type");
	objRet->objName = nameNode->text;
	objRet->clsName = clsNode->text;
	LONG length, subLength;
	xmlSubNode->get_childNodes(&subElementNodes);
	subElementNodes->get_length(&length);
	objRet->attri.clear();

	for (int i = 0;i < length;i++)
	{
		subElementNodes->get_item(i, &xmlNodeTmp);
		string childName = xmlNodeTmp->nodeName;
		if (strcmp(xmlNodeTmp->nodeName,"child") != 0)
		{
			xmlNodeTmp->get_attributes(&elementAttributes);
			if (!elementAttributes)
				return FALSE;
			MSXML2::IXMLDOMNodePtr typeNode = elementAttributes->getNamedItem("type");
			objRet->attri.push_back(std::make_pair(xmlNodeTmp->nodeName, std::make_pair(typeNode->text, xmlNodeTmp->text)));
		}
		else
		{
			xmlNodeTmp->get_childNodes(&subSubElementNodes);
			subSubElementNodes->get_length(&subLength);
			for (int j = 0;j < subLength;j++)
			{
				ExternalObject *objSub = new ExternalObject();
				subSubElementNodes->get_item(j, &xmlNodeTmp);
				readObject(objSub, xmlNodeTmp);
				objRet->children.push_back(objSub);
			}
		}
	}

	return TRUE;
}
Ejemplo n.º 6
0
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);
	}
}
Ejemplo n.º 7
0
bool CNodeUtil::bReadAttribute(MSXML2::IXMLDOMNode* iNode,
                               std::string& omAttribute, _bstr_t temp)
{
    std::string strTemp;
    bool bResult = false;
    MSXML2::IXMLDOMNamedNodeMapPtr pCodeAttrib;
    MSXML2::IXMLDOMNodePtr iTempNode = nullptr;

    pCodeAttrib = iNode->Getattributes();
    if (pCodeAttrib->Getlength() >= 1)
    {
        iTempNode = pCodeAttrib->getNamedItem(temp);
        if (iTempNode != nullptr)
        {
            omAttribute = _com_util::ConvertBSTRToString(iTempNode->text.GetBSTR());
            bResult = true;
        }
    }
    return bResult;
}