本文整理匯總了C#中System.Xml.XmlTextReader.ReadElementContentAsString方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlTextReader.ReadElementContentAsString方法的具體用法?C# XmlTextReader.ReadElementContentAsString怎麽用?C# XmlTextReader.ReadElementContentAsString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlTextReader
的用法示例。
在下文中一共展示了XmlTextReader.ReadElementContentAsString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: parsePackageInfo
public static Dictionary<string, string> parsePackageInfo(string input)
{
if (!File.Exists(input))
return new Dictionary<string, string>();
Dictionary<string, string> details = new Dictionary<string, string>();
try
{
#region Boring XML parsing
// Try to parse the package_info.xml.
XmlTextReader xmldoc = new XmlTextReader(input);
xmldoc.DtdProcessing = DtdProcessing.Ignore;
while (xmldoc.Read())
{
if (xmldoc.NodeType.Equals(XmlNodeType.Element))
{
switch (xmldoc.LocalName)
{
case "id":
string mid = xmldoc.ReadElementContentAsString();
details.Add("modID", mid);
// Determine the mod author.
string[] pieces = mid.Split(':');
details.Add("modUser", pieces[0]);
break;
case "name":
details.Add("modName", xmldoc.ReadElementContentAsString());
break;
case "version":
details.Add("modVersion", xmldoc.ReadElementContentAsString());
break;
case "type":
if (xmldoc.ReadElementContentAsString() == "modification")
details.Add("modType", "Modification");
else
details.Add("modType", "Avatar pack");
break;
case "install":
if (!details.ContainsKey("modCompat"))
details.Add("modCompat", xmldoc.GetAttribute("for"));
break;
}
}
}
xmldoc.Close();
#endregion
return details;
}
catch
{
return new Dictionary<string, string>();
}
}
示例2: loadXML
public static void loadXML()
{
if (pointers.Count <= 0) {
reader = new XmlTextReader("RocketLeague.CT");
while (reader.ReadToFollowing("CheatEntry"))
{
reader.ReadToFollowing("Description");
string name = reader.ReadElementContentAsString().Trim('"');
reader.ReadToFollowing("Address");
string adress = reader.ReadElementContentAsString();
string offsets = "";
reader.ReadToFollowing("Offsets");
reader.Read();
while (reader.Read() && reader.NodeType != XmlNodeType.EndElement)
{
offsets = "+" + reader.ReadElementContentAsString() + offsets;
}
pointers.Add(name, adress + offsets);
}
reader.Close();
}
}
示例3: ReadXml
internal void ReadXml(XmlTextReader reader)
{
while (reader.Read())
{
// End of credit_card element, get out of here
if (reader.Name == "credit_card" && reader.NodeType == XmlNodeType.EndElement)
break;
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
case "year":
this.ExpirationYear = reader.ReadElementContentAsInt();
break;
case "month":
this.ExpirationMonth = reader.ReadElementContentAsInt();
break;
case "last_four":
this.LastFour = reader.ReadElementContentAsString();
break;
case "type":
this.CreditCardType = reader.ReadElementContentAsString();
break;
}
}
}
}
示例4: Unmarshall
public override WebServiceResponse Unmarshall(XmlUnmarshallerContext context)
{
XmlTextReader reader = new XmlTextReader(context.ResponseStream);
SendMessageResponse response = new SendMessageResponse();
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
switch (reader.LocalName)
{
case MNSConstants.XML_ELEMENT_MESSAGE_ID:
response.MessageId = reader.ReadElementContentAsString();
break;
case MNSConstants.XML_ELEMENT_MESSAGE_BODY_MD5:
response.MessageBodyMD5 = reader.ReadElementContentAsString();
break;
}
break;
}
}
reader.Close();
return response;
}
示例5: Unmarshall
public override WebServiceResponse Unmarshall(XmlUnmarshallerContext context)
{
XmlTextReader reader = new XmlTextReader(context.ResponseStream);
ListQueueResponse response = new ListQueueResponse();
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
switch (reader.LocalName)
{
case MNSConstants.XML_ELEMENT_QUEUE_URL:
response.QueueUrls.Add(reader.ReadElementContentAsString());
break;
case MNSConstants.XML_ELEMENT_NEXT_MARKER:
response.NextMarker = reader.ReadElementContentAsString();
break;
}
break;
}
}
reader.Close();
return response;
}
示例6: GetLocation
/// <summary>
/// The get location.
/// </summary>
/// <param name="ip">
/// The ip.
/// </param>
/// <returns>
/// The <see cref="GeolocateResult"/>.
/// </returns>
public static GeolocateResult GetLocation(this IPAddress ip)
{
// FIXME: ServiceLocator - logger & privateconfig
var config = ServiceLocator.Current.GetInstance<IPrivateConfiguration>();
var logger = ServiceLocator.Current.GetInstance<ILogger>().CreateChildLogger("IPAddressExtensions");
if (config.IpInfoDbApiKey == string.Empty)
{
logger.Error("API key is empty, please fix this in configuration.");
return new GeolocateResult();
}
var requestData =
HttpRequest.Get(
"http://api.ipinfodb.com/v3/ip-city/?key=" + config.IpInfoDbApiKey + "&ip=" + ip + "&format=xml");
using (Stream s = requestData.ToStream())
{
var xtr = new XmlTextReader(s);
var result = new GeolocateResult();
while (!xtr.EOF)
{
xtr.Read();
switch (xtr.Name)
{
case "statusCode":
result.Status = xtr.ReadElementContentAsString();
break;
case "countryCode":
result.CountryCode = xtr.ReadElementContentAsString();
break;
case "countryName":
result.Country = xtr.ReadElementContentAsString();
break;
case "regionName":
result.Region = xtr.ReadElementContentAsString();
break;
case "cityName":
result.City = xtr.ReadElementContentAsString();
break;
case "zipCode":
result.ZipPostalCode = xtr.ReadElementContentAsString();
break;
case "latitude":
result.Latitude = xtr.ReadElementContentAsFloat();
break;
case "longitude":
result.Longitude = xtr.ReadElementContentAsFloat();
break;
}
}
return result;
}
}
示例7: CreateRequest
public Request CreateRequest(string testXMLFilePath)
{
using (var outlookApp = new WsApplication(new Microsoft.Office.Interop.Outlook.Application(), false))
{
using (var mailItem = outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem))
{
int positionCount = 0;
XmlReader reader = new XmlTextReader(testXMLFilePath);
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
if (reader.Name.CompareTo("subject") == 0)
{
mailItem.Subject = reader.ReadElementContentAsString();
}
else if (reader.Name.CompareTo("recipient") == 0)
{
mailItem.Recipients.Add(reader.ReadElementContentAsString());
}
else if (reader.Name.CompareTo("attachment") == 0)
{
string fileName = reader.ReadElementContentAsString();
// We want the parent directory because the scripts live in \succeed and \fail below the folder containg the test files
string testFilePath = Path.Combine(Directory.GetParent(Path.GetDirectoryName(testXMLFilePath)).FullName, fileName);
if (!File.Exists(testFilePath))
{
throw new Exception("Unable to find test file: " + fileName);
}
mailItem.Attachments.Add(testFilePath, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, ++positionCount, fileName);
}
break;
}
}
mailItem.Save();
// Now convert to to a request
Request request = null;
// Yes we are assuming the security has been disabled OK...but we're testing the decryption here, NOT the proxy/security code path
_proxy = new OutlookMailProxy(mailItem);
_email2Uro = new Email2Request(_proxy);
request = _email2Uro.Convert(RequestChannel.Outlook, false);
// Tidyup
mailItem.Delete();
return request;
}
}
}
示例8: Parse
private Compiler Parse(string xmlFilePath)
{
var compiler = new Compiler();
var xmlReader = new XmlTextReader(xmlFilePath);
xmlReader.Read();
while (xmlReader.Read())
{
switch (xmlReader.Name)
{
case "name":
{
compiler.Name = xmlReader.ReadElementContentAsString();
}
break;
case "location":
{
compiler.Location = Path.Combine(
AppDomain.CurrentDomain.BaseDirectory, xmlReader.ReadElementContentAsString());
}
break;
case "extension":
{
compiler.Extension = xmlReader.ReadElementContentAsString().TrimEnd().TrimStart();
}
break;
case "arguments":
{
compiler.Arguments = xmlReader.ReadElementContentAsString().TrimEnd().TrimStart();
}
break;
case "compiledExtension":
{
compiler.CompiledExtension = xmlReader.ReadElementContentAsString().TrimEnd().TrimStart();
}
break;
case "needShortName":
{
compiler.IsNeedShortPath = xmlReader.ReadElementContentAsBoolean();
}
break;
}
}
if (compiler.Extension == string.Empty || compiler.Name == string.Empty || compiler.Location == string.Empty || compiler.CompiledExtension == string.Empty || compiler.Arguments == string.Empty)
throw new Exception("Bad xml information about compiler");
return compiler;
}
示例9: parseXML
private void parseXML(string filename)
{
using (XmlTextReader reader = new XmlTextReader(filename))
{
reader.ReadToFollowing("title");
Title = reader.ReadElementContentAsString();
reader.ReadToFollowing("path");
Path = reader.ReadElementContentAsString();
reader.ReadToFollowing("description");
Description = reader.ReadElementContentAsString();
reader.ReadToFollowing("img_path");
ImagePath = reader.ReadElementContentAsString();
}
}
示例10: LoadFromFile
public bool LoadFromFile(string filename)
{
m_FileName = filename;
bool bRet = false;
XmlTextReader reader = null;
try
{
reader = new XmlTextReader(m_FileName);
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element: // The node is an element.
switch (reader.Name)
{
case "name": reader.MoveToContent(); m_name = reader.ReadElementContentAsString(); break;
case "pass1": reader.MoveToContent(); m_pass1 = reader.ReadElementContentAsString(); break;
case "pass2": reader.MoveToContent(); m_pass2 = reader.ReadElementContentAsString(); break;
case "icon": reader.MoveToContent(); m_icon = reader.ReadElementContentAsInt(); break;
case "account":
{
AccountItem newAccount = new AccountItem();
if (newAccount.AccountXMLLoad(reader))
{
m_Accounts.Add(newAccount);
}
break;
}
}
break;
case XmlNodeType.EndElement:
break;
}
}
}
catch (System.IO.FileNotFoundException exception)
{
return false;
}
catch (Exception exception)
{
MessageBox.Show("Error reading " + m_FileName);
}
finally
{
reader.Close();
}
return bRet;
}
示例11: ReadXml
internal override void ReadXml(XmlTextReader reader)
{
while (reader.Read())
{
if (reader.Name == "subscription_add_on" && reader.NodeType == XmlNodeType.EndElement)
break;
if (reader.NodeType != XmlNodeType.Element) continue;
switch (reader.Name)
{
case "add_on_code":
AddOnCode = reader.ReadElementContentAsString();
break;
case "quantity":
Quantity = reader.ReadElementContentAsInt();
break;
case "unit_amount_in_cents":
UnitAmountInCents = reader.ReadElementContentAsInt();
break;
}
}
}
示例12: GetXMLValue
public string GetXMLValue(XmlTextReader reader, String nodeName)
{
if (reader.ReadToDescendant(nodeName))
return reader.ReadElementContentAsString();
else
return "";
}
示例13: LoadFromFile
public void LoadFromFile()
{
var path = CreateAndGetPath();
var xmlReader = new XmlTextReader(System.IO.File.OpenText(path));
while (xmlReader.Read())
{
if (xmlReader.NodeType != XmlNodeType.Element) continue;
if (xmlReader.Name == Utils.XmlPrefix) Prefix = xmlReader.ReadElementContentAsString();
if (xmlReader.Name == Utils.XmlTemplateName) TemplateName = xmlReader.ReadElementContentAsString();
if (xmlReader.Name == Utils.XmlCode) Code = xmlReader.ReadElementContentAsString();
if (xmlReader.Name == Utils.XmlFolder) Folder = xmlReader.ReadElementContentAsString();
}
xmlReader.Close();
}
示例14: Unmarshall
public override WebServiceResponse Unmarshall(XmlUnmarshallerContext context)
{
XmlTextReader reader = new XmlTextReader(context.ResponseStream);
ChangeMessageVisibilityResponse response = new ChangeMessageVisibilityResponse();
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
switch (reader.LocalName)
{
case MNSConstants.XML_ELEMENT_RECEIPT_HANDLE:
response.ReceiptHandle = reader.ReadElementContentAsString();
break;
case MNSConstants.XML_ELEMENT_NEXT_VISIBLE_TIME:
response.NextVisibleTime = AliyunSDKUtils.ConvertFromUnixEpochSeconds(reader.ReadElementContentAsLong());
break;
}
break;
}
}
reader.Close();
return response;
}
示例15: LoadFromXml
public List<string> LoadFromXml(string xmlFileName, string nodeName, string attributeName = "")
{
var items = new List<string>();
if (string.IsNullOrEmpty(xmlFileName) || string.IsNullOrEmpty(nodeName))
return items;
var r = new XmlTextReader(xmlFileName);
while (r.Read())
{
string item = string.Empty;
if (r.NodeType != XmlNodeType.Element || r.Name != nodeName) continue;
if (string.IsNullOrEmpty(attributeName))
{
item = r.ReadElementContentAsString();
}
else
{
item = r.GetAttribute(attributeName);
}
if (string.IsNullOrEmpty(item)) continue;
items.Add(item);
}
r.Close();
return items;
}