//helper function to append a sub node child to a documentfragment with given name and value:
	HRESULT AddSubNodeToDocumentFragment(
		     IXMLDOMDocument* pDOM, 
		     const wchar_t* wszSubNodeName, 
		     const wchar_t* wszSubNodeValue,
		     IXMLDOMDocumentFragment* pdf	// Release is completed outside
		)
	{
		BSTR bstr = NULL;
		IXMLDOMElement* peSub = NULL;

        HRESULT hr = S_OK;
		do
		{
			bstr = SysAllocString(wszSubNodeName);
			HR_SUCCESSCALL( pDOM->createElement(bstr, &peSub), hr );
            SAFE_BSTR_RELEASE(bstr);
			
			bstr=SysAllocString(wszSubNodeValue);
			HR_SUCCESSCALL( peSub->put_text(bstr), hr );
			HR_SUCCESSCALL( AppendChildToParent(peSub, pdf), hr );
		}while(0);

        //release the com object
        SAFE_COM_RELEASE(peSub);
        //release the bstr
        SAFE_BSTR_RELEASE(bstr);

		return hr;
	}
Beispiel #2
0
HRESULT PlotWindowOpened::AppendXmlProperty(IXMLDOMDocument *pDom, IXMLDOMElement *pParent)
{
	auto SThis = dynamic_pointer_cast<PlotWindowOpened, AsyncObject>(shared_from_this());
	this->DoNow([SThis, pDom, pParent](){

		IXMLDOMElement *pElement = NULL;

		CreateAndAddElementNode(pDom, L"WndName", L"\n\t\t", pParent, &pElement);
		pElement->put_text((_bstr_t)SThis->_name.c_str());

		CreateAndAddElementNode(pDom, L"WndType", L"\n\t\t", pParent, &pElement);
		pElement->put_text(_bstr_t(typeid(*SThis).name()));

		CreateAndAddElementNode(pDom, L"WndNameIsSet", L"\n\t\t", pParent, &pElement);
		pElement->put_text((_bstr_t)SThis->_bNameIsSet);

		CreateAndAddElementNode(pDom, L"WndRectTLX", L"\n\t\t", pParent, &pElement);
		pElement->put_text((_bstr_t)SThis->_rect.TopLeft().x);

		CreateAndAddElementNode(pDom, L"WndRectTLY", L"\n\t\t", pParent, &pElement);
		pElement->put_text((_bstr_t)SThis->_rect.TopLeft().y);

		CreateAndAddElementNode(pDom, L"WndRectBRX", L"\n\t\t", pParent, &pElement);
		pElement->put_text((_bstr_t)SThis->_rect.BottomRight().x);

		CreateAndAddElementNode(pDom, L"WndRectBRY", L"\n\t\t", pParent, &pElement);
		pElement->put_text((_bstr_t)SThis->_rect.BottomRight().y);
	});

	return S_OK;
}
// The original Events list was created to exchange data from RAD with
// other tools, such as INCC.  A columnar text file was defined, where the
// first row in the file representing the columns and titles.
// The RADEventsXML class maintains an array of strings, indexed by the
// type RADEventField, declaring the same column titles. These titles
// are represented in the XML document processed by the class.
//
// Returns:
//	IXMLDOMElement: the constructed Columns node,
//	or a NULL pointer if processing failed.
//
///////////////////////////////////////////////////////
IXMLDOMElement* RADEventsXML::ConstructColumnsNode()
{
	IXMLDOMElement *pColumns = NULL;
	IXMLDOMElement *pTitle = NULL;
	IXMLDOMNode *pIXMLDOMNode = NULL;

	_bstr_t bstr1;
	_bstr_t bstr2;
	HRESULT hr = 0;

	try
	{
		// create <Columns>
		bstr1 = "Columns";
		hr = m_pXMLDom->createElement(bstr1,&pColumns);
		TESTHR(hr);
		AddWhiteSpaceToNode(bstr_wsnt, pColumns);

		// for each title element
		//	create <Title>value</Title>
		bstr2 = "Title";
		for (int i = 0; i < eRADAttMax; i++)
		{
			pTitle = NULL;
			//	create <Title>value</Title> 
			hr = m_pXMLDom->createElement(bstr2,&pTitle);
			TESTHR(hr);

			bstr1 = RADEventsList::Titles[i];
			hr = pTitle->put_text(bstr1); 
			TESTHR(hr);

			//  append it as a child to <Columns>
			hr = pColumns->appendChild(pTitle, &pIXMLDOMNode); 
			TESTHR(hr);
			AddWhiteSpaceToNode(bstr_wsnt, pColumns);
		}
	}
	catch(...)
	{
		dprintf( "%s:%d  HRCALL Failed: %s\n  0x%.8x = %s\n",
			__FILE__, __LINE__, "ConstructColumnsNode Exception" , hr);
	}
	return pColumns;
}