Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » XML » XSLT » Downloads
 
Add your own
alternative version

Using XSLT to render XML data returned by a COM object

, 12 Sep 2001
This is a 3-tier application. A COM component returns SQL data in XML format, then using XSLT to transform to HTML at client side. By using XML, all the data can be sort, split into pages locally, that will give users a quick response!
xmlrs_src.zip
code
xml.xsl
xmlrs
xmlrs.def
xmlrs.dsp
xmlrs.dsw
xmlrs.tlb
xmlrsobj.rgs
xmlrsps.def
xmlrsps.mk
// xmlrsobj.cpp : Implementation of Cxmlrsobj
#include "stdafx.h"
#include "Xmlrs.h"
#include "xmlrsobj.h"

#import "C:\Program Files\Common Files\System\ADO\msado15.dll" \
    named_guids no_namespace rename("EOF", "EndOfFile")

inline void TESTHR(HRESULT x) {if FAILED(x) _com_issue_error(x);};

bool GetRowsOK(_RecordsetPtr pRstTemp,int intNumber,
        _variant_t& avarData);

/////////////////////////////////////////////////////////////////////////////
// Cxmlrsobj

// global variable save the recordset point of Employees table
_RecordsetPtr pRstEmployees = NULL;

STDMETHODIMP Cxmlrsobj::ConnectDB(BSTR bstrConn)
{
	// Get the Innstance of Recordset
    TESTHR(pRstEmployees.CreateInstance(__uuidof(Recordset)));

	// Open the recordset by the specific SELECT
    pRstEmployees->Open("SELECT fName, lName, hire_date "
        "FROM Employee ORDER BY lName", 
		bstrConn, // Connection string comes from the ASP client
        adOpenStatic, adLockReadOnly, adCmdText);

	return S_OK;
}

STDMETHODIMP Cxmlrsobj::GetXmlrs(BSTR *bstrXmlrs)
{
	_bstr_t bstrTmp;

	// Wrap the Recordset into an XML format
	bstrTmp = "<Recordset>";

	while (true)
	{
		bstrTmp += "<Record>";
		bstrTmp += "<fName>";
		bstrTmp += (_bstr_t)pRstEmployees->Fields->Item["fName"]->Value;
		bstrTmp += "</fName><lName>";
		bstrTmp += (_bstr_t)pRstEmployees->Fields->Item["lName"]->Value;
		bstrTmp += "</lName><hire_date>";
		bstrTmp += (_bstr_t)pRstEmployees->Fields->Item["hire_date"]->Value;
		bstrTmp += "</hire_date>";
		bstrTmp += "</Record>";
		pRstEmployees->MoveNext();
		if (pRstEmployees->EndOfFile)
		{
			break;
		}
	}

	bstrTmp += "</Recordset>";

	*bstrXmlrs = bstrTmp.copy();

	return S_OK;
}

STDMETHODIMP Cxmlrsobj::CloseDB()
{
	// Close the database
    pRstEmployees->Close();

	return S_OK;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Alan Wen
Web Developer
China China
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 13 Sep 2001
Article Copyright 2001 by Alan Wen
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid