示例#1
0
        private void Run()
        {
            // move to top-level element
            source.MoveToContent();
            int depth = source.Depth;

            if (source.NodeType != XmlNodeType.Element)
            {
                throw new ArgumentException("Argument XmlReader content is expected to be an element.");
            }

            QName qname = new QName(source.LocalName,
                                    source.NamespaceURI);
            RelaxngDefine el = GetGlobalElement(qname);

            if (el == null)
            {
                el = CreateGlobalElement(qname);
                InferElement(el, true);
            }
            else
            {
                InferElement(el, false);
            }
            RelaxngStart start = new RelaxngStart();

            start.Combine = "choice";
            RelaxngRef topRef = new RelaxngRef();

            topRef.Name   = el.Name;
            start.Pattern = topRef;
            grammar.Starts.Add(start);
        }
示例#2
0
 // Note that it might not be used directly when a grammar
 // contains more than one "start" (compact syntax does not
 // support "combine" attribute).
 public void WriteStart(RelaxngStart start)
 {
     w.Write("start");
     if (start.Combine == null)
     {
         w.Write(" = ");
     }
     else
     {
         w.Write(start.Combine.Trim() == "interleave" ?
                 " &= " : " |= ");
     }
     start.Pattern.WriteRnc(this);
     w.WriteLine();
 }
示例#3
0
        RelaxngGrammar DtdXsd2Rng(XmlSchema xsd, string ns)
        {
            g = new RelaxngGrammar();
            g.DefaultNamespace = ns;
            RelaxngStart start = new RelaxngStart();

            g.Starts.Add(start);
            RelaxngChoice choice = new RelaxngChoice();

            start.Pattern = choice;

            // There are only elements.
            foreach (XmlSchemaElement el in xsd.Items)
            {
                RelaxngDefine def = DefineElement(el);
                g.Defines.Add(def);
                RelaxngRef dref = new RelaxngRef();
                dref.Name = def.Name;
                choice.Patterns.Add(dref);
            }

            return(g);
        }