當前位置: 首頁>>代碼示例>>C#>>正文


C# XmlValidatingReader.ReadTypedValue方法代碼示例

本文整理匯總了C#中System.Xml.XmlValidatingReader.ReadTypedValue方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlValidatingReader.ReadTypedValue方法的具體用法?C# XmlValidatingReader.ReadTypedValue怎麽用?C# XmlValidatingReader.ReadTypedValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Xml.XmlValidatingReader的用法示例。


在下文中一共展示了XmlValidatingReader.ReadTypedValue方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            string xmlFile = Server.MapPath("~/Customers1.xml");
            string xsdFile = Server.MapPath("~/Customers.xsd");

            XmlTextReader textReader = new XmlTextReader(xmlFile);
            XmlValidatingReader validatingReader = new XmlValidatingReader(textReader);
            validatingReader.Schemas.Add(null, xsdFile);
            validatingReader.ValidationType = ValidationType.Schema;
            validatingReader.ValidationEventHandler += new ValidationEventHandler(validatingReader_ValidationEventHandler);

            while (validatingReader.Read())
            {
                if (validatingReader.NodeType == XmlNodeType.Element)
                {
                    if (validatingReader.SchemaType is XmlSchemaComplexType)
                    {
                        XmlSchemaComplexType complexType = (XmlSchemaComplexType)validatingReader.SchemaType;
                        Response.Write(validatingReader.Name + " " + complexType.Name);
                    }
                    else
                    {
                        object innerText = validatingReader.ReadTypedValue();
                        Response.Write(validatingReader.Name + " : " + innerText.ToString() + " <br />");
                    }
                }
            }
            validatingReader.Close();
        }
開發者ID:sujithkumar640,項目名稱:Technical-Concepts,代碼行數:29,代碼來源:WebForm1.aspx.cs

示例2: TestReadTypedValueSimple

		public void TestReadTypedValueSimple ()
		{
			string xml = "<root>12</root>";
			XmlSchema schema = new XmlSchema ();
			XmlSchemaElement elem = new XmlSchemaElement ();
			elem.Name = "root";
			elem.SchemaTypeName = new XmlQualifiedName ("integer", XmlSchema.Namespace);
			schema.Items.Add (elem);

			// Lap 1:
			
			xvr = PrepareXmlReader (xml);
			xvr.Schemas.Add (schema);
			// Read directly from root.
			object o = xvr.ReadTypedValue ();
			Assert.AreEqual (ReadState.Initial, xvr.ReadState);
			Assert.IsNull (o);

			xvr.Read ();	// element root
			Assert.AreEqual (XmlNodeType.Element, xvr.NodeType);
			Assert.IsNotNull (xvr.SchemaType);
			Assert.IsTrue (xvr.SchemaType is XmlSchemaDatatype);
			o = xvr.ReadTypedValue ();	// read "12"
			Assert.AreEqual (XmlNodeType.EndElement, xvr.NodeType);
			Assert.IsNotNull (o);
			Assert.AreEqual (typeof (decimal), o.GetType ());
			decimal n = (decimal) o;
			Assert.AreEqual (12, n);
			Assert.IsTrue (!xvr.EOF);
			Assert.AreEqual ("root", xvr.Name);
			Assert.IsNull (xvr.SchemaType);	// EndElement's type

			// Lap 2:

			xvr = PrepareXmlReader (xml);
			xvr.Schemas.Add (schema);
			xvr.Read ();	// root
			XmlSchemaDatatype dt = xvr.SchemaType as XmlSchemaDatatype;
			Assert.IsNotNull (dt);
			Assert.AreEqual (typeof (decimal), dt.ValueType);
			Assert.AreEqual (XmlTokenizedType.None, dt.TokenizedType);
			xvr.Read ();	// text "12"
			Assert.IsNull (xvr.SchemaType);
			o = xvr.ReadTypedValue ();
			// ReadTypedValue is different from ReadString().
			Assert.IsNull (o);
		}
開發者ID:calumjiao,項目名稱:Mono-Class-Libraries,代碼行數:47,代碼來源:XsdValidatingReaderTests.cs

示例3: ReadTypedValueWhitespaces

		public void ReadTypedValueWhitespaces ()
		{
			string xml = "<root>  </root><!-- after -->";
			string xsd = @"
<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
  <xs:element name='root'>
    <xs:simpleType>
      <xs:restriction base='xs:string'>
        <xs:minLength value='2' />
      </xs:restriction>
    </xs:simpleType>
  </xs:element>
</xs:schema>";
			XmlTextReader xir = 
				new XmlTextReader (xml, XmlNodeType.Document, null);
			XmlTextReader xsr =
				new XmlTextReader (xsd, XmlNodeType.Document, null);
			XmlValidatingReader vr = new XmlValidatingReader (xir);
			vr.Schemas.Add (XmlSchema.Read (xsr, null));
			vr.Read (); // root
			Assert.AreEqual ("  ", vr.ReadTypedValue ());
			Assert.AreEqual (XmlNodeType.EndElement, vr.NodeType);
		}
開發者ID:calumjiao,項目名稱:Mono-Class-Libraries,代碼行數:23,代碼來源:XsdValidatingReaderTests.cs

示例4: TestReadTypedAttributeValue

		public void TestReadTypedAttributeValue ()
		{
			string xml = "<root attr='12'></root>";
			XmlSchema schema = new XmlSchema ();
			XmlSchemaElement elem = new XmlSchemaElement ();
			elem.Name = "root";
			XmlSchemaComplexType ct = new XmlSchemaComplexType ();
			XmlSchemaAttribute attr = new XmlSchemaAttribute ();
			attr.Name = "attr";
			attr.SchemaTypeName = new XmlQualifiedName ("int", XmlSchema.Namespace);
			ct.Attributes.Add (attr);
			elem.SchemaType = ct;
			schema.Items.Add (elem);

			xvr = PrepareXmlReader (xml);
			xvr.Schemas.Add (schema);
			xvr.Read ();
			Assert.AreEqual ("root", xvr.Name);
			Assert.IsTrue (xvr.MoveToNextAttribute ());	// attr
			Assert.AreEqual ("attr", xvr.Name);
			XmlSchemaDatatype dt = xvr.SchemaType as XmlSchemaDatatype;
			Assert.IsNotNull (dt);
			Assert.AreEqual (typeof (int), dt.ValueType);
			Assert.AreEqual (XmlTokenizedType.None, dt.TokenizedType);
			object o = xvr.ReadTypedValue ();
			Assert.AreEqual (XmlNodeType.Attribute, xvr.NodeType);
			Assert.AreEqual (typeof (int), o.GetType ());
			int n = (int) o;
			Assert.AreEqual (12, n);
			Assert.IsTrue (xvr.ReadAttributeValue ());	// can read = seems not proceed.
		}
開發者ID:calumjiao,項目名稱:Mono-Class-Libraries,代碼行數:31,代碼來源:XsdValidatingReaderTests.cs

示例5: Parse

		public override object Parse (string value, XmlReader reader)
		{
			// Now we create XmlValidatingReader to handle
			// simple-type based validation (since there is no
			// other way, because of sucky XmlSchemaSimpleType
			// design).
			if (value != null)
				value = value.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;");
			XmlValidatingReader v = new XmlValidatingReader (
				new XmlTextReader (
					String.Concat ("<root>", value, "</root>"),
					XmlNodeType.Document,
					null));
			v.Schemas.Add (schema);
			v.Read (); // <root>
			try {
				return v.ReadTypedValue ();
			} finally {
				v.Read (); // </root>
			}
		}
開發者ID:KonajuGames,項目名稱:SharpLang,代碼行數:21,代碼來源:XsdDatatypeProvider.cs


注:本文中的System.Xml.XmlValidatingReader.ReadTypedValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。