Exemple #1
0
		private RelaxngAttribute ReadAttributePattern ()
		{
			RelaxngAttribute attr = new RelaxngAttribute ();
			FillLocation (attr);

			if (MoveToFirstAttribute ()) {
				do {
					if (NamespaceURI != String.Empty)
						continue;
					switch (LocalName) {
					case "datatypeLibrary":
					case "name":
					case "ns":
						break;
					default:
						throw new RelaxngException ("Invalid attribute.");
					}
				} while (MoveToNextAttribute ());
				MoveToElement ();
			}

			string ns = GetSpaceStrippedAttribute ("ns", String.Empty);

			// try to get name from attribute.
			if (MoveToAttribute ("name", String.Empty)) {
//				attr.NameClass = resolvedName (XmlConvert.VerifyName (Value.Trim ()), false);
				RelaxngName nc = new RelaxngName ();
				string name = XmlConvert.VerifyName (Value.Trim ());
				if (name.IndexOf (':') > 0)
					nc = resolvedName (name);
				else {
					nc.LocalName = name;
					nc.Namespace = ns == null ? String.Empty : ns;
				}
				attr.NameClass = nc;
			}

			MoveToElement ();
			if (!IsEmptyElement) {
				Read ();
				// read nameClass from content.
				if (attr.NameClass == null)
					attr.NameClass = ReadNameClass ();

				if (NodeType == XmlNodeType.Element)
					attr.Pattern = ReadPattern ();

				expectEnd ("attribute");
			} else
				Read ();

			if (attr.NameClass == null)
				throw new RelaxngException ("Name class was not specified.");
			return attr;
		}
Exemple #2
0
        private RelaxngAttribute ReadAttributePattern()
        {
            RelaxngAttribute attr = new RelaxngAttribute();

            FillLocation(attr);

            if (MoveToFirstAttribute())
            {
                do
                {
                    if (NamespaceURI != String.Empty)
                    {
                        continue;
                    }
                    switch (LocalName)
                    {
                    case "datatypeLibrary":
                    case "name":
                    case "ns":
                        break;

                    default:
                        throw new RelaxngException("Invalid attribute.");
                    }
                } while (MoveToNextAttribute());
                MoveToElement();
            }

            string ns = GetSpaceStrippedAttribute("ns", String.Empty);

            // try to get name from attribute.
            if (MoveToAttribute("name", String.Empty))
            {
//				attr.NameClass = resolvedName (XmlConvert.VerifyName (Value.Trim ()), false);
                RelaxngName nc   = new RelaxngName();
                string      name = XmlConvert.VerifyName(Value.Trim());
                if (name.IndexOf(':') > 0)
                {
                    nc = resolvedName(name);
                }
                else
                {
                    nc.LocalName = name;
                    nc.Namespace = ns == null ? String.Empty : ns;
                }
                attr.NameClass = nc;
            }

            MoveToElement();
            if (!IsEmptyElement)
            {
                Read();
                // read nameClass from content.
                if (attr.NameClass == null)
                {
                    attr.NameClass = ReadNameClass();
                }

                if (NodeType == XmlNodeType.Element)
                {
                    attr.Pattern = ReadPattern();
                }

                expectEnd("attribute");
            }
            else
            {
                Read();
            }

            if (attr.NameClass == null)
            {
                throw new RelaxngException("Name class was not specified.");
            }
            return(attr);
        }
Exemple #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;
		}
Exemple #4
0
		public void WriteAttribute (RelaxngAttribute attribute)
		{
			w.Write ("attribute ");
			attribute.NameClass.WriteRnc (this);
			w.Write (" {");
			if (attribute.Pattern == null)
				w.Write ("empty");
			else
				attribute.Pattern.WriteRnc (this);
			w.Write (" }");
		}
		private RelaxngDefine CreateGlobalAttribute (QName name)
		{
			RelaxngDefine def = new RelaxngDefine ();
			def.Name = CreateUniqueName (name.Name + "-attr");
			RelaxngAttribute attr = new RelaxngAttribute ();
			attr.NameClass = new RelaxngName (
				name.Name, name.Namespace);
			def.Patterns.Add (attr);
			attributes.Add (name, def);
			grammar.Defines.Add (def);
			return def;
		}
		// It returns RelaxngAttribute for local attribute, and
		// RelaxngRef for global attribute.
		private RelaxngPattern InferNewAttribute (
			QName attrName, bool isNewTypeDefinition)
		{
			RelaxngPattern p = null;
			bool mergedRequired = false;
			if (attrName.Namespace.Length > 0) {
				// global attribute; might be already defined.
				// (Actually RELAX NG has no concept of "global
				// attributes" but it is still useful to
				// represent attributes in global scope.
				RelaxngDefine attr = GetGlobalAttribute (
					attrName);
				if (attr == null) {
					attr = CreateGlobalAttribute (attrName);
					attr.Patterns.Add (CreateSimplePattern (
						InferSimpleType (source.Value)));
				} else {
					RelaxngAttribute a = attr.Patterns [0] as RelaxngAttribute;
					if (a != null)
						mergedRequired = true;
					else {
						RelaxngOptional opt =
							(RelaxngOptional) attr.Patterns [0];
						a = (RelaxngAttribute) opt.Patterns [0];
					}
					InferMergedAttribute (a);
				}
				RelaxngRef r = new RelaxngRef ();
				r.Name = attr.Name;
				p = r;
			} else {
				// local attribute
				RelaxngAttribute a = new RelaxngAttribute ();
				a.NameClass = new RelaxngName (
					attrName.Name, attrName.Namespace);
				a.Pattern = CreateSimplePattern (
					InferSimpleType (source.Value));
				p = a;
			}
			// optional
			if (laxOccurence ||
				(!isNewTypeDefinition && !mergedRequired)) {
				RelaxngOptional opt = new RelaxngOptional ();
				opt.Patterns.Add (p);
				p = opt;
			}

			return p;
		}