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


C# XmlValidatingReader.ReadString方法代碼示例

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


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

示例1: TestExpandEntity

		public void TestExpandEntity ()
		{
			string intSubset = "<!ELEMENT root (#PCDATA)><!ATTLIST root foo CDATA 'foo-def' bar CDATA 'bar-def'><!ENTITY ent 'entity string'>";
			string dtd = "<!DOCTYPE root [" + intSubset + "]>";
			string xml = dtd + "<root foo='&ent;' bar='internal &ent; value'>&ent;</root>";
			dvr = PrepareXmlReader (xml);
			dvr.EntityHandling = EntityHandling.ExpandEntities;
			dvr.Read ();	// DTD
			dvr.Read ();
			Assert.AreEqual (XmlNodeType.Element, dvr.NodeType);
			Assert.AreEqual ("root", dvr.Name);
			Assert.IsTrue (dvr.MoveToFirstAttribute ());
			Assert.AreEqual ("foo", dvr.Name);
			Assert.AreEqual ("entity string", dvr.Value);
			Assert.IsTrue (dvr.MoveToNextAttribute ());
			Assert.AreEqual ("bar", dvr.Name);
			Assert.AreEqual ("internal entity string value", dvr.Value);
			Assert.AreEqual ("entity string", dvr.ReadString ());

			// ValidationType = None

			dvr = PrepareXmlReader (xml);
			dvr.EntityHandling = EntityHandling.ExpandEntities;
			dvr.ValidationType = ValidationType.None;
			dvr.Read ();	// DTD
			dvr.Read ();
			Assert.AreEqual (XmlNodeType.Element, dvr.NodeType);
			Assert.AreEqual ("root", dvr.Name);

			Assert.IsTrue (dvr.MoveToFirstAttribute ());
			Assert.AreEqual ("foo", dvr.Name);
			Assert.AreEqual ("entity string", dvr.Value);

			Assert.IsTrue (dvr.MoveToNextAttribute ());
			Assert.AreEqual ("bar", dvr.Name);
			Assert.AreEqual ("internal entity string value", dvr.Value);
			Assert.AreEqual ("entity string", dvr.ReadString ());
		}
開發者ID:nobled,項目名稱:mono,代碼行數:38,代碼來源:XmlValidatingReaderTests.cs

示例2: parseXML

        /// <summary>
        /// takes in raw xml string and attempts to parse it into a workable hash.
        /// all valid xml for the gateway contains
        /// <transaction><fields><field key="attribute name">value</field></fields></transaction>
        /// there will be 1 or more (should always be more than 1 to be valid) field tags
        /// this method will take the attribute name and make that the hash key and then the value is the value 
        /// if an error occurs then the error key will be added to the hash.
        /// </summary>
        /// <param name="xml"></param>
        /// <returns></returns>
        private Hashtable parseXML(string xml)
        {
            Hashtable ret_hash = new Hashtable(); //stores key values to return
            XmlTextReader txtreader = null;
            XmlValidatingReader reader = null;

            if (xml != null && xml.Length > 0)
            {

                try
                {
                    //Implement the readers.
                    txtreader = new XmlTextReader(new System.IO.StringReader(xml));
                    reader = new XmlValidatingReader(txtreader);

                    //Parse the XML and display the text content of each of the elements.
                    while (reader.Read())
                    {
                        if (reader.IsStartElement() && reader.Name.ToLower() == "field")
                        {
                            if (reader.HasAttributes)
                            {
                                //we want the key attribute value
                                ret_hash[reader.GetAttribute(0).ToLower()] = reader.ReadString();
                            }
                            else
                            {
                                ret_hash["error"] = "All FIELD tags must contains a KEY attribute.";
                            }
                        }
                    } //ends while
                }
                catch (Exception e)
                {
                    //handle exceptions
                    ret_hash["error"] = e.Message;
                }
                finally
                {
                    if (reader != null) reader.Close();
                }
            }
            else
            {
                //incoming xml is empty
                ret_hash["error"] = "No data was present. Valid XML must be sent in order to process a transaction.";
            }

            return ret_hash;
        }
開發者ID:GoEmerchant,項目名稱:goemerchant-csharp,代碼行數:60,代碼來源:XMLGatewayTest.cs


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