CppXsl.cpp
上传用户:sz0451
上传日期:2022-07-29
资源大小:256k
文件大小:1k
- // This is the main project file for VC++ application project
- // generated using an Application Wizard.
- #include "stdafx.h"
- #using <mscorlib.dll>
- #using <System.xml.dll>
- using namespace System;
- using namespace System::Xml;
- using namespace System::Xml::XPath;
- using namespace System::Xml::Xsl;
- // This is the entry point for this application
- #ifdef _UNICODE
- int wmain(void)
- #else
- int main(int argc, char* argv[])
- #endif
- {
- // Check for required arguments
- if (argc < 3)
- {
- Console::WriteLine(S"Usage: CppXsl xml-file stylesheet");
- return -1;
- }
- String* path = new String(argv[1]);
- String* xslpath = new String(argv[2]);
- try
- {
- // Create the XmlDocument to parse the file
- XmlDocument* doc = new XmlDocument();
- // Load the file
- doc->Load(path);
- // Create the navigator and position it
- XPathNavigator* nav = doc->CreateNavigator();
- nav->MoveToRoot();
- // Create the XslTransform and load it
- XslTransform* xslt = new XslTransform();
- xslt->Load(xslpath);
-
- // Create a writer for output
- XmlTextWriter* xtw = new XmlTextWriter(Console::Out);
- xtw->Formatting = Formatting::Indented;
- // Do the transformation
- xslt->Transform(nav, 0, xtw);
- }
- catch(Exception* pe)
- {
- Console::WriteLine(pe->Message);
- }
-
- return 0;
- }