Ejemplo n.º 1
0
        private void InferComplexContent(RelaxngElement ct, bool isNew)
        {
            bool           makeMixed = false;
            RelaxngPattern content   = GetElementContent(ct);

            if (content != null)
            {
                switch (content.PatternType)
                {
                case RelaxngPatternType.Text:
                case RelaxngPatternType.Data:
                    makeMixed = true;
                    ct.Patterns.Remove(content);
                    ct.Patterns.Add(new RelaxngGroup());
                    break;
                }
            }
            else
            {
                ct.Patterns.Add(new RelaxngGroup());
            }
            InferComplexContentCore(ct, isNew);
            if (makeMixed)
            {
                MarkAsMixed(ct);
            }
        }
Ejemplo n.º 2
0
        RelaxngPattern CreatePatternFromParticle(XmlSchemaParticle xsdp)
        {
            RelaxngSingleContentPattern rngp = null;

            if (xsdp.MinOccurs == 0 && xsdp.MaxOccursString == "unbounded")
            {
                rngp = new RelaxngZeroOrMore();
            }
            else if (xsdp.MinOccurs == 1 && xsdp.MaxOccursString == "unbounded")
            {
                rngp = new RelaxngOneOrMore();
            }
            else if (xsdp.MinOccurs == 0)
            {
                rngp = new RelaxngOptional();
            }

            RelaxngPattern child = CreatePatternFromParticleCore(xsdp);

            if (rngp == null)
            {
                return(child);
            }
            rngp.Patterns.Add(child);
            return(rngp);
        }
Ejemplo n.º 3
0
        public void SimpleRead()
        {
            loadGrammarFromUrl(TestResourceHelper.GetFullPathOfResource("Test/XmlFiles/SimpleElementPattern1.rng"));
            RelaxngPattern p = reader.ReadPattern();

            Assert.AreEqual(RelaxngPatternType.Element, p.PatternType);
        }
Ejemplo n.º 4
0
        // It returns RelaxngAttribute for local attribute, and
        // RelaxngRef for global attribute.
        private RelaxngPattern InferNewAttribute(
            QName attrName, bool isNewTypeDefinition)
        {
            RelaxngPattern p = null;
            bool           mergedRequired = false;

            if (attrName.Namespace.Length > 0)
            {
                // global attribute; might be already defined.
                // (Actually RELAX NG has no concept of "global
                // attributes" but it is still useful to
                // represent attributes in global scope.
                RelaxngDefine attr = GetGlobalAttribute(
                    attrName);
                if (attr == null)
                {
                    attr = CreateGlobalAttribute(attrName);
                    attr.Patterns.Add(CreateSimplePattern(
                                          InferSimpleType(source.Value)));
                }
                else
                {
                    RelaxngAttribute a = attr.Patterns [0] as RelaxngAttribute;
                    if (a != null)
                    {
                        mergedRequired = true;
                    }
                    else
                    {
                        RelaxngOptional opt =
                            (RelaxngOptional)attr.Patterns [0];
                        a = (RelaxngAttribute)opt.Patterns [0];
                    }
                    InferMergedAttribute(a);
                }
                RelaxngRef r = new RelaxngRef();
                r.Name = attr.Name;
                p      = r;
            }
            else
            {
                // local attribute
                RelaxngAttribute a = new RelaxngAttribute();
                a.NameClass = new RelaxngName(
                    attrName.Name, attrName.Namespace);
                a.Pattern = CreateSimplePattern(
                    InferSimpleType(source.Value));
                p = a;
            }
            // optional
            if (laxOccurence ||
                (!isNewTypeDefinition && !mergedRequired))
            {
                RelaxngOptional opt = new RelaxngOptional();
                opt.Patterns.Add(p);
                p = opt;
            }

            return(p);
        }
Ejemplo n.º 5
0
        public void SimpleRead()
        {
            loadGrammarFromUrl("Test/XmlFiles/SimpleElementPattern1.rng");
            RelaxngPattern p = reader.ReadPattern();

            Assert.AreEqual(RelaxngPatternType.Element, p.PatternType);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
 private void LoadSchemaFile(string rngFile)
 {
     using (var rngReader = new XmlTextReader(rngFile))
     {
         relaxPattern = RelaxngPattern.Read(rngReader);
         relaxPattern.Compile();
     }
 }
Ejemplo n.º 8
0
        RelaxngPattern Compile(TextReader reader, string baseUri)
        {
            RncParser      parser = new RncParser(new NameTable());
            RelaxngPattern g      = parser.Parse(reader, baseUri);

            g.Compile();
            return(g);
        }
 /// <summary>
 /// Initializes a new instance of RngVerifier class from specified RelaxNG schema definition
 /// </summary>
 /// <param name="schema">RelaxNG schema definition</param>
 public RngVerifier(string schema)
 {
     using (var rdr = new StringReader(schema))
     {
         XmlTextReader xtrRng = new XmlTextReader(rdr);
         this.rngPattern = RelaxngPattern.Read(xtrRng);
         this.rngPattern.Compile();
     }
 }
Ejemplo n.º 10
0
        public void CompileRelaxngGrammar()
        {
            loadGrammarFromUrl(TestResourceHelper.GetFullPathOfResource("Test/XmlFiles/relaxng.rng"));
            RelaxngPattern p = reader.ReadPattern();

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

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

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

            p.Compile();
        }
        public override NvdlValidatorGenerator CreateGenerator(
            XmlReader reader, NvdlConfig config)
        {
            if (reader.NamespaceURI != RelaxngGrammar.NamespaceURI)
            {
                return(null);
            }

            return(new NvdlRelaxngValidatorGenerator(RelaxngPattern.Read(reader), config));
        }
Ejemplo n.º 13
0
        public void Bug347945()
        {
            string         rng = @"
<element name='x' xmlns='http://relaxng.org/ns/structure/1.0'>
  <interleave>
    <element name='y'><text/></element>
    <element name='z'><text/></element>
  </interleave>
</element>";
            RelaxngPattern p   = RelaxngPattern.Read(new XmlTextReader(rng, XmlNodeType.Document, null));
        }
Ejemplo n.º 14
0
        private void InferTextContent(RelaxngElement ct, bool isNew)
        {
            string         value = source.ReadString();
            RelaxngPattern p     = GetElementContent(ct);

            if (p == null)
            {
                ct.Patterns.Add(CreateSimplePattern(
                                    InferSimpleType(value)));
                return;
            }
            RelaxngPatternList pl = null;

            switch (p.PatternType)
            {
            case RelaxngPatternType.Text:
            case RelaxngPatternType.Data:
                return;                 // no way to narrow it to data.

            case RelaxngPatternType.Empty:
                ct.Patterns.Remove(p);
                ct.Patterns.Add(new RelaxngText());
                return;

            case RelaxngPatternType.Group:
                pl = ((RelaxngBinaryContentPattern)p).Patterns;
                break;

            case RelaxngPatternType.Optional:
            case RelaxngPatternType.ZeroOrMore:
            case RelaxngPatternType.OneOrMore:
                pl = ((RelaxngSingleContentPattern)p).Patterns;
                break;

            default:
                throw Error(p, "Unexpected pattern");
            }
            if (pl.Count > 0 && pl [0] is RelaxngMixed)
            {
                return;
            }
            RelaxngMixed m = new RelaxngMixed();

            while (pl.Count > 0)
            {
                RelaxngPattern child = pl [0];
                m.Patterns.Add(child);
                pl.Remove(child);
            }
            pl.Add(m);
        }
Ejemplo n.º 15
0
        // Change pattern as to allow text content.
        private void MarkAsMixed(RelaxngElement ct)
        {
            RelaxngPattern p = GetElementContent(ct);

            // empty
            if (p == null || p is RelaxngEmpty)
            {
                if (p != null)
                {
                    ct.Patterns.Remove(p);
                }
                ct.Patterns.Add(new RelaxngText());
                return;
            }
            // text
            switch (p.PatternType)
            {
            case RelaxngPatternType.Text:
            case RelaxngPatternType.Data:
            case RelaxngPatternType.Mixed:
                return;

            case RelaxngPatternType.Choice:
            case RelaxngPatternType.Group:
                RelaxngBinaryContentPattern b =
                    (RelaxngBinaryContentPattern)p;
                if (b != null)
                {
                    RelaxngMixed m = b.Patterns [0]
                                     as RelaxngMixed;
                    if (m == null)
                    {
                        m = new RelaxngMixed();
                        while (b.Patterns.Count > 0)
                        {
                            RelaxngPattern child =
                                b.Patterns [0];
                            m.Patterns.Add(child);
                            b.Patterns.Remove(child);
                        }
                        b.Patterns.Add(m);
                    }
                }
                break;

            default:
                throw Error(p, "Not allowed pattern.");
            }
        }
Ejemplo n.º 16
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();
            }
        }
Ejemplo n.º 17
0
        // validate string value agains attr and
        // if invalid, then relax the type.
        private void InferMergedAttribute(RelaxngPattern ap)
        {
            switch (ap.PatternType)
            {
            case RelaxngPatternType.Ref:
                string        refName = ((RelaxngRef)ap).Name;
                RelaxngDefine def     = GetDefine(refName);
                InferMergedAttribute(def.Patterns [0]);
                return;

            case RelaxngPatternType.Optional:
                InferMergedAttribute(
                    ((RelaxngOptional)ap).Patterns [0]);
                return;
            }

            RelaxngAttribute attr = (RelaxngAttribute)ap;

            RelaxngPattern p = attr.Pattern;

            if (p is RelaxngText)
            {
                return;                 // We could do nothing anymore.
            }
            if (p is RelaxngEmpty)
            {
                if (source.Value.Length == 0)
                {
                    return;                     // We can keep empty.
                }
                // We still could infer a choice of empty and
                // data, but it's being too complicated. So
                // here we just set text.
                attr.Pattern = new RelaxngText();
                return;
            }
            RelaxngData data = p as RelaxngData;

            if (data == null)
            {
                throw Error(p, "This inference implementation only allows text, empty and data for an attribute.");
            }
            attr.Pattern = CreateSimplePattern(
                InferMergedType(source.Value,
                                new QName(data.Type, data.DatatypeLibrary)));
        }
Ejemplo n.º 18
0
        private RelaxngPattern GetElementContent(RelaxngElement el)
        {
            if (el.Patterns.Count == 0)
            {
                return(null);
            }
            RelaxngPattern p = el.Patterns [0];

            if (p is RelaxngInterleave)
            {
                return(el.Patterns.Count == 2 ?
                       el.Patterns [1] : null);
            }
            else
            {
                return(p);
            }
        }
        private bool _validateGrammarRules()
        {
            if (!_validateGrammarFormat())
            {
                return(false);
            }

            try
            {
                RelaxngPattern pattern = RelaxngPattern.Read(_grammarReader);
                GrammarRuleError = null;
                return(true);
            }
            catch (RelaxngException e)
            {
                GrammarRuleError = e.Message;
                return(false);
            }
        }
        private NvdlValidatorGenerator CreateRncGenerator(NvdlValidate validate, NvdlConfig config)
        {
            XmlResolver resolver  = config.XmlResolverInternal;
            string      schemaUri = GetSchemaUri(validate);

            if (schemaUri == null)
            {
                return(null);
            }
            Uri            baseUri = resolver.ResolveUri(null, validate.SourceUri);
            Uri            absUri  = resolver.ResolveUri(baseUri, schemaUri);
            RelaxngPattern p       = RncParser.ParseRnc(
                new StreamReader((Stream)resolver.GetEntity(
                                     absUri,
                                     null,
                                     typeof(Stream))), null, absUri.ToString());

            return(new NvdlRelaxngValidatorGenerator(p, config));
        }
Ejemplo n.º 21
0
        private void loadSchemas()
        {
            Assembly ass = Assembly.GetExecutingAssembly();

            if (schemaModel == null)
            {
                System.IO.Stream s = ass.GetManifestResourceStream("doap.rdf");
                schemaStorage = new Storage("memory", "schema", null);
                schemaModel   = new Model(schemaStorage);
                Encoding     e   = Encoding.GetEncoding("utf-8");
                StreamReader r   = new StreamReader(s, e);
                string       txt = r.ReadToEnd();
                parser.ParseStringIntoModel(txt, DoapSchemaUri, schemaModel);
            }
            if (rngSchema == null)
            {
                System.IO.Stream s = ass.GetManifestResourceStream("doap.rng");
                rngSchema = RelaxngPattern.Read(new XmlTextReader(s));
            }
        }
Ejemplo n.º 22
0
        RelaxngPattern CreateAttribute(XmlSchemaAttribute attr)
        {
            RelaxngAttribute ra   = new RelaxngAttribute();
            RelaxngName      name = new RelaxngName();

            name.LocalName = attr.Name;
            ra.NameClass   = name;
            ra.Pattern     = attr.SchemaType != null?
                             CreatePatternFromType(attr.SchemaType) :
                                 CreatePatternFromTypeName(attr.SchemaTypeName);

            RelaxngPattern ret = ra;

            if (attr.Use == XmlSchemaUse.Optional)
            {
                RelaxngOptional opt = new RelaxngOptional();
                opt.Patterns.Add(ra);
                ret = opt;
            }
            return(ret);
        }
Ejemplo n.º 23
0
        private void InferAsEmptyElement(RelaxngElement ct, bool isNew)
        {
            RelaxngPattern content = GetElementContent(ct);

            if (content == null)
            {
                ct.Patterns.Add(new RelaxngEmpty());
                return;
            }

            RelaxngGroup g = content as RelaxngGroup;

            if (g == null)
            {
                return;
            }
            RelaxngOptional opt = new RelaxngOptional();

            opt.Patterns.Add(g);
            ct.Patterns.Remove(content);
            ct.Patterns.Add(opt);
        }
Ejemplo n.º 24
0
        // --- Methods ---
        public ScriptManifestValidationResult Validate(string path)
        {
            try {
                XmlTextReader           xmlReader = new XmlTextReader(path);
                RelaxngValidatingReader validator;

                using (Stream resourceStream
                           = Plug.New("resource://mindtouch.deki.script.check/MindTouch.Deki.Script.ExtensionManifest.rnc").Get().ToStream()) {
                    using (TextReader source = new StreamReader(resourceStream)) {
                        RncParser      parser  = new RncParser(new NameTable());
                        RelaxngPattern pattern = parser.Parse(source);
                        validator = new RelaxngValidatingReader(xmlReader, pattern);
                    }
                }
                while (validator.Read())
                {
                    // do nothing, errors will be reported through exceptions
                }
            } catch (Exception e) {
                return(new ScriptManifestValidationResult(true, e.Message));
            }

            return(new ScriptManifestValidationResult());
        }
Ejemplo n.º 25
0
        public int Process(string [] args)
        {
            string file    = null;
            bool   compact = false;
            string ns      = String.Empty;

            foreach (string arg in args)
            {
                if (arg == "--help")
                {
                    Usage();
                    return(1);
                }
                if (arg == "--compact" || arg == "-c")
                {
                    compact = true;
                }
                else if (file == null)
                {
                    file = arg;
                }
                else if (ns != String.Empty)
                {
                    Usage();
                    Console.Error.WriteLine("Extra command line argument.");
                    return(1);
                }
                else
                {
                    ns = arg;
                }
            }

            XmlTextReader xtr;

            if (file.EndsWith(".dtd"))
            {
                xtr = new XmlTextReader(
                    "<!DOCTYPE dummy SYSTEM '" + file + "'>",
                    XmlNodeType.Document, null);
            }
            else
            {
                xtr = new XmlTextReader(file);
            }
            xtr.Read();
            if (xtr.NodeType == XmlNodeType.XmlDeclaration)
            {
                xtr.Read();
            }

            XmlSchema xsd = GetXmlSchema(xtr);

            RelaxngPattern rng = DtdXsd2Rng(xsd, ns);

            if (compact)
            {
                rng.WriteCompact(Console.Out);
            }
            else
            {
                XmlTextWriter w = new XmlTextWriter(Console.Out);
                w.Formatting = Formatting.Indented;
                rng.Write(w);
                w.Close();
            }
            return(0);
        }
Ejemplo n.º 26
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();
            }
        }
Ejemplo n.º 27
0
        private void ProcessSequence(RelaxngElement ct, RelaxngGroup s,
                                     ref int position, ref bool consumed,
                                     bool isNew)
        {
            RelaxngMixed       m  = s.Patterns.Count > 0 ? s.Patterns [0] as RelaxngMixed : null;
            RelaxngPatternList pl = m != null ?
                                    m.Patterns : s.Patterns;

            for (int i = 0; i < position; i++)
            {
                RelaxngPattern p   = pl [i];
                RelaxngRef     iel = p as RelaxngRef;
                if (iel == null)
                {
                    RelaxngOneOrMore oom =
                        p as RelaxngOneOrMore;
                    iel = (RelaxngRef)oom.Patterns [0];
                }
                if (ElementMatches(iel))
                {
                    // Sequence element type violation
                    // might happen (might not, but we
                    // cannot backtrack here). So switch
                    // to sequence of choice* here.
                    ProcessLax(ToSequenceOfChoice(ct, s));
                    return;
                }
            }

            if (pl.Count <= position)
            {
                QName name = new QName(source.LocalName,
                                       source.NamespaceURI);
                RelaxngDefine nel = GetGlobalElement(name);
                if (nel != null)
                {
                    InferElement(nel, false);
                }
                else
                {
                    nel = CreateGlobalElement(name);                      // used to be CreateElement().
                    InferElement(nel, true);
                }
                RelaxngRef re = new RelaxngRef();
                re.Name = nel.Name;
                pl.Add(re);
                consumed = true;
                return;
            }
            RelaxngPattern c  = pl [position];
            RelaxngRef     el = c as RelaxngRef;

            if (el == null)
            {
                RelaxngOneOrMore oom = c as RelaxngOneOrMore;
                el = (RelaxngRef)oom.Patterns [0];
            }
            if (el == null)
            {
                throw Error(s, String.Format("Target complex type content sequence has an unacceptable type of particle {0}", s.Patterns [position]));
            }
            bool matches = ElementMatches(el);

            if (matches)
            {
                if (consumed && c is RelaxngRef)
                {
                    RelaxngOneOrMore oom = new RelaxngOneOrMore();
                    oom.Patterns.Add(el);
                    pl [position] = oom;
                }
                InferElement(el, false);
                source.MoveToContent();
                switch (source.NodeType)
                {
                case XmlNodeType.None:
                    if (source.NodeType ==
                        XmlNodeType.Element)
                    {
                        goto case XmlNodeType.Element;
                    }
                    else if (source.NodeType ==
                             XmlNodeType.EndElement)
                    {
                        goto case XmlNodeType.EndElement;
                    }
                    break;

                case XmlNodeType.Element:
                    ProcessSequence(ct, s, ref position,
                                    ref consumed, isNew);
                    break;

                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                case XmlNodeType.SignificantWhitespace:
                    MarkAsMixed(ct);
                    source.ReadString();
                    goto case XmlNodeType.None;

                case XmlNodeType.Whitespace:
                    source.ReadString();
                    goto case XmlNodeType.None;

                case XmlNodeType.EndElement:
                    return;

                default:
                    source.Read();
                    break;
                }
            }
            else
            {
                if (consumed)
                {
                    position++;
                    consumed = false;
                    ProcessSequence(ct, s,
                                    ref position, ref consumed,
                                    isNew);
                }
                else
                {
                    ProcessLax(ToSequenceOfChoice(ct, s));
                }
            }
        }
Ejemplo n.º 28
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);
                }
            }
        }
    }
Ejemplo n.º 29
0
        private void InferAttributes(RelaxngElement ct, bool isNew)
        {
            RelaxngInterleave attList = null;
            Hashtable         table   = null;

            do
            {
                if (source.NamespaceURI == NamespaceXmlns)
                {
                    continue;
                }

                if (table == null)
                {
                    attList = GetAttributes(ct);
                    table   = CollectAttrTable(attList);
                }
                QName attrName = new QName(
                    source.LocalName, source.NamespaceURI);
                RelaxngPattern attr = table [attrName]
                                      as RelaxngPattern;
                if (attr == null)
                {
                    if (attList == null)
                    {
                        attList = new RelaxngInterleave();
                        ct.Patterns.Insert(0, attList);
                    }
                    attList.Patterns.Add(
                        InferNewAttribute(
                            attrName, isNew));
                }
                else
                {
                    table.Remove(attrName);
                    if (attrName.Namespace.Length > 0)
                    {
                        RelaxngDefine ga = GetGlobalAttribute(attrName);
                        InferMergedAttribute(
                            ga.Patterns [0]);
                    }
                    else
                    {
                        InferMergedAttribute(attr);
                    }
                }
            } while (source.MoveToNextAttribute());

            // mark all attr definitions that did not appear
            // as optional.
            if (table != null)
            {
                foreach (RelaxngPattern attr in table.Values)
                {
                    if (attr is RelaxngOptional)
                    {
                        continue;
                    }
                    attList.Patterns.Remove(attr);
                    RelaxngOptional opt = new RelaxngOptional();
                    opt.Patterns.Add(attr);
                    attList.Patterns.Add(opt);
                }
            }
        }
Ejemplo n.º 30
0
        private void InferComplexContentCore(RelaxngElement ct,
                                             bool isNew)
        {
            int  position = 0;
            bool consumed = false;

            do
            {
                switch (source.NodeType)
                {
                case XmlNodeType.Element:
                    RelaxngPattern p =
                        GetElementContent(ct);
                    RelaxngGroup g = null;
                    if (p == null)
                    {
                        g = new RelaxngGroup();
                    }
                    switch (p.PatternType)
                    {
                    case RelaxngPatternType.OneOrMore:
                    case RelaxngPatternType.ZeroOrMore:
                        ProcessLax((RelaxngSingleContentPattern)p);
                        break;

                    case RelaxngPatternType.Optional:
                        g = (RelaxngGroup)
                            ((RelaxngOptional)p)
                            .Patterns [0];
                        goto default;

                    case RelaxngPatternType.Group:
                        g = (RelaxngGroup)p;
                        goto default;

                    case RelaxngPatternType.Text:
                    case RelaxngPatternType.Data:
                        g = new RelaxngGroup();
                        g.Patterns.Add(new RelaxngMixed());
                        goto default;

                    default:
                        if (g == null)
                        {
                            throw Error(p, "Unexpected pattern: " + p.PatternType);
                        }
                        ProcessSequence(ct, g,
                                        ref position,
                                        ref consumed,
                                        isNew);
                        break;
                    }
                    source.MoveToContent();
                    break;

                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                case XmlNodeType.SignificantWhitespace:
                    MarkAsMixed(ct);
                    source.ReadString();
                    source.MoveToContent();
                    break;

                case XmlNodeType.EndElement:
                    return;                     // finished

                case XmlNodeType.None:
                    throw new NotImplementedException("Internal Error: Should not happen.");
                }
            } while (true);
        }