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); }
// 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); }