本文整理匯總了C#中System.Xml.XmlTextReader.IsStartElement方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlTextReader.IsStartElement方法的具體用法?C# XmlTextReader.IsStartElement怎麽用?C# XmlTextReader.IsStartElement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlTextReader
的用法示例。
在下文中一共展示了XmlTextReader.IsStartElement方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: readCurrentElement
/// <summary>
/// Parser recursiv de elemente XML.
/// </summary>
/// <param name="reader">Cititorul secvenţial care a deschis fişierul XML</param>
/// <returns>Elementul XML parsat care conţine toate atributele şi subelementele sale</returns>
private static XMLElement readCurrentElement(XmlTextReader reader)
{
if (!reader.IsStartElement()) {
return null;
}
bool hasChildren = !reader.IsEmptyElement;
XMLElement result = new XMLElement();
for (int i = 0; i < reader.AttributeCount; ++i) {
reader.MoveToAttribute(i);
result.addAttribute(reader.Name, reader.Value);
}
if (hasChildren) {
while (reader.Read() && reader.NodeType != XmlNodeType.EndElement) {
if (reader.IsStartElement()) {
result.addElement(reader.Name, readCurrentElement(reader));
}
}
}
reader.Read();
return result;
}
示例2: ParseFromXml
public static Test ParseFromXml(string pathFile)
{
var test = new Test {PathFile = pathFile};
var xtr = new XmlTextReader(pathFile) {WhitespaceHandling = WhitespaceHandling.None};
xtr.Read(); // read the XML declaration node, advance to <test> tag
xtr.Read();
test.TestName = xtr.GetAttribute("testname");
test.Order = xtr.GetAttribute("order");
test.Questions=new List<Question>();
while (!xtr.EOF)
{
if (xtr.Name == "test" && !xtr.IsStartElement()) break;
while (xtr.Name != "question" || !xtr.IsStartElement())
xtr.Read(); // advance to <question> tag
Question question;
switch (xtr.GetAttribute("type"))
{
case "Radio":
question = QuestionWithVariants(xtr);
break;
case "Checked":
question = QuestionWithVariants(xtr);
break;
default:
throw new Exception();
}
test.Questions.Add(question);
xtr.Read();// and now either at <question> tag or </test> tag
}
xtr.Close();
test.DateDownload = DateTime.Now;
return test;
}
示例3: LoadFromFile
/// <summary>
/// Loads the namespaces and properties from the file into
/// Namespace and Property objects.
/// </summary>
///
/// <param name="filename">The name of the file.</param>
/// <returns>The populated Namespace objects</returns>
///
/// <exception cref="NamespaceClashException">
/// If a namespace clash occurs.
/// </exception>
///
/// <exception cref="PropertyClashException">
/// If a property clash occurs.
/// </exception>
///
/// <exception cref="InvalidConfigFileException">
/// If the configuration file is invalid.
/// </exception>
///
/// <exception cref="UnknownFormatException">
/// If the format of the configuration file is unkown.
/// </exception>
///
/// <exception cref="IOException">
/// If an I/O error occurs.
/// </exception>
public List<Namespace> LoadFromFile(string filename)
{
try
{
var namespaces = new List<Namespace>();
using (var reader = new XmlTextReader(filename))
{
while (reader.Read())
{
if (reader.Name.ToLower() == "namespace" && reader.IsStartElement())
{
var namespaceName = reader.GetAttribute("name");
var currentNamespace = new Namespace(namespaceName);
namespaces.Add(currentNamespace);
while (reader.Read())
{
if (reader.Name.ToLower() == "property" && reader.IsStartElement())
{
var propertyName = reader.GetAttribute("name");
var valueList = new List<string>();
while (reader.Read())
{
if (reader.Name.ToLower() == "value" && reader.IsStartElement())
{
reader.Read();
valueList.Add(reader.Value);
}
else if (reader.Name.ToLower() == "property" && reader.NodeType == XmlNodeType.EndElement)
{
break;
}
}
currentNamespace.AddProperty(new Property(propertyName, valueList));
}
else if (reader.Name.ToLower() == "namespace" && reader.NodeType == XmlNodeType.EndElement)
{
break;
}
}
}
else if (reader.Name.ToLower() == "ConfigManager" && reader.NodeType == XmlNodeType.EndElement)
{
break;
}
}
}
return namespaces;
}
catch (XmlException e)
{
throw new InvalidConfigFileException("'" + filename + "' contains errors.", e);
}
}
示例4: LoadURLList
public void LoadURLList()
{
XmlTextReader reader = null;
try
{
reader = new XmlTextReader(Configuration.Instance.UrlList);
reader.Read();
}
catch
{
if (reader != null)
reader.Close();
SaveURLList();
reader = new XmlTextReader(Configuration.Instance.UrlList);
reader.Read();
}
if(reader.Name == "URLList" && !reader.IsEmptyElement)
{
while (!(reader.Name == "URLList" && reader.NodeType == XmlNodeType.EndElement))
{
reader.Read();
if (reader.Name == "ShellURL" && reader.IsStartElement())
{
string url = "";
string password = "";
string prestring = "";
while (!(reader.Name == "ShellURL" && reader.NodeType == XmlNodeType.EndElement))
{
reader.Read();
if (reader.IsStartElement())
{
switch (reader.Name)
{
case "URL":
reader.Read();
url = reader.Value;
break;
case "Password":
reader.Read();
password = reader.Value;
break;
case "PreString":
reader.Read();
prestring = reader.Value;
break;
}
}
}
ShellURLs.Add(new ShellURL(url, password, prestring));
}
}
}
reader.Close();
}
示例5: Load
public bool Load()
{
if (!File.Exists(this._path))
{
throw new Exception("Saved Template Input file not found: " + this._path);
}
else
{
bool inStartElement = true;
string tagName;
string projectDirPath = this._path.Substring(0, (this._path.LastIndexOf('\\') + 1));
XmlTextReader xr = new XmlTextReader(File.OpenText(this._path));
while (xr.Read())
{
inStartElement = xr.IsStartElement();
tagName = xr.LocalName;
if (inStartElement && ((tagName == "obj")) )
{
tagName = this.InputData.ReadXML(xr);
}
}
xr.Close();
return true;
}
}
示例6: Load
public Exception Load(out Dictionary<string, object> settingEntity, string path)
{
settingEntity = new Dictionary<string, object>();
try
{
using (XmlTextReader reader = new XmlTextReader(path))
{
string tag = String.Empty;
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element && reader.IsStartElement())
tag = reader.Name;
if (reader.NodeType == XmlNodeType.Text && tag != String.Empty)
settingEntity[tag] = reader.Value;
}
}
return null;
}
catch (Exception e)
{
return e;
}
}
示例7: BuildPatternCache
public static void BuildPatternCache()
{
Pattern.FlushPatternCache();
Pattern.sPatternCategories.Clear();
Pattern.sPatternCache.Clear();
KeySearch search = new KeySearch(0xd4d9fbe5);
foreach (ResourceKey key in search)
{
string xmlFragment = Simulator.LoadXMLString(key);
if ((xmlFragment != null) && (xmlFragment != string.Empty))
{
XmlTextReader reader = new XmlTextReader(xmlFragment, XmlNodeType.Document, null);
while (reader.Read())
{
if (reader.IsStartElement("patternlist"))
{
try
{
Pattern.ParseCategories(reader);
}
catch (Exception e)
{
Common.Exception("ResourceKey: " + key, e);
}
}
}
}
}
Pattern.sCacheBuilt = true;
}
示例8: ReturnGitHubChecksumDictionary
internal static Dictionary<string, string> ReturnGitHubChecksumDictionary()
{
Dictionary<string, string> returnValues = new Dictionary<string, string>();
try
{
using (XmlTextReader reader = new XmlTextReader(GitHubProjectUrl))
{
// simply (and easily) skip the junk at the beginning
reader.MoveToContent();
//reader.ReadToDescendant("FileList");
while (reader.Read())
{
if ((reader.NodeType == XmlNodeType.Element) &&
(reader.IsStartElement()) &&
reader.HasAttributes)
{
string fileName = reader.GetAttribute(0);
string fileHash = reader.GetAttribute(1);
returnValues.Add(fileName, fileHash);
}
}
}
}
catch (Exception)
{
}
return returnValues;
}
示例9: ReadKey
public void ReadKey(string keyId, Domain domain, string keyName, Type dataType, object defaultVal, string inputStr)
{
//<key id="nd0" for="node" attr.name="X1" attr.type="string" />
var keyReader = new KeyReader();
var reader = new XmlTextReader(new StringReader(inputStr));
reader.Read();
Assert.True(reader.IsStartElement());
Assert.True(string.Compare("key", reader.Name, true) == 0, string.Format("Reader.Name should match expected, not: \"{0}\"", reader.Name));
string retrievedKeyId;
Domain retrievedDomain;
string retrievedAttribName;
Type retrievedType;
object retrievedDefault;
keyReader.Read(out retrievedKeyId, out retrievedDomain, out retrievedAttribName, out retrievedType, out retrievedDefault, reader);
Assert.Equal(keyId, retrievedKeyId);
Assert.Equal(domain, retrievedDomain);
Assert.Equal(keyName, retrievedAttribName);
Assert.Equal(dataType, retrievedType);
Assert.Equal(defaultVal, retrievedDefault);
if (!reader.IsEmptyElement)
Assert.True(string.Compare("key", reader.Name, true) == 0, string.Format("End Reader.Name should match expected, not: \"{0}\"", reader.Name));
}
示例10: ReadConfiguration
private ConfigurationContainer ReadConfiguration(string file)
{
ConfigurationContainer container = new ConfigurationContainer();
XmlTextReader reader = null;
try {
reader = new XmlTextReader(new StreamReader(file));
while (!reader.EOF) {
reader.Read();
if (reader.IsStartElement()) {
if (reader.Name == "WaitTime") {
reader.MoveToContent();
reader.Read();
container.WaitTime = int.Parse(reader.Value);
}
else if (reader.Name == "AutoStart") {
reader.MoveToContent();
reader.Read();
container.AutoStart = bool.Parse(reader.Value);
}
else if (reader.Name == "MaxRetryCount") {
reader.MoveToContent();
reader.Read();
container.MaxRetryCount = int.Parse(reader.Value);
}
}
}
return container;
}
catch { return null; }
finally { if (reader != null) reader.Close(); }
}
示例11: 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;
}
示例12: 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);
}
}
示例13: ReadXML
public static void ReadXML(string xmlName)
{
XmlTextReader xmltextreader = new XmlTextReader(xmlName);
while (xmltextreader.Read())
{
if (xmltextreader.IsStartElement())
{
// Get element name and switch on it.
switch (xmltextreader.Name)
{
case "IRCamProperties":
irCamProperties.ReadXML(xmltextreader, "IRCamProperties");
break;
case "VICamProperties":
viCamProperties.ReadXML(xmltextreader, "VICamProperties");
break;
case "GPSProperties":
gpsProperties.ReadXML(xmltextreader, "GPSProperties");
break;
}
}
}
xmltextreader.Close();
}
示例14: TriviaServer
public TriviaServer(int port)
{
IPAddress ipAddress = Dns.Resolve(Dns.GetHostName()).AddressList[0];
this.port = port;
this.connector = new TCPIPconnectorServer(port, ipAddress);
this.dbConnected = true;
string login = "";
string password = "";
string dbName = "";
XmlTextReader reader;
try
{
reader = new XmlTextReader("config.xml");
while (reader.Read())
{
if (reader.IsStartElement())
{
if (reader.Name == "login")
{
login = reader.ReadString();
}
if (reader.Name == "password")
{
password = reader.ReadString();
}
if (reader.Name == "dbName")
{
dbName = reader.ReadString();
}
}
}
reader.Close();
}
catch (Exception e)
{
Logging.LogEvent("Constructor|XmlTextReader", e.Message);
}
try
{
this.DBConnector = new DatabaseConnector("localhost", login, password, dbName);
TriviaServer.answerID = this.DBConnector.GetNumberOfUserAnswer() + 1;
}
catch (Exception e)
{
Logging.LogEvent("Constructor|DatabaseConnector", e.Message + " " + login + " " + password + " " + dbName);
this.dbConnected = false;
}
this.userList = new List<User>();
this.userThread = new List<Thread>();
this.mutex = new ManualResetEvent(true);
}
示例15: Load
public static VexObject Load(string fileFullPathAndName)
{
VexObject vo;
string rootFolder = Path.GetDirectoryName(fileFullPathAndName);
string fileNameOnly = Path.GetFileNameWithoutExtension(fileFullPathAndName);
Environment.CurrentDirectory = rootFolder;
string definitionsFolder = "";
string instancesFolder = "";
uint rootId = 0;
vo = new VexObject(fileNameOnly);
FileStream fs = new FileStream(fileFullPathAndName, FileMode.Open);
XmlTextReader r = new XmlTextReader(fs);
r.ReadStartElement("UIL");
while (r.Read())
{
if (r.IsStartElement())
{
switch (r.Name)
{
case "DefinitionsFolder":
if (r.Read())
{
definitionsFolder = r.Value.Trim();
}
break;
case "InstancesFolder":
if (r.Read())
{
instancesFolder = r.Value.Trim();
}
break;
case "RootId":
if (r.Read())
{
rootId = uint.Parse(r.Value.Trim(), NumberStyles.Any);
}
break;
}
}
}
fs.Close();
string defsPath = rootFolder + Path.DirectorySeparatorChar + fileNameOnly + definitionsFolder;
LoadDefinitions(defsPath, vo);
string instsPath = rootFolder + Path.DirectorySeparatorChar + fileNameOnly + instancesFolder;
LoadInstances(instsPath, vo);
vo.Root = (Timeline)vo.Definitions[rootId];
return vo;
}