示例#1
0
//取得节点
MSXML2::IXMLDOMNodePtr CXmlBase::GetNodePtr(LPCTSTR lpszAttrName, LPCTSTR lpszAttrValue
	, MSXML2::IXMLDOMNodePtr pParentNode)
{
	if (lpszAttrName == NULL 
		|| lpszAttrValue == NULL 
		|| pParentNode == NULL) return NULL;

	CComBSTR strCompare = _bstr_t(lpszAttrValue).GetBSTR();
	map<CString, CComBSTR> mapAttrs;
	MSXML2::IXMLDOMNodePtr pNode;
	for (pNode = pParentNode->GetfirstChild(); 
		pNode != NULL; 
		pNode = pNode->GetnextSibling())
	{
		GetAttrsOfNode(mapAttrs, pNode);
		if (mapAttrs[lpszAttrName] != strCompare) continue;
		return pNode;
	}
	return NULL;
}
示例#2
0
//取得节点
MSXML2::IXMLDOMNodePtr CXmlBase::GetFirstChildNodeWithoutComment(MSXML2::IXMLDOMNodePtr pParentNode)
{
	MSXML2::IXMLDOMNodePtr pNode = NULL;
	static const _bstr_t bstr_commentstr("#comment");
	if (pParentNode == NULL) return NULL;
	try
	{
		pNode = pParentNode->GetfirstChild();
		while (pNode != NULL)
		{
			if (pNode->GetnodeName() == bstr_commentstr)
			{
				pNode = pNode->GetnextSibling();
				continue;
			}
			break;
		}
	}
	catch (...)
	{
		return NULL;
	}
	return pNode;
}
示例#3
0
文件: DwgWriter.cpp 项目: giserh/HyDM
//////////////////////////////////////////////////////////////////////////
//简要描述 : 设置扩展属性配置文件
//输入参数 :
//返 回 值 :
//
//
//修改日志 :
//////////////////////////////////////////////////////////////////////////
STDMETHODIMP CDwgWriter::put_XDataXMLConfigFile(BSTR sXMLFile)
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());

    if (sXMLFile == NULL) return S_OK;

    CString sXml = sXMLFile;
    if (sXml.IsEmpty()) return S_OK;

    m_XDataCfgs.RemoveAll();

    try
    {
        CXMLFile xmlfile;
        xmlfile.load(sXml);
        MSXML2::IXMLDOMNodePtr pNode;
        MSXML2::IXMLDOMNodePtr pExtAttrNode = NULL;
        xmlfile.GetNode("LAYERS", pNode);
        if (pNode == NULL)
        {
            //AfxMessageBox("XML配置文件不正确,请检查。");
            m_dwgWriter.WriteLog("XML配置文件不正确,请检查。");
            return S_FALSE;
        }
        pNode = pNode->GetfirstChild();
        if (pNode == NULL)
        {
            //AfxMessageBox("XML配置文件不正确,请检查。");
            m_dwgWriter.WriteLog("XML配置文件不正确,请检查。");
            return S_FALSE;
        }
        CComBSTR bsNodeName;
        CComBSTR bsExtAttrs;
        CString sLayerName;
        CString sRegAppName;
        CString sExtAttrs;
        while (pNode != NULL)
        {
            //得到图层名
            pNode->get_nodeName(&bsNodeName);
            sLayerName = bsNodeName;

            //去掉前面的_前缀,解决数字开头的节点问题
            CString sSign = "";
            sSign = sLayerName.Mid(0, 1);
            if (sSign.CompareNoCase("_") == 0)
            {
                sLayerName = sLayerName.Mid(1);
            }

            XDataAttrLists* pExtAttrs = new XDataAttrLists();
            //得到图层下的注册应用名
            if (pNode->hasChildNodes())
            {
                pExtAttrNode = pNode->GetfirstChild();
                while (pExtAttrNode != NULL)
                {
                    pExtAttrNode->get_nodeName(&bsNodeName);
                    sRegAppName = bsNodeName;

                    //去掉前面的_前缀,解决数字开头的节点问题
                    sSign = sRegAppName.Mid(0, 1);
                    if (sSign.CompareNoCase("_") == 0)
                    {
                        sRegAppName = sRegAppName.Mid(1);
                    }

                    pExtAttrNode->get_text(&bsExtAttrs);
                    sExtAttrs = bsExtAttrs;
                    CStringList* pAttrLst = new CStringList();
                    //解析注册应用名下的属性字段名称
                    CString sAttr;
                    int iPos  = sExtAttrs.Find(',');
                    while (iPos > 0)
                    {
                        sAttr = sExtAttrs.Mid(0, iPos);
                        sExtAttrs = sExtAttrs.Mid(iPos + 1);
                        if (!sAttr.IsEmpty())
                        {
                            pAttrLst->AddTail(sAttr);
                        }
                        iPos  = sExtAttrs.Find(',');
                    }
                    if (iPos == -1)
                    {
                        if (!sExtAttrs.IsEmpty())
                        {
                            pAttrLst->AddTail(sExtAttrs);
                        }
                    }
                    pExtAttrs->SetAt(sRegAppName, pAttrLst);
                    //得到下一个注册应用名的配置
                    pExtAttrNode = pExtAttrNode->GetnextSibling();
                }
            }

            m_XDataCfgs.SetAt(sLayerName, pExtAttrs);
            //得到下一个图层的扩展属性的配置
            pNode = pNode->GetnextSibling();
        }
    }
    catch (...)
    {
		m_dwgWriter.WriteLog("解析XML文件出错,请检查。");
        return S_FALSE;
    }

    return S_OK;
}