Beispiel #1
0
        RelaxngPattern CreateElement(XmlSchemaElement xse)
        {
            if (xse.RefName != XmlQualifiedName.Empty)
            {
                RelaxngRef r = new RelaxngRef();
                r.Name = xse.RefName.Name;
                // namespace means nothing here.
                return(r);
            }

            RelaxngElement re   = new RelaxngElement();
            RelaxngName    name = new RelaxngName();

            name.LocalName = xse.Name;
            re.NameClass   = name;

            XmlSchemaComplexType ct = xse.SchemaType as XmlSchemaComplexType;

            foreach (XmlSchemaAttribute a in ct.Attributes)
            {
                re.Patterns.Add(CreateAttribute(a));
            }

            RelaxngPattern rpart;

            if (ct.Particle == null)
            {
                rpart = new RelaxngEmpty();
            }
            else
            {
                rpart = CreatePatternFromParticle(ct.Particle);
            }

            if (ct.IsMixed)
            {
                if (rpart.PatternType != RelaxngPatternType.Empty)
                {
                    RelaxngMixed mixed = new RelaxngMixed();
                    mixed.Patterns.Add(rpart);
                    rpart = mixed;
                }
                else
                {
                    rpart = new RelaxngText();
                }
            }

            re.Patterns.Add(rpart);

            return(re);
        }
Beispiel #2
0
        private RngInference(XmlReader xmlReader,
                             RelaxngGrammar grammar,
                             bool laxOccurence,
                             bool laxTypeInference)
        {
            this.source           = xmlReader;
            this.grammar          = grammar;
            this.laxOccurence     = laxOccurence;
            this.laxTypeInference = laxTypeInference;
            nsmgr = new XmlNamespaceManager(source.NameTable);

            foreach (RelaxngDefine def in grammar.Defines)
            {
                if (def.Patterns.Count != 1)
                {
                    continue;
                }
                RelaxngElement   e = def.Patterns [0] as RelaxngElement;
                RelaxngAttribute a = def.Patterns [0] as RelaxngAttribute;
                if (e == null && a == null)
                {
                    continue;
                }
                RelaxngName rn = e != null ?
                                 e.NameClass as RelaxngName :
                                 a.NameClass as RelaxngName;
                if (rn == null)
                {
                    continue;
                }
                QName qname = new QName(rn.LocalName,
                                        rn.Namespace);
                if (e != null)
                {
                    elements.Add(qname, def);
                }
                else
                {
                    attributes.Add(qname, def);
                }
            }
        }
Beispiel #3
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);
        }
Beispiel #4
0
        // get attribute definition table.
        private Hashtable CollectAttrTable(RelaxngInterleave attList)
        {
            Hashtable table = new Hashtable();

            if (attList == null)
            {
                return(table);
            }
            foreach (RelaxngPattern p in attList.Patterns)
            {
                RelaxngAttribute a = p as RelaxngAttribute;
                if (a == null)
                {
                    a = (RelaxngAttribute)
                        ((RelaxngOptional)p)
                        .Patterns [0];
                }
                RelaxngName rn = a.NameClass as RelaxngName;
                table.Add(new QName(
                              rn.LocalName, rn.Namespace),
                          a);
            }
            return(table);
        }
Beispiel #5
0
 public void WriteName(RelaxngName n)
 {
     WriteQName(n.LocalName, n.Namespace);
 }