3 using System
.Reflection
;
5 using System
.Xml
.Schema
;
7 using BF
= System
.Reflection
.BindingFlags
;
11 public static void Main (string [] args
)
15 } catch (Exception ex
) {
16 Console
.WriteLine ("ERROR: " + ex
.Message
);
20 static void Run (string [] args
)
22 if (args
.Length
< 1) {
23 Console
.WriteLine ("USAGE: mono dtd2xsd.exe instance-xmlfile [output-xsdfile]");
27 if (args
[0].EndsWith (".dtd"))
28 xtr
= new XmlTextReader ("<!DOCTYPE dummy SYSTEM '" + args
[0] + "'><dummy/>",
29 XmlNodeType
.Document
, null);
31 xtr
= new XmlTextReader (args
[0]);
32 XmlSchema xsd
= Dtd2Xsd
.Run (xtr
);
34 xsd
.Write (new StreamWriter (args
[1]));
36 xsd
.Write (Console
.Out
);
42 public static XmlSchema
Run (XmlTextReader xtr
)
44 while (xtr
.NodeType
!= XmlNodeType
.DocumentType
) {
46 throw new Exception ("DTD did not appeare.");
49 // Hacky reflection part
51 BF flag
= BF
.NonPublic
| BF
.Instance
;
53 // In Mono NET_2_0 XmlTextReader is just a wrapper which
54 // does not contain DTD directly.
55 FieldInfo fi
= typeof (XmlTextReader
).GetField ("source", flag
);
57 impl
= fi
.GetValue (xtr
);
59 PropertyInfo pi
= impl
.GetType ().GetProperty ("DTD", flag
);
60 object dtd
= pi
.GetValue (impl
, null);
62 dtd
.GetType ().GetMethod ("CreateXsdSchema", flag
);
63 object o
= mi
.Invoke (dtd
, null);