Пример #1
0
        public object ReadTypedValue()
        {
            if (dtdReader == null)
            {
                return(null);
            }
            XmlSchemaDatatype dt = schemaInfo.SchemaType as XmlSchemaDatatype;

            if (dt == null)
            {
                XmlSchemaType st = schemaInfo.SchemaType as XmlSchemaType;
                if (st != null)
                {
                    dt = st.Datatype;
                }
            }
            if (dt == null)
            {
                return(null);
            }
            switch (NodeType)
            {
            case XmlNodeType.Element:
                if (IsEmptyElement)
                {
                    return(null);
                }

                storedCharacters.Length = 0;
                bool loop = true;
                do
                {
                    Read();
                    switch (NodeType)
                    {
                    case XmlNodeType.Whitespace:
                    case XmlNodeType.SignificantWhitespace:
                    case XmlNodeType.Text:
                    case XmlNodeType.CDATA:
                        storedCharacters.Append(Value);
                        break;

                    case XmlNodeType.Comment:
                        break;

                    default:
                        loop = false;
                        break;
                    }
                } while (loop && !EOF);
                return(dt.ParseValue(storedCharacters.ToString(), NameTable, dtdReader.ParserContext.NamespaceManager));

            case XmlNodeType.Attribute:
                return(dt.ParseValue(Value, NameTable, dtdReader.ParserContext.NamespaceManager));
            }
            return(null);
        }
Пример #2
0
        private void AssertDatatype(XmlSchema schema, int index,
                                    XmlTokenizedType tokenizedType, Type type, string rawValue, object parsedValue)
        {
            XmlSchemaElement  element  = schema.Items [index] as XmlSchemaElement;
            XmlSchemaDatatype dataType = element.ElementType as XmlSchemaDatatype;

            Assert.AreEqual(tokenizedType, dataType.TokenizedType, "#1");
            Assert.AreEqual(type, dataType.ValueType, "#2");
            Assert.AreEqual(parsedValue, dataType.ParseValue(rawValue, null, null), "#3");
        }
Пример #3
0
 internal static T ParseValue <T>(string value, XElement element, XmlSchemaDatatype datatype)
 {
     if (datatype.TypeCode == XmlTypeCode.QName || datatype.TypeCode == XmlTypeCode.NCName)
     {
         return((T)datatype.ParseValue(value, NameTable, new XNamespaceResolver(element)));
     }
     else
     {
         return((T)datatype.ChangeType(value, typeof(T)));
     }
 }
Пример #4
0
		private void ValidateSimpleContentIdentity (
			XmlSchemaDatatype dt, string value)
		{
			// Identity field value
			if (currentKeyFieldConsumers != null) {
				while (this.currentKeyFieldConsumers.Count > 0) {
					XsdKeyEntryField field = this.currentKeyFieldConsumers [0] as XsdKeyEntryField;
					if (field.Identity != null)
						HandleError ("Two or more identical field was found. Former value is '" + field.Identity + "' .");
					object identity = null; // This means empty value
					if (dt != null) {
						try {
							identity = dt.ParseValue (value, NameTable, NamespaceManager);
						} catch (Exception ex) { // FIXME: (wishlist) This is bad manner ;-(
							HandleError ("Identity value is invalid against its data type " + dt.TokenizedType, ex);
						}
					}
					if (identity == null)
						identity = value;

					if (!field.SetIdentityField (identity, reader.Depth == xsiNilDepth, dt as XsdAnySimpleType, this.Depth, readerLineInfo))
						HandleError ("Two or more identical key value was found: '" + value + "' .");
					this.currentKeyFieldConsumers.RemoveAt (0);
				}
			}
		}
Пример #5
0
        internal static T ParseValue <T>(string value, XElement element, XmlSchemaDatatype datatype)
        {
            T t;

            t = ((datatype.TypeCode == XmlTypeCode.QName ? false : datatype.TypeCode != XmlTypeCode.NCName) ? ParseValueFast <T>(value, datatype) : (T)datatype.ParseValue(value, XTypedServices.NameTable, new XNamespaceResolver(element)));
            return(t);
        }
Пример #6
0
 public override object Parse(string text, XmlReader reader)
 {
     return(dt.ParseValue(text,
                          reader != null ? reader.NameTable : null,
                          null));
 }