实例简析XPath串函数和XSLT(3)

来源:互联网 时间:2008-09-04 14:16:00 

下面是程序的执行结果。

1.VC6建立Win32控制台应用程序。

2.在stdafx.h中添加下面的代码:


#include <TCHAR.H>
#include <stdio.h>
#include <time.h>
#import "msxml4.dll"
// If this import statement fails, you need to install MSXML 4.0 SP1 from:
//http://msdn.microsoft.com/downloads/sample.asp?url=/MSDN-FILES/027/001/766/msdncompositedoc.xml

#include <msxml2.h>
// If this include statement fails, you need to install MSXML 4.0 SP1 SDK from:
//http://msdn.microsoft.com/downloads/sample.asp?url=/MSDN-FILES/027/001/766/msdncompositedoc.xml
// You also need to add the include file and library search path
// to Visual C++'s list of directories (Tools > Options... > Directories).

using namespace MSXML2;

inline void EVAL_HR( HRESULT _hr )
   { if FAILED(_hr) throw(_hr); }
#define TEMP_SIZE  _MAX_PATH               // size of short buffer
static _TCHAR   szTemp[TEMP_SIZE];         // multipurpose buffer on stack
static DWORD    dwLen;  


3.上面的代码引入MSXML4类型库,包含MSXML头文件,检查HRESULT值并声明了一些全局变量。

4.main函数:


 int main(int argc, char* argv[])
{
 try
 {
  EVAL_HR(CoInitialize(NULL));

  // Make sure that MSXML 4.0 is installed
  if (!isMSXMLInstalled())
   return -1;

  // Make sure that XML and XSL file names are passed
  // as command line parameters
  if (argc < 3)
   // Show proper message here
   return -1;
 
  IXMLDOMDocument2Ptr pXMLDoc = NULL;
  IXMLDOMDocument2Ptr pXSLDoc = NULL;
 
  // Load the XML document
  if (loadDocument(pXMLDoc, argv[1], true))
  {
   // Load the stylesheet
   if (loadDocument(pXSLDoc, argv[2], false))
   {
    _ftprintf(stdout, pXMLDoc->transformNode(pXSLDoc));
   }
   else
   {
    printMSXMLError(pXSLDoc);
   }
  }
  else
  {
   printMSXMLError(pXMLDoc);
  }

 }
 catch(...)
 {//exception handling
 }
 
 _ftprintf(stdout, "\n\nPress Enter to continue...");
 getchar();
 CoUninitialize();
 return 0;
}


5.XML文件和XSLT样式表文件名作为命令行参数传递给应用程序。主函数通过调用isMSXMLInstalled验证    MSXML4.0是否安装。接下来两次调用loadDocument;先是加载XML文档,然后是加载XSLT样式表。 最后调用transformNode进行转换。

标签:
0
投稿

猜你喜欢

  • 在asp中调用sql server的存储过程方法

    2007-08-13 13:28:00
  • 删除多余的属性 xmlns=""

    2010-08-24 18:41:00
  • asp版FCKEditor编辑器的用法

    2008-07-05 12:15:00
  • Asp定时执行操作、各种网页定时操作详解

    2008-06-10 17:32:00
  • 视觉设计的一致性与用户体验

    2010-01-06 13:38:00
  • QQ聊天窗口链接提示效果代码

    2008-12-16 12:59:00
  • 他们是如何不让我的Teleport和Webzip工作的?

    2010-07-14 21:06:00
  • 如何解决国外空间显示乱码问题

    2007-11-18 14:28:00
  • 正则表达式结合数组提取文章中的文件名

    2007-10-12 13:59:00
  • 中国移动G3笔记本全Flash 网站

    2009-04-27 12:51:00
  • css布局自适应高度方法

    2007-05-11 17:03:00
  • sql2000如何完美压缩.mdf文件

    2010-03-03 15:47:00
  • js编写的语法高亮引擎工具

    2008-05-25 13:27:00
  • Oracle新建用户、角色,授权,建表空间的sql语句

    2012-07-11 15:39:24
  • Oracle数据库安全策略分析(二)

    2010-07-31 13:04:00
  • 开源MySQL公司停止提供企业版源代码tar包

    2009-01-14 13:02:00
  • 把网页中的(电话,qq等数字)生成图片的ASP程序

    2011-04-11 10:40:00
  • 客户端数据存储–超越cookies

    2008-01-15 13:01:00
  • asp 根据IP地址自动判断转向分站的代码

    2011-04-14 10:51:00
  • 深入分析SQL Server的数据转换服务

    2008-11-28 15:29:00
  • asp之家 网络编程 m.aspxhome.com