Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        RelaxngPattern Compile(TextReader reader, string baseUri)
        {
            RncParser      parser = new RncParser(new NameTable());
            RelaxngPattern g      = parser.Parse(reader, baseUri);

            g.Compile();
            return(g);
        }
Exemplo n.º 3
0
 private void LoadSchemaFile(string rngFile)
 {
     using (var rngReader = new XmlTextReader(rngFile))
     {
         relaxPattern = RelaxngPattern.Read(rngReader);
         relaxPattern.Compile();
     }
 }
Exemplo n.º 4
0
        public void CompileRelaxngGrammar()
        {
            loadGrammarFromUrl(TestResourceHelper.GetFullPathOfResource("Test/XmlFiles/relaxng.rng"));
            RelaxngPattern p = reader.ReadPattern();

            Assert.AreEqual(RelaxngPatternType.Grammar, p.PatternType);

            p.Compile();
        }
Exemplo n.º 5
0
        public void CompileRelaxngGrammar()
        {
            loadGrammarFromUrl("Test/XmlFiles/relaxng.rng");
            RelaxngPattern p = reader.ReadPattern();

            Assert.AreEqual(RelaxngPatternType.Grammar, p.PatternType);

            p.Compile();
        }
Exemplo n.º 6
0
    static void RunTest()
    {
        foreach (DirectoryInfo di in new DirectoryInfo(@"relax-ng").GetDirectories())
        {
            XmlTextReader xtr = null;
            FileInfo      fi  = new FileInfo(di.FullName + "/i.rng");
            // Invalid grammar case:
            if (fi.Exists)
            {
                xtr = new XmlTextReader(fi.FullName);
                try {
                    RelaxngPattern.Read(xtr).Compile();
                    Console.WriteLine("Expected error: " + di.Name);
                } catch (RelaxngException ex) {
                } catch (XmlException ex) {
                } catch (ArgumentNullException ex) {
                } catch (UriFormatException ex) {
                } catch (Exception ex) {
                    Console.WriteLine("Unexpected error type : " + di.Name + " : " + ex.Message);
                } finally {
                    xtr.Close();
                }
                continue;
            }

            // Valid grammar case:
            xtr = new XmlTextReader(di.FullName + "/c.rng");
            RelaxngPattern p = null;
            try {
                p = RelaxngPattern.Read(xtr);
                p.Compile();
            } catch (Exception ex) {
                Console.WriteLine("Invalidated grammar: " + di.Name + " : " + ex.Message);
                continue;
            } finally {
                xtr.Close();
            }


            // Instance validation
            foreach (FileInfo inst in di.GetFiles("*.xml"))
            {
                try {
                    RelaxngValidatingReader vr = new RelaxngValidatingReader(new XmlTextReader(inst.FullName), p);
                    if (skip_error)
                    {
                        vr.InvalidNodeFound += RelaxngValidatingReader.IgnoreError;
                    }
                    while (!vr.EOF)
                    {
                        vr.Read();
                    }
                    if (inst.Name.IndexOf("i.") >= 0 && !skip_error)
                    {
                        Console.WriteLine("Incorrectly validated instance: " + di.Name + "/" + inst.Name);
                    }
                } catch (RelaxngException ex) {
                    string path = di.Name + "/" + inst.Name;
                    if (skip_error)
                    {
                        Console.WriteLine("Failed to skip error : " + path + ex.Message);
                    }
                    if (inst.Name.IndexOf("i.") >= 0)
                    {
                        continue;
                    }
                    Console.WriteLine("Invalidated instance: " + path + " : " + ex.Message);
                }
            }
        }
    }
Exemplo n.º 7
0
        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();
            }
        }