實例解析XPath串函數和XSLT(3)_Xml教程

      編輯Tag賺U幣
      教程Tag:暫無Tag,歡迎添加,賺取U幣!

      推薦:如何編寫結構完整的XML文檔
      一個XML文檔如果符合一些基本的規范,那它就是結構規范的。XML格式有一套比HTML簡單的解析規則,允許XML解析器不需要外部描述或了解數據含義就可以解析XML數據。 起始標簽和結束

      下面是程序的執行結果。

      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進行轉換。

      分享:淺析XML簡易教程之一
      在Intel的早期,Andy Grove遇到一個雇員 - 他建議公司在芯片的基礎上開發個人計算機。AndyGrove疑問道“個人計算機能做什么呢?”,這個雇員舉例說,它可以存儲處方。Grove考慮到整個研究、開發

      共3頁上一頁123下一頁
      來源:模板無憂//所屬分類:Xml教程/更新時間:2009-06-11
      相關Xml教程