public static int sMain(string [] args) { if (args.Length < 1) { Console.WriteLine("Usage: monodoc2wiki monodoc_xmlfile"); return(1); } XmlDocument doc = new XmlDocument(); #if VALIDATION XmlTextReader xr = new XmlTextReader(args [0]); RelaxngPattern rp = RncParser.ParseRnc(new StreamReader("CLILibraryTypes.rnc")); Console.Error.WriteLine("**** READY ****"); rp.Compile(); Console.Error.WriteLine("**** DONE ****"); RelaxngValidatingReader rvr = new RelaxngValidatingReader(xr, rp); doc.Load(rvr); rvr.Close(); #else doc.Load(args [0]); #endif Monodoc2Wiki instance = new Monodoc2Wiki(); string ret = instance.ProcessNode(doc.DocumentElement); Console.WriteLine(ret); return(0); }
public void InheritDefaultNamespace() { RelaxngPattern g = Compile("Test/XmlFiles/include-default-namespace.rnc"); XmlReader xtr = new XmlTextReader("Test/XmlFiles/include-default-namespace.xml"); RelaxngValidatingReader r = new RelaxngValidatingReader(xtr, g); try { while (!r.EOF) { r.Read(); } } finally { r.Close(); } }
public void SimpleDefaultNamespace() { var g = RncParser.ParseRnc(new StringReader("element e { empty }")); var x = XmlReader.Create(new StringReader("<e/>")); var r = new RelaxngValidatingReader(x, g); try { while (!r.EOF) { r.Read(); } } finally { r.Close(); } }
public static string RelaxNGValidate(string xml, string rngFile) { string r = "\r\n"; // Files must exist. if (!File.Exists(rngFile)) { return("Schema file not found."); } // Grammar. RelaxngPattern p = null; if (Path.GetExtension(rngFile).ToUpper() == ".RNG") { XmlTextReader xtrRng = new XmlTextReader(rngFile); try { p = RelaxngPattern.Read(xtrRng); p.Compile(); } catch (Exception ex1) { return("Schema file has invalid grammar:" + r + rngFile + r + ex1.Message); } finally { xtrRng.Close(); } } else if (Path.GetExtension(rngFile).ToUpper() == ".RNC") { var trRnc = new StreamReader(rngFile); try { p = RncParser.ParseRnc(trRnc); p.Compile(); } catch (Exception ex1) { return("Schema file has invalid grammar:" + r + rngFile + r + ex1.Message); } finally { trRnc.Close(); } } else { return("Unknown schema file extension: " + Path.GetExtension(rngFile)); } byte[] byteArray = Encoding.Default.GetBytes(xml); MemoryStream stream = new MemoryStream(byteArray); // Validate instance. XmlTextReader xtrXml = new XmlTextReader(stream); RelaxngValidatingReader vr = new RelaxngValidatingReader(xtrXml, p); try { while (!vr.EOF) { vr.Read(); } // XML file is valid. return(""); } catch (RelaxngException ex2) { // XML file not valid. return(ex2.Message); } catch (Exception ex3) { // XML file not well-formed. return(ex3.Message); } finally { vr.Close(); xtrXml.Close(); } }