本文整理汇总了C#中System.Xml.XmlTextReader.ReadSubtree方法的典型用法代码示例。如果您正苦于以下问题:C# XmlTextReader.ReadSubtree方法的具体用法?C# XmlTextReader.ReadSubtree怎么用?C# XmlTextReader.ReadSubtree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlTextReader
的用法示例。
在下文中一共展示了XmlTextReader.ReadSubtree方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RetrieveStockDetailedInfos
public IEnumerable<DetailedQuoteQueryResultModel> RetrieveStockDetailedInfos(List<string> codeList)
{
string urlPrefix = @"https://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.quotes where symbol in (";
string codes = string.Join(@""",""", codeList);
string urlSuffix = ")&env=store://datatables.org/alltableswithkeys";
string url = string.Format(@"{0}""{1}""{2}", urlPrefix, codes, urlSuffix);
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(string.Format(url));
webReq.Method = "GET";
HttpWebResponse webResponse = (HttpWebResponse)webReq.GetResponse();
XmlTextReader reader = new XmlTextReader(webResponse.GetResponseStream());
XmlSerializer serializer = new XmlSerializer(typeof(DetailedQuoteQueryResultModel));
var detailedList = new List<Models.DetailedQuoteQueryResultModel>();
while(reader.Read())
{
if(reader.Name == "quote" && reader.IsStartElement())
{
DetailedQuoteQueryResultModel item = (DetailedQuoteQueryResultModel)serializer.Deserialize(reader.ReadSubtree());
detailedList.Add(item);
}
}
reader.Close();
return detailedList;
}
示例2: ExtractQuery
public static string ExtractQuery(string fileName, TextWriter errorlogger)
{
try
{
string data = File.ReadAllText(fileName);
XmlParserContext context = new XmlParserContext(null, null, null, XmlSpace.None);
Stream xmlFragment = new MemoryStream(Encoding.UTF8.GetBytes(data));
XmlTextReader reader = new XmlTextReader(xmlFragment, XmlNodeType.Element, context);
reader.MoveToContent();
if (reader.NodeType == XmlNodeType.Text)
{
return data;
}
XmlReader reader2 = reader.ReadSubtree();
StringBuilder output = new StringBuilder();
using (XmlWriter writer = XmlWriter.Create(output))
{
writer.WriteNode(reader2, true);
}
StringReader reader3 = new StringReader(data);
for (int i = 0; i < reader.LineNumber; i++)
{
reader3.ReadLine();
}
return reader3.ReadToEnd().Trim();
}
catch (Exception ex)
{
errorlogger.WriteLine(ex.Message);
errorlogger.WriteLine(ex.StackTrace);
}
return string.Format("//Error loading the file - {0} .The the linq file might be a linqpad expression which is not supported in the viewer currently." ,fileName);
}
示例3: ApiMakeList
/// <summary>
/// Main function that retrieves the list from API, including paging
/// </summary>
/// <param name="url">URL of API request</param>
/// <param name="haveSoFar">Number of pages already retrieved, for upper limit control</param>
/// <returns>List of pages</returns>
public List<Article> ApiMakeList(string url, int haveSoFar)
{
// TODO: error handling
List<Article> list = new List<Article>();
string postfix = "";
string newUrl = url;
while (list.Count + haveSoFar < Limit)
{
string text = Tools.GetHTML(newUrl + postfix);
XmlTextReader xml = new XmlTextReader(new StringReader(text));
xml.MoveToContent();
postfix = "";
while (xml.Read())
{
if (xml.Name == "query-continue")
{
XmlReader r = xml.ReadSubtree();
r.Read();
while (r.Read())
{
if (!r.IsStartElement()) continue;
if (!r.MoveToFirstAttribute())
throw new FormatException("Malformed element '" + r.Name + "' in <query-continue>");
postfix += "&" + r.Name + "=" + HttpUtility.UrlEncode(r.Value);
}
}
else if (PageElements.Contains(xml.Name) && xml.IsStartElement())
{
if (!EvaluateXmlElement(xml))
continue;
//int ns = -1;
//int.TryParse(xml.GetAttribute("ns"), out ns);
string name = xml.GetAttribute("title");
if (string.IsNullOrEmpty(name))
{
System.Windows.Forms.MessageBox.Show(xml.ReadInnerXml());
break;
}
// HACK: commented out until we make AWB always load namespaces from the wiki,
// to avoid problems with unknown namespace
//if (ns >= 0) list.Add(new Article(name, ns));
//else
list.Add(new Article(name));
}
}
if (string.IsNullOrEmpty(postfix)) break;
}
return list;
}
示例4: Read_Config
/// <summary> Static class is used to read the configuration file defining oai-pmh elements and metadata prefixes </summary>
/// <param name="ConfigFile"> Path and name of the configuration XML file to read </param>
/// <param name="SystemName"> System name from the system-wide settings, used as a default name for OAI-PMH </param>
/// <param name="SystemAbbreviation"> System identifyer from the system-wide settings, used as a default identifier for OAI-PMH </param>
/// <param name="SystemEmail"> System email(s) from the system-wide settings, used as default admin email(s) for OAI-PMH </param>
/// <returns> Fully configured OAI-PMH configuration object </returns>
public static OAI_PMH_Configuration Read_Config(string ConfigFile, string SystemName, string SystemAbbreviation, string SystemEmail )
{
// Create config value and set some default values
OAI_PMH_Configuration returnValue = new OAI_PMH_Configuration
{
Identifier = SystemAbbreviation,
Name = SystemName,
Identifier_Base = "oai:" + SystemAbbreviation.ToLower() + ":"
};
returnValue.Add_Admin_Email(SystemEmail);
// Streams used for reading
Stream readerStream = null;
XmlTextReader readerXml = null;
try
{
// Open a link to the file
readerStream = new FileStream(ConfigFile, FileMode.Open, FileAccess.Read);
// Open a XML reader connected to the file
readerXml = new XmlTextReader(readerStream);
while (readerXml.Read())
{
if (readerXml.NodeType == XmlNodeType.Element)
{
switch (readerXml.Name.ToLower())
{
case "oai-pmh":
read_oai_details(readerXml.ReadSubtree(), returnValue);
break;
}
}
}
}
catch (Exception ee)
{
returnValue.Error = ee.Message;
}
finally
{
if (readerXml != null)
{
readerXml.Close();
}
if (readerStream != null)
{
readerStream.Close();
}
}
return returnValue;
}
示例5: Read
public static Dictionary<String, Brute> Read()
{
Dictionary<String, Brute> brutes = new Dictionary<String, Brute>();
Console.WriteLine(File.Exists("Users.xml"));
if(File.Exists("Users.xml"))
{
XmlTextReader xml = new XmlTextReader("Users.xml");
while (xml.Read())
{
if (xml.Name.Equals("Brute") && (xml.NodeType == XmlNodeType.Element))
{
xml.Read();
String name = xml.ReadElementString("Name");
short level = Convert.ToInt16(xml.ReadElementString("Level"));
short life = Convert.ToInt16(xml.ReadElementString("Life"));
short strength = Convert.ToInt16(xml.ReadElementString("Strength"));
short agility = Convert.ToInt16(xml.ReadElementString("Agility"));
short speed = Convert.ToInt16(xml.ReadElementString("Speed"));
int image = Convert.ToInt32(xml.ReadElementString("Image"));
Brute brute = new Brute(name, level, life, strength, agility, speed, image);
if(xml.Name.Equals("BonusList") && (xml.NodeType == XmlNodeType.Element))
{
XmlReader inner = xml.ReadSubtree();
while (inner.Read())
{
if (inner.Name.Equals("Bonus") && (xml.NodeType == XmlNodeType.Element))
{
xml.Read();
name = xml.ReadElementString("Name");
life = Convert.ToInt16(xml.ReadElementString("Life"));
strength = Convert.ToInt16(xml.ReadElementString("Strength"));
agility = Convert.ToInt16(xml.ReadElementString("Agility"));
speed = Convert.ToInt16(xml.ReadElementString("Speed"));
image = Convert.ToInt32(xml.ReadElementString("Image"));
brute.BonusList.Add(new Bonus(name, life, strength, agility, speed, image));
}
}
inner.Close();
Console.WriteLine(brute.ToString());
}
brutes.Add(brute.Name, brute);
}
}
xml.Close();
}
return brutes;
}
示例6: Read_Config
/// <summary> Static class is used to read the configuration file defining microservice endpoints </summary>
/// <param name="ConfigFile"> Path and name of the configuration XML file to read </param>
/// <param name="SystemBaseUrl"> System base URL </param>
/// <returns> Fully configured microservices configuration object </returns>
public static MicroservicesClient_Configuration Read_Config(string ConfigFile, string SystemBaseUrl )
{
MicroservicesClient_Configuration returnValue = new MicroservicesClient_Configuration();
// Streams used for reading
Stream readerStream = null;
XmlTextReader readerXml = null;
try
{
// Open a link to the file
readerStream = new FileStream(ConfigFile, FileMode.Open, FileAccess.Read);
// Open a XML reader connected to the file
readerXml = new XmlTextReader(readerStream);
while (readerXml.Read())
{
if (readerXml.NodeType == XmlNodeType.Element)
{
switch (readerXml.Name.ToLower())
{
case "microservicesclient":
read_microservices_client_details(readerXml.ReadSubtree(), returnValue, SystemBaseUrl);
break;
}
}
}
}
catch (Exception ee)
{
returnValue.Error = ee.Message;
}
finally
{
if (readerXml != null)
{
readerXml.Close();
}
if (readerStream != null)
{
readerStream.Close();
}
}
return returnValue;
}
示例7: Read_Config
/// <summary> Read the contact form system configuration file from within the config subfolder on the web app </summary>
/// <param name="ConfigFile"> Complete path and name of the configuration file to read </param>
/// <returns> Built configuration object for the contact form </returns>
public static ContactForm_Configuration Read_Config(string ConfigFile)
{
ContactForm_Configuration returnValue = new ContactForm_Configuration();
// Streams used for reading
Stream readerStream = null;
XmlTextReader readerXml = null;
try
{
// Open a link to the file
readerStream = new FileStream(ConfigFile, FileMode.Open, FileAccess.Read);
// Open a XML reader connected to the file
readerXml = new XmlTextReader(readerStream);
while (readerXml.Read())
{
if (readerXml.NodeType == XmlNodeType.Element)
{
switch (readerXml.Name.ToLower())
{
case "contactform":
Read_ContactForm_Details(readerXml.ReadSubtree(), returnValue);
break;
}
}
}
}
catch (Exception ee)
{
returnValue.Error = ee.Message;
}
finally
{
if (readerXml != null)
{
readerXml.Close();
}
if (readerStream != null)
{
readerStream.Close();
}
}
return returnValue;
}
示例8: GetLocationData
public static Location GetLocationData(string street,
string zip,
string city,
string state,
string country)
{
// Use an invariant culture for formatting numbers.
NumberFormatInfo numberFormat = new NumberFormatInfo();
Location loc = new Location();
XmlTextReader xmlReader = null;
try
{
HttpWebRequest webRequest = GetWebRequest(street, zip, city, state);
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
using (xmlReader = new XmlTextReader(response.GetResponseStream()))
{
while (xmlReader.Read())
{
if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.Name == "Result")
{
XmlReader resultReader = xmlReader.ReadSubtree();
while (resultReader.Read())
{
if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.Name == "Latitude")
loc.Latitude = Convert.ToDouble(xmlReader.ReadInnerXml(), numberFormat);
if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.Name == "Longitude")
{
loc.Longitude = Convert.ToDouble(xmlReader.ReadInnerXml(), numberFormat);
break;
}
}
}
}
}
}
finally
{
if (xmlReader != null)
xmlReader.Close();
}
// Return the location data.
return loc;
}
示例9: GetBody
public string GetBody()
{
using (var reader = new XmlTextReader(new StringReader(Body)))
{
reader.DtdProcessing = DtdProcessing.Ignore;
reader.WhitespaceHandling = WhitespaceHandling.None;
reader.ReadToFollowing("body");
var builder = new StringBuilder();
var sub = reader.ReadSubtree();
while (sub.Read())
{
builder.Append(sub.ReadInnerXml());
}
return builder.ToString();
}
}
示例10: MaterialReader
public MaterialReader()
{
try
{
XmlTextReader reader = new XmlTextReader(Application.StartupPath + "\\config\\materials.xml");
reader.MoveToContent();
while (reader.ReadToFollowing("material"))
{
ProcessItem(reader.ReadSubtree());
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
示例11: AddEntryIntoWebConfig
public static void AddEntryIntoWebConfig(String webConfigFilePath, String path, SPWebConfigModification.SPWebConfigModificationType type, String value)
{
XmlTextReader reader = null;
XmlNode compareNode = null;
string[] nodePath = null;
try
{
reader = new XmlTextReader(webConfigFilePath);
nodePath = path.Split('/');
var notificationDataXmlDocument = new XmlDocument();
notificationDataXmlDocument.LoadXml(value);
compareNode = notificationDataXmlDocument.DocumentElement;
_nodeAttributesFound = new List<bool>();
if (compareNode != null)
if (compareNode.Attributes != null)
#pragma warning disable 168
foreach (object t in compareNode.Attributes)
#pragma warning restore 168
_nodeAttributesFound.Add(false);
}
catch (Exception)
{
_isValueExists = false;
}
if (nodePath != null)
if (nodePath.GetUpperBound(0) > -1 && compareNode != null)
{
while (reader.NodeType != XmlNodeType.Element)
reader.Read();
_isValueExists = false;
IsXmlEntryFoundInWebConfig(path, reader.ReadSubtree(), 0, compareNode);
try
{
reader.Close();
}
catch
{
reader.Close();
}
if (_isValueExists == false)
AddEntrytoWebConfig(webConfigFilePath, path, value);
}
}
示例12: readObjectFromXML
void readObjectFromXML()
{
using (XmlTextReader reader = new XmlTextReader("map.xml"))
{
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
case "Player":
{
createPlayer(reader.ReadSubtree());
}
break;
}
}
}
}
}
示例13: Load
public void Load ()
{
if (!File.Exists (_path))
return;
_privateKeys.Clear ();
_publicKeys.Clear ();
using (XmlTextReader reader = new XmlTextReader (_path)) {
while (reader.Read ()) {
if (!reader.IsStartElement ())
continue;
if (reader.Name != "private" && reader.Name != "public")
continue;
bool isPrivate = (reader.Name == "private");
string name = null, key = null;
XmlReader sub_reader = reader.ReadSubtree ();
while (sub_reader.Read ()) {
if (!sub_reader.IsStartElement ()) continue;
switch (sub_reader.Name) {
case "name":
name = sub_reader.ReadElementString ();
break;
case "key":
key = sub_reader.ReadElementString ();
break;
}
}
if (name != null && key != null) {
if (isPrivate)
_privateKeys.Add (new KeyEntry (name, key));
else
_publicKeys.Add (new KeyEntry (name, key));
}
}
}
if (_privateKeys.Count > 0)
RaisePrivateKeyUpdatedEvent ();
if (_publicKeys.Count > 0)
RaisePublicKeyUpdatedEvent ();
}
示例14: Main
static void Main(string[] args)
{
try
{
if (args.Length >= 4 && args[0] == "Define")
{
var list = new List<string>();
using (FileStream inStream = new FileStream(args[3], FileMode.Open))
using (StreamReader reader = new StreamReader(inStream))
{
for (;;)
{
string line = reader.ReadLine();
if (line == null) break;
list.Add(line);
}
}
bool flag = (args[1] == "on");
foreach (var item in list)
{
Program.Define(item, flag, args[2]);
}
}
else if (args.Length >= 3 && args[0] == "Increment")
{
string projectFilePath = args[1];
string baseDirectory = Path.GetDirectoryName(projectFilePath);
var filePaths = new List<string>();
using (Stream stream = new FileStream(projectFilePath, FileMode.Open))
using (XmlTextReader xml = new XmlTextReader(stream))
{
while (xml.Read())
{
if (xml.NodeType == XmlNodeType.Element)
{
if (xml.LocalName == "Compile")
{
var path = xml.GetAttribute("Include");
string dependentUponBaseDirectory = Path.GetDirectoryName(path);
filePaths.Add(Path.Combine(baseDirectory, path).Replace('\\', '/'));
using (var xmlSubtree = xml.ReadSubtree())
{
while (xmlSubtree.Read())
{
if (xmlSubtree.NodeType == XmlNodeType.Element)
{
if (xmlSubtree.LocalName == "DependentUpon")
{
filePaths.Add(Path.Combine(baseDirectory, dependentUponBaseDirectory, xml.ReadString()).Replace('\\', '/'));
}
}
}
}
}
}
}
}
string assemblyInfoFilePath = Path.Combine(baseDirectory, args[2]).Replace('\\', '/');
filePaths.Remove(assemblyInfoFilePath);
filePaths.Sort();
var regex = new Regex(@"^( *)\[( *)assembly( *):( *)AssemblyVersion( *)\(( *)" + "\"" + @"(\d*)\.(\d*)\.(\d*)\.(\d*)" + "\"" + @"( *)\)( *)\](.*)$");
byte[] hash = Program.GetHash(filePaths);
using (var readerStream = new StreamReader(assemblyInfoFilePath))
using (var writerStream = new StreamWriter(assemblyInfoFilePath + "~", false, Encoding.UTF8))
{
for (;;)
{
var line = readerStream.ReadLine();
if (line == null) break;
var match = regex.Match(line);
if (match.Success)
{
int i = int.Parse(match.Groups[10].Value);
if (match.Groups[13].Value.TrimStart().StartsWith("//"))
{
if (!Unsafe.Equals(hash, NetworkConverter.FromBase64UrlString(match.Groups[13].Value.TrimStart().Remove(0, 2).Trim())))
{
i++;
}
}
writerStream.WriteLine(
string.Format(
"{0}[{1}assembly{2}:{3}AssemblyVersion{4}({5}\"{6}.{7}.{8}.{9}\"{10}){11}]{12}",
match.Groups[1].Value,
match.Groups[2].Value,
//.........这里部分代码省略.........
示例15: Import
public bool Import(string fileName, bool deleteBeforeImport, bool showProgress)
{
//System.Diagnostics.Debugger.Launch();
_errorMessage = "";
if (_isImporting == true)
{
_errorMessage = "already importing...";
return false;
}
_isImporting = true;
bool result = false;
XmlTextReader xmlReader = null;
// remove old programs
_status.Status = "Removing old programs";
_status.Channels = 0;
_status.Programs = 0;
_status.StartTime = DateTime.Now;
_status.EndTime = new DateTime(1971, 11, 6);
if (showProgress && ShowProgress != null) ShowProgress(_status);
layer.RemoveOldPrograms();
/*
// for each channel, get the last program's time
Dictionary<int, DateTime> lastProgramForChannel = new Dictionary<int, DateTime>();
IList channels = Channel.ListAll();
foreach (Channel ch in channels)
{
SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof(TvDatabase.Program));
sb.AddConstraint(Operator.Equals, "idChannel", ch.IdChannel);
sb.AddOrderByField(false, "starttime");
sb.SetRowLimit(1);
SqlStatement stmt = sb.GetStatement(true);
IList programsInDbs = ObjectFactory.GetCollection(typeof(TvDatabase.Program), stmt.Execute());
DateTime lastProgram = DateTime.MinValue;
if (programsInDbs.Count > 0)
{
TvDatabase.IProgram p = (TvDatabase.Program)programsInDbs[0];
lastProgram = p.EndTime;
}
lastProgramForChannel[ch.IdChannel] = lastProgram;
}*/
//TVDatabase.SupressEvents = true;
bool useTimeZone = layer.GetSetting("xmlTvUseTimeZone", "false").Value == "true";
int hours = Int32.Parse(layer.GetSetting("xmlTvTimeZoneHours", "0").Value);
int mins = Int32.Parse(layer.GetSetting("xmlTvTimeZoneMins", "0").Value);
int timeZoneCorrection = hours * 60 + mins;
ArrayList Programs = new ArrayList();
Dictionary<int, ChannelPrograms> dChannelPrograms = new Dictionary<int, ChannelPrograms>();
try
{
Log.WriteFile("xmltv import {0}", fileName);
//
// Make sure the file exists before we try to do any processing
//
if (File.Exists(fileName))
{
_status.Status = "Loading channel list";
_status.Channels = 0;
_status.Programs = 0;
_status.StartTime = DateTime.Now;
_status.EndTime = new DateTime(1971, 11, 6);
if (showProgress && ShowProgress != null) ShowProgress(_status);
Dictionary<int, Channel> guideChannels = new Dictionary<int, Channel>();
IList<Channel> allChannels = Channel.ListAll();
int iChannel = 0;
xmlReader = new XmlTextReader(fileName);
#region import non-mapped channels by their display-name
if (xmlReader.ReadToDescendant("tv"))
{
// get the first channel
if (xmlReader.ReadToDescendant("channel"))
{
do
{
String id = xmlReader.GetAttribute("id");
if (id == null || id.Length == 0)
{
Log.Error(" channel#{0} doesnt contain an id", iChannel);
}
else
{
String displayName = null;
XmlReader xmlChannel = xmlReader.ReadSubtree();
xmlChannel.ReadStartElement(); // read channel
// now, xmlChannel is positioned on the first sub-element of <channel>
//.........这里部分代码省略.........