本文整理匯總了C#中System.Xml.XmlValidatingReader.GetAttribute方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlValidatingReader.GetAttribute方法的具體用法?C# XmlValidatingReader.GetAttribute怎麽用?C# XmlValidatingReader.GetAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlValidatingReader
的用法示例。
在下文中一共展示了XmlValidatingReader.GetAttribute方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: 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;
}