Example #1
0
        private RelaxngMixed ReadMixedPattern()
        {
            RelaxngMixed o = new RelaxngMixed();

            FillLocation(o);
            expect("mixed");
            Read();
            ReadPatterns(o);
            expectEnd("mixed");
            return(o);
        }
Example #2
0
		private RelaxngMixed ReadMixedPattern ()
		{
			RelaxngMixed o = new RelaxngMixed ();
			FillLocation (o);
			expect ("mixed");
			Read ();
			ReadPatterns (o);
			expectEnd ("mixed");
			return o;
		}
Example #3
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;
		}
Example #4
0
		public void WriteMixed (RelaxngMixed p)
		{
			w.Write ("mixed {");
			WritePatterns (p.Patterns, false);
			w.Write ("}");
		}
		// 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.");
			}
		}
		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);
		}