Ejemplo n.º 1
0
// Helper function to create a DOM instance:
MSXML2::IXMLDOMDocument * DomFromCOM()
{
    HRESULT hr;
    MSXML2::IXMLDOMDocument *pxmldoc = NULL;

    HRCALL( CoCreateInstance(__uuidof(DOMDocument),
                             NULL,
                             CLSCTX_INPROC_SERVER,
                             __uuidof(MSXML2::IXMLDOMDocument),
                             (void**)&pxmldoc),
            "Create a new DOMDocument");

    HRCALL( pxmldoc->put_async(VARIANT_FALSE),
            "should never fail");
    HRCALL( pxmldoc->put_validateOnParse(VARIANT_FALSE),
            "should never fail");
    HRCALL( pxmldoc->put_resolveExternals(VARIANT_FALSE),
            "should never fail");

    return pxmldoc;
clean:
    if (pxmldoc)
    {
        pxmldoc->Release();
    }
    return NULL;
}
Ejemplo n.º 2
0
TCHAR * CTaskModel::toXMLString(StringBuffer &sb, bool bKids)
{
	BSTR str = 0;
	if(bKids)
	{
		HRESULT hr = m_pNode->get_xml(&str);
		if(hr == S_OK)
		{
			sb.append(str);
			SysFreeString(str);
		}
	}
	else
	{
		//TODO decide best code
		StringBuffer sbXslt(_T("<?xml version=\"1.0\" ?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"><xsl:output method=\"text\" /><xsl:variable name=\"item\" select=\"//task[@taskid='"));
		StringBuffer buf(32);
		sbXslt.append(ModelUtils::toHexString(m_id, buf));
		sbXslt.append(_T("']\" /><xsl:template match=\"/\">&lt;task <xsl:for-each select=\"$item/@*\"><xsl:value-of select=\"name()\" />=&quot;<xsl:value-of select=\".\" />&quot; </xsl:for-each>&gt;<xsl:for-each select=\"$item/*[not(task)]\">&lt;<xsl:value-of select=\"name()\" /> <xsl:for-each select=\"@*\"><xsl:value-of select=\"name()\" />=&quot;<xsl:value-of select=\".\" />&quot; </xsl:for-each>&gt;<xsl:value-of select=\".\" />&lt;/<xsl:value-of select=\"name()\" />&gt;</xsl:for-each>&lt;/task&gt;</xsl:template></xsl:stylesheet>"));

		MSXML2::IXMLDOMDocument *pDoc = 0;
		m_pNode->get_ownerDocument(&pDoc);
		BSTR xslt = SysAllocString(sbXslt);
		XMLTransform xform(xslt);
		HRESULT hr = pDoc->transformNode(xform.m_pStyleSheet, &str);
		//HRESULT hr = m_pNode->transformNode(xform.m_pStyleSheet, &str);
		if(hr == S_OK && str)
		{
			sb.append(str);
			SysFreeString(str);
		}
		else
		{
			DebugBreak();
		}
		SysFreeString(xslt);
		pDoc->Release();
		xslt = 0;
	}
    return sb;
}
Ejemplo n.º 3
0
/*
 * Sends XML to the XMPP server. The XML is stored in an MSXML IXMLDOMDocument
 * object.
 */
STDMETHODIMP XMPP::SendXML(IDispatch* pDisp)
{
	MSXML2::IXMLDOMDocument *pXMLDoc = NULL;
	BSTR xmlString;

	if(pDisp != NULL &&
		SUCCEEDED(pDisp->QueryInterface(IID_IXMLDOMDocument,
			(LPVOID*) &pXMLDoc)) &&
		SUCCEEDED(pXMLDoc->get_xml(&xmlString)))
	{
		m_ConnectionManager.SendText(xmlString);

		::SysFreeString(xmlString);
		pXMLDoc->Release();
	}
	else
	{
		return E_FAIL;
	}
	return S_OK;
}