-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
74 lines (66 loc) · 2.19 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Diagnostics;
using System.IO;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
namespace xsltr
{
class Program
{
static void Main(string[] args)
{
if (args.Length != 3)
{
Console.WriteLine("Usage: xsltr.exe inputXmlFilePath xslTransformationFilePath outputFilePath");
return;
}
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
string xmlfile = args[0];
string xslfile = args[1];
string outfile = args[2];
XPathDocument doc = null;
try
{
doc = new XPathDocument(xmlfile);
}
catch (XmlException e)
{
Console.WriteLine(Path.GetFullPath(xmlfile));
Console.WriteLine(e.Message);
Environment.Exit(1);
}
try
{
XslCompiledTransform transform = new XslCompiledTransform(true);
transform.Load(xslfile);
XmlTextWriter writer = new XmlTextWriter(outfile, null);
transform.Transform(doc, null, writer);
Console.WriteLine(String.Format("{0} in {1}ms", Path.GetFullPath(outfile), stopwatch.ElapsedMilliseconds));
}
catch (XsltException e)
{
Console.WriteLine(e.Message);
Console.WriteLine(String.Format("{0}({1},{2})", e.SourceUri, e.LineNumber, e.LinePosition));
Console.WriteLine(e.InnerException.Message);
Environment.Exit(1);
}
catch (XmlException e)
{
Console.WriteLine(e.Message);
Environment.Exit(1);
}
catch (NullReferenceException e)
{
Console.WriteLine(e.Message);
Environment.Exit(1);
}
catch (Exception e)
{
Console.Write(e.ToString());
Environment.Exit(1);
}
}
}
}