RelaxngPattern CreatePatternFromType(XmlSchemaType type) { XmlSchemaSimpleType st = type as XmlSchemaSimpleType; if (st == null) { throw new NotSupportedException("Complex types are not supported as an attribute type."); } XmlSchemaSimpleTypeRestriction r = st.Content as XmlSchemaSimpleTypeRestriction; if (r == null) { throw new NotSupportedException("Only simple type restriction is supported as an attribute type."); } RelaxngChoice c = new RelaxngChoice(); foreach (XmlSchemaFacet f in r.Facets) { XmlSchemaEnumerationFacet en = f as XmlSchemaEnumerationFacet; if (en == null) { throw new NotSupportedException("Only enumeration facet is supported."); } RelaxngValue v = new RelaxngValue(); v.Type = r.BaseTypeName.Name; v.DatatypeLibrary = RemapDatatypeLibrary( r.BaseTypeName.Namespace); v.Value = en.Value; c.Patterns.Add(v); } return(c); }
RelaxngPattern CreatePatternFromParticleCore(XmlSchemaParticle xsdp) { XmlSchemaGroupBase gb = xsdp as XmlSchemaGroupBase; if (xsdp is XmlSchemaAny) { RelaxngRef r = new RelaxngRef(); r.Name = "anyType"; return(r); } if (gb is XmlSchemaSequence) { RelaxngGroup grp = new RelaxngGroup(); foreach (XmlSchemaParticle xsdc in gb.Items) { grp.Patterns.Add(CreatePatternFromParticle(xsdc)); } return(grp); } if (gb is XmlSchemaChoice) { RelaxngChoice rc = new RelaxngChoice(); foreach (XmlSchemaParticle xsdc in gb.Items) { rc.Patterns.Add(CreatePatternFromParticle(xsdc)); } return(rc); } return(CreateElement((XmlSchemaElement)xsdp)); }
// Note that it does not return the changed sequence. private RelaxngSingleContentPattern ToSequenceOfChoice( RelaxngElement ct, RelaxngGroup s) { RelaxngSingleContentPattern scp = laxOccurence ? (RelaxngSingleContentPattern) new RelaxngZeroOrMore() : new RelaxngOneOrMore(); RelaxngChoice c = new RelaxngChoice(); foreach (RelaxngPattern p in s.Patterns) { c.Patterns.Add(p); } scp.Patterns.Add(c); ct.Patterns.Clear(); ct.Patterns.Add(scp); return(scp); }
private void ProcessLax(RelaxngSingleContentPattern scp) { RelaxngChoice c = (RelaxngChoice)scp.Patterns [0]; foreach (RelaxngPattern p in c.Patterns) { RelaxngRef el = p as RelaxngRef; if (el == null) { RelaxngOneOrMore oom = (RelaxngOneOrMore)p; el = (RelaxngRef)oom.Patterns [0]; } if (el == null) { throw Error(c, String.Format("Target pattern contains unacceptable child pattern {0}. Only ref is allowed here.")); } if (ElementMatches(el)) { InferElement(el, false); return; } } // append a new element particle to lax term. QName qname = new QName( source.LocalName, source.NamespaceURI); RelaxngDefine def = GetGlobalElement(qname); if (def == null) { def = CreateGlobalElement(qname); // used to be CreateElement(). InferElement(def, true); } else { InferElement(def, false); } RelaxngRef nel = new RelaxngRef(); nel.Name = def.Name; c.Patterns.Add(nel); }
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); }
public void WriteChoice(RelaxngChoice p) { WritePatterns(p.Patterns, '|', false); }