bstr_t CCMSDIntegrator::GetProperty(MSXML2::IXMLDOMNodePtr pNode,bstr_t PropName, bstr_t defaultVal, bstr_t NodeType)
{
	MSXML2::IXMLDOMNodeListPtr properties = pNode->selectNodes(NodeType);
	for(int j=0; j< properties->length; j++)
	{
		MSXML2::IXMLDOMNodePtr pProp = NULL;					
		properties->get_item(j, &pProp);
		MSXML2::IXMLDOMNodePtr pName = pProp->selectSingleNode(bstr_t(".//Name"));
		MSXML2::IXMLDOMNodePtr pValue = pProp->selectSingleNode(bstr_t(".//Value"));
		bstr_t propName =  (pName!=NULL) ? pName->Gettext() : L"None";
		if( propName == PropName)
		{
			return (pValue!=NULL) ? pValue->Gettext() : defaultVal;
		}
	}
	return defaultVal;
}
MappedValues CCMSDIntegrator::GetNameValueProperties(MSXML2::IXMLDOMNodePtr pNode, bstr_t NodeType)
{
	MappedValues namedvalues;
	MSXML2::IXMLDOMNodeListPtr properties= pNode->selectNodes(NodeType);
	for(int j=0; j< properties->length; j++)
	{
		MSXML2::IXMLDOMNodePtr pProp = NULL;					
		properties->get_item(j, &pProp);
		MSXML2::IXMLDOMNodePtr pName = pProp->selectSingleNode(bstr_t(".//Name"));
		MSXML2::IXMLDOMNodePtr pValue = pProp->selectSingleNode(bstr_t(".//Value"));
		bstr_t propName =  (pName!=NULL) ? pName->Gettext() : L"None";
		bstr_t propValue = (pValue!=NULL) ? pValue->Gettext() :  L"None";
		if( propName != bstr_t(L"None") && propValue != bstr_t(L"None"))
		{
			namedvalues[propName]=propValue;
		}
	}
	return namedvalues;
}
Ejemplo n.º 3
0
	CString CXmlNodeWrapper::GetValue(LPCTSTR valueName)
	{
		if (!IsValid())
			return _T("");

		MSXML2::IXMLDOMNodePtr attribute = m_xmlnode->Getattributes()->getNamedItem(valueName);
		if (attribute)
		{
			return (LPCTSTR)attribute->Gettext();
		}
		return _T("");
	}
bstr_t CCMSDIntegrator::GetElement(MSXML2::IXMLDOMNodePtr pNode,bstr_t ElementName, bstr_t defaultVal)
{
	MSXML2::IXMLDOMNodePtr pElement = pNode->selectSingleNode(ElementName);
	return (pElement!=NULL) ? pElement->Gettext() : defaultVal;
}
DataDictionary MTConnectStreamsParser::ParseDataItems()
{
	MSXML2::IXMLDOMNodePtr root = m_pXMLDoc->GetdocumentElement();
	MSXML2::IXMLDOMNodeListPtr nodes = root->selectNodes(_bstr_t("//DeviceStream"));
	DataDictionary data;
	try
	{
		for(int i=0; i< nodes->length; i++)
		{
			MSXML2::IXMLDOMNodePtr pNode = NULL;					
			nodes->get_item(i, &pNode);

			_bstr_t items[3] = {_bstr_t(".//Samples"), _bstr_t(".//Events"), _bstr_t(".//Condition") };
			for(int ii=0; ii<3 ; ii++)
			{
				MSXML2::IXMLDOMNodeListPtr samples = pNode->selectNodes(items[ii]);
				for(int j=0; j< samples->length; j++)
				{
					MSXML2::IXMLDOMNodePtr pSampleHive = NULL;					
					samples->get_item(j, &pSampleHive);

					// Get each child
					MSXML2::IXMLDOMNodeListPtr childs = pSampleHive->childNodes;
					for(int k=0; k< childs->length; k++)
					{
						MSXML2::IXMLDOMNodePtr pSample = NULL;
						ptime datetime;
						std::string name ;
						std::string timestamp;
						std::string sequence;


						childs->get_item(k, &pSample);
						name = (LPCSTR)  GetAttribute(pSample, "name");
						if(name.empty())
							name = (LPCSTR)  GetAttribute(pSample, "dataItemId");
						if(name.empty())
							continue;
						timestamp = (LPCSTR)  GetAttribute(pSample, "timestamp");
						sequence = (LPCSTR)  GetAttribute(pSample, "sequence");

						// Lookup any name remapping to shorten
						if(TagRenames.find(name)!= TagRenames.end())
						{
							name = TagRenames[name];
						}
						if(items[ii] == _bstr_t(".//Samples"))
							data[name]=(LPCSTR) pSample->Gettext();
						else if(items[ii] == _bstr_t(".//Events"))
							data[name]=(LPCSTR) pSample->Gettext();
						else if(items[ii] == _bstr_t(".//Condition"))
						{
							std::string tagname  = (LPCSTR)  GetElement(pSample);
							if(stricmp(tagname.c_str(),"FAULT")==0)
								data[name]="fault";
							else
								data[name]="normal";
						}
					}
				}
			}
		}
	}
	catch(...)
	{
		std::cout<< "MTConnectStreamsParser::ParseDataItems() Exception\n";
	}
	return data;

}