本文整理匯總了C#中System.Xml.XmlTextReader.ReadElementString方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlTextReader.ReadElementString方法的具體用法?C# XmlTextReader.ReadElementString怎麽用?C# XmlTextReader.ReadElementString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlTextReader
的用法示例。
在下文中一共展示了XmlTextReader.ReadElementString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Read
/// <summary>
/// Reads this instance.
/// </summary>
public List<XmlExceptionParser> Read(string exceptionPath)
{
var exceptionsList = new List<XmlExceptionParser>();
var xmlText = new XmlTextReader(exceptionPath);
while (xmlText.Read())
{
var xmlNode = new XmlExceptionParser();
if (xmlText.MoveToContent() == XmlNodeType.Element && xmlText.Name == "Message")
{
xmlNode.Message = xmlText.ReadElementString();
}
if (xmlText.MoveToContent() == XmlNodeType.Element && xmlText.Name == "Source")
{
xmlNode.Source = xmlText.ReadElementString();
}
if (xmlText.MoveToContent() == XmlNodeType.Element && xmlText.Name == "Stack")
{
xmlNode.Stack = xmlText.ReadElementString();
}
if (xmlText.MoveToContent() == XmlNodeType.Element && xmlText.Name == "Date")
{
xmlNode.Date = Convert.ToDateTime(xmlText.ReadElementString());
}
if (!string.IsNullOrEmpty(xmlNode.Message) && !string.IsNullOrEmpty(xmlNode.Source) &&
!string.IsNullOrEmpty(xmlNode.Stack))
{
exceptionsList.Add(xmlNode);
}
}
xmlText.Close();
return exceptionsList;
}
示例2: Deserialize
public static AAInventoryItemBase Deserialize(string serialization)
{
AAInventoryItemBase item = new AAInventoryItemBase();
StringReader sr = new StringReader(serialization);
XmlTextReader xtr = new XmlTextReader(sr);
xtr.ReadStartElement("InventoryItem");
item.Name = xtr.ReadElementString("Name");
item.ID = UUID.Parse(xtr.ReadElementString("ID"));
item.InvType = Convert.ToInt32(xtr.ReadElementString("InvType"));
item.CreatorId = xtr.ReadElementString("CreatorUUID");
item.CreationDate = Convert.ToInt32(xtr.ReadElementString("CreationDate"));
item.Owner = UUID.Parse(xtr.ReadElementString("Owner"));
item.Description = xtr.ReadElementString("Description");
item.AssetType = Convert.ToInt32(xtr.ReadElementString("AssetType"));
item.AssetID = UUID.Parse(xtr.ReadElementString("AssetID"));
item.SaleType = Convert.ToByte(xtr.ReadElementString("SaleType"));
item.SalePrice = Convert.ToInt32(xtr.ReadElementString("SalePrice"));
item.BasePermissions = Convert.ToUInt32(xtr.ReadElementString("BasePermissions"));
item.CurrentPermissions = Convert.ToUInt32(xtr.ReadElementString("CurrentPermissions"));
item.EveryOnePermissions = Convert.ToUInt32(xtr.ReadElementString("EveryOnePermissions"));
item.NextPermissions = Convert.ToUInt32(xtr.ReadElementString("NextPermissions"));
item.Flags = Convert.ToUInt32(xtr.ReadElementString("Flags"));
item.GroupID = UUID.Parse(xtr.ReadElementString("GroupID"));
item.GroupOwned = Convert.ToBoolean(xtr.ReadElementString("GroupOwned"));
xtr.ReadEndElement();
xtr.Close();
sr.Close();
return item;
}
示例3: Main
public static void Main()
{
using (XmlTextWriter writer = new XmlTextWriter("../../albums.xml", Encoding.UTF8))
{
writer.Formatting = Formatting.Indented;
writer.IndentChar = '\t';
writer.Indentation = 1;
writer.WriteStartDocument();
writer.WriteStartElement("albums");
using (XmlTextReader reader = new XmlTextReader("../../catalog.xml"))
{
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name == "name")
{
writer.WriteStartElement("album");
writer.WriteElementString("name", reader.ReadElementString());
}
if (reader.Name == "artist")
{
writer.WriteElementString("artist", reader.ReadElementString());
writer.WriteEndElement();
}
}
}
}
writer.WriteEndDocument();
}
}
示例4: Main
private static void Main(string[] args)
{
// 8. Write a program, which (using XmlReader and XmlWriter) reads the file catalog.xml and creates the file album.xml,
// in which stores in appropriate way the names of all albums and their authors
Encoding encoding = Encoding.UTF8;
using (XmlTextWriter writer = new XmlTextWriter(FileToWrite, encoding))
{
writer.Formatting = Formatting.Indented;
writer.IndentChar = '\t';
writer.Indentation = 1;
writer.WriteStartDocument();
writer.WriteStartElement("albums");
using (XmlTextReader reader = new XmlTextReader(FileToRead))
{
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element && reader.Name == "name")
{
writer.WriteStartElement("album");
writer.WriteElementString("name", reader.ReadElementString());
}
else if (reader.NodeType == XmlNodeType.Element && reader.Name == "artist")
{
writer.WriteElementString("artist", reader.ReadElementString());
writer.WriteEndElement();
}
}
}
writer.WriteEndDocument();
}
}
示例5: PopulateCache
static void PopulateCache(Dictionary<Key, GenericXmlSecurityToken> cache, Stream stream)
{
XmlTextReader reader = new XmlTextReader(stream);
while (reader.IsStartElement("Entry"))
{
reader.ReadStartElement();
Uri target = new Uri(reader.ReadElementString("Target"));
string issuerStr = reader.ReadElementString("Issuer");
Uri issuer = string.IsNullOrEmpty(issuerStr) ? null : new Uri(issuerStr);
reader.ReadStartElement("Token");
reader.ReadStartElement("XML");
XmlDocument doc = new XmlDocument();
XmlElement tokenXml = doc.ReadNode(reader) as XmlElement;
reader.ReadEndElement();
byte[] key = Convert.FromBase64String(reader.ReadElementString("Key"));
reader.ReadElementString("Id");
DateTime validFrom = Convert.ToDateTime(reader.ReadElementString("ValidFrom"));
DateTime validTo = Convert.ToDateTime(reader.ReadElementString("ValidTo"));
WSSecurityTokenSerializer serializer = new WSSecurityTokenSerializer();
reader.ReadStartElement("InternalTokenReference");
SecurityKeyIdentifierClause internalReference = serializer.ReadKeyIdentifierClause(reader);
reader.ReadEndElement();
reader.ReadStartElement("ExternalTokenReference");
SecurityKeyIdentifierClause externalReference = serializer.ReadKeyIdentifierClause(reader);
reader.ReadEndElement();
reader.ReadEndElement(); // token
reader.ReadEndElement(); // entry
List<IAuthorizationPolicy> policies = new List<IAuthorizationPolicy>();
GenericXmlSecurityToken token = new GenericXmlSecurityToken(tokenXml, new BinarySecretSecurityToken(key), validFrom, validTo, internalReference, externalReference,
new ReadOnlyCollection<IAuthorizationPolicy>(policies));
cache.Add(new Key(target, issuer), token);
}
}
示例6: LoadPIDSetting_FromXmlTextReader
public void LoadPIDSetting_FromXmlTextReader(ref XmlTextReader xml_reader)
{
this.cycle_time_in_seconds = Double.Parse(xml_reader.ReadElementString("cycle_time_in_seconds"));
xml_reader.ReadStartElement("outer_zone");
this.proportional_band_EachZone[0] = Double.Parse(xml_reader.ReadElementString("proportional_band"));
this.offset_EachZone[0] = Double.Parse(xml_reader.ReadElementString("offset"));
this.reset_EachZone[0] = Double.Parse(xml_reader.ReadElementString("reset"));
this.rate_EachZone[0] = Double.Parse(xml_reader.ReadElementString("rate"));
xml_reader.ReadEndElement();
xml_reader.ReadStartElement("sample_zone");
this.proportional_band_EachZone[1] = Double.Parse(xml_reader.ReadElementString("proportional_band"));
this.offset_EachZone[1] = Double.Parse(xml_reader.ReadElementString("offset"));
this.reset_EachZone[1] = Double.Parse(xml_reader.ReadElementString("reset"));
this.rate_EachZone[1] = Double.Parse(xml_reader.ReadElementString("rate"));
xml_reader.ReadEndElement();
xml_reader.ReadStartElement("inner_zone");
this.proportional_band_EachZone[2] = Double.Parse(xml_reader.ReadElementString("proportional_band"));
this.offset_EachZone[2] = Double.Parse(xml_reader.ReadElementString("offset"));
this.reset_EachZone[2] = Double.Parse(xml_reader.ReadElementString("reset"));
this.rate_EachZone[2] = Double.Parse(xml_reader.ReadElementString("rate"));
xml_reader.ReadEndElement();
}
示例7: Main
public static void Main()
{
var writer = new XmlTextWriter("../../album.xml", Encoding.UTF8);
using (writer)
{
writer.Formatting = Formatting.Indented;
writer.IndentChar = '\t';
writer.WriteStartDocument();
writer.WriteStartElement("albums");
var reader = new XmlTextReader("../../catalog.xml");
using (reader)
{
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name == "name")
{
writer.WriteStartElement("album");
var albumName = reader.ReadElementString();
writer.WriteElementString("name", albumName);
}
else if (reader.Name == "artist")
{
var artistName = reader.ReadElementString();
writer.WriteElementString("artist", artistName);
writer.WriteEndElement();
}
}
}
}
writer.WriteEndDocument();
}
Console.WriteLine("albums.xml created");
Console.WriteLine(new string('-', 30));
var document = XDocument.Load("../../album.xml");
var albumElements = document.Element("albums").Elements("album");
foreach (var album in albumElements)
{
var albumName = album.Element("name").Value;
Console.WriteLine("Album: {0}", albumName);
var albumArtist = album.Element("artist").Value;
Console.WriteLine("Artist: {0}", albumArtist);
Console.WriteLine();
}
}
示例8: FromXml
private void FromXml(String xmlStream)
{
try
{
StringReader stringReader = new StringReader(xmlStream);
XmlTextReader reader = new XmlTextReader(stringReader);
while (reader.EOF == false)
{
reader.ReadStartElement("ValidationContext");
String generateSummaryResults = reader.ReadElementString("GenerateSummaryResults");
if (generateSummaryResults == "true")
{
_generateSummaryResults = true;
}
String generateDetailedResults = reader.ReadElementString("GenerateDetailedResults");
if (generateDetailedResults == "true")
{
_generateDetailedResults = true;
}
// ...
// EVS Specific Context properties
// ...
reader.ReadElementString("EvsSpecificContext");
reader.ReadEndElement();
}
reader.Close();
}
catch (Exception e)
{
String message = String.Format("Failed to FromXml() DVTK DICOM EVS Validation Context XML stream: \"{0}\". Error: \"{1}\"", xmlStream, e.Message);
throw new Exception(message, e);
}
}
示例9: Read
public static DatabaseConfiguration Read (string file)
{
DatabaseConfiguration config = new DatabaseConfiguration ();
StreamReader s = new StreamReader (file);
using (s) {
XmlTextReader tr = new XmlTextReader (s);
tr.MoveToContent ();
tr.ReadStartElement ("Configuration");
tr.MoveToContent ();
tr.ReadStartElement ("DisabledAddins");
tr.MoveToContent ();
if (!tr.IsEmptyElement) {
while (tr.NodeType != XmlNodeType.EndElement) {
if (tr.NodeType == XmlNodeType.Element) {
if (tr.LocalName == "Addin")
config.DisabledAddins.Add (tr.ReadElementString ());
}
else
tr.Skip ();
tr.MoveToContent ();
}
}
}
return config;
}
示例10: getData
public void getData(ref SortedDictionary<string,string> data, ref List<string> localizations)
{
XmlTextReader reader = new XmlTextReader (fileName);
string currentLocal=GameConfig.Localization;
string key;
string value;
reader.Read();
while (reader.Read()) {
if (reader.Name.Equals(LOCALIZATION_NAME)) {
currentLocal = reader.GetAttribute(LOCALIZATION_ATTRIBUTE);
if (!localizations.Contains(currentLocal))
localizations.Add(currentLocal);
}
if(reader.Name.Equals(ITEM_NAME)){
key = reader.GetAttribute(ITEM_ATTRIBUTE);
value = reader.ReadElementString();
if (key!=null)
data.Add(currentLocal+key, value);
}
}
reader.Close();
reader = null;
}
示例11: ReadXml
public void ReadXml(XmlTextReader xmlReader)
{
try
{
bool isEndCycle = false;
while (xmlReader.Read() && !isEndCycle)
{
if (xmlReader.NodeType == XmlNodeType.Element)
{
if (xmlReader.Name.Equals("html_text"))
{
response.DocumentHtml = QuestionXmlReader.XmlToHtml(xmlReader.ReadElementString());
}
}
else if (xmlReader.NodeType == XmlNodeType.EndElement)
{
if (xmlReader.Name.ToLower().Equals("answer"))
{
isEndCycle = true;
}
}
}
}
catch (Exception ex)
{
ExceptionManager.Instance.LogException(ex);
}
}
示例12: Read
public static CharacterInformation Read(XmlTextReader reader)
{
reader.ReadStartElement ("Class");
string name = reader.ReadElementString ("Name");
reader.ReadEndElement();
return new CharacterInformation
{
Class = name
};
}
示例13: ReadElementString
public static string ReadElementString( XmlTextReader reader, string name, string defaultValue )
{
try
{
return reader.ReadElementString( name );
}
catch (System.Exception)
{
return defaultValue;
}
}
示例14: ReadCharacter
public static ArcanaPlayer ReadCharacter(XmlTextReader reader)
{
reader.ReadStartElement ("Character");
int id = Convert.ToInt32 (reader.ReadElementString ("CharacterID"));
string name = reader.ReadElementString ("Name");
string pclass = reader.ReadElementString ("Class");
int level = Convert.ToInt32 (reader.ReadElementString ("Level"));
reader.ReadEndElement ();
ArcanaPlayer p = classConstructors[pclass] ();
{
p.CharacterID = id;
p.Name = name;
p.Class = pclass;
p.Level = level;
}
return p;
}
示例15: Read
public static DatabaseConfiguration Read(string file)
{
DatabaseConfiguration config = new DatabaseConfiguration ();
StreamReader s = new StreamReader (file);
using (s) {
XmlTextReader tr = new XmlTextReader (s);
tr.MoveToContent ();
if (tr.IsEmptyElement)
return config;
tr.ReadStartElement ("Configuration");
tr.MoveToContent ();
while (tr.NodeType != XmlNodeType.EndElement) {
if (tr.NodeType != XmlNodeType.Element || tr.IsEmptyElement) {
tr.Skip ();
}
else if (tr.LocalName == "DisabledAddins") {
// For back compatibility
tr.ReadStartElement ();
tr.MoveToContent ();
while (tr.NodeType != XmlNodeType.EndElement) {
if (tr.NodeType == XmlNodeType.Element && tr.LocalName == "Addin")
config.addinStatus [tr.ReadElementString ()] = null;
else
tr.Skip ();
tr.MoveToContent ();
}
tr.ReadEndElement ();
}
else if (tr.LocalName == "AddinStatus") {
tr.ReadStartElement ();
tr.MoveToContent ();
while (tr.NodeType != XmlNodeType.EndElement) {
if (tr.NodeType == XmlNodeType.Element && tr.LocalName == "Addin") {
string aid = tr.GetAttribute ("id");
string senabled = tr.GetAttribute ("enabled");
if (senabled.Length == 0 || senabled == "True")
config.addinStatus [aid] = config;
else
config.addinStatus [aid] = null;
}
tr.Skip ();
tr.MoveToContent ();
}
tr.ReadEndElement ();
}
tr.MoveToContent ();
}
}
return config;
}