本文整理汇总了C#中XmlTextReader.MoveToNextAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# XmlTextReader.MoveToNextAttribute方法的具体用法?C# XmlTextReader.MoveToNextAttribute怎么用?C# XmlTextReader.MoveToNextAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlTextReader
的用法示例。
在下文中一共展示了XmlTextReader.MoveToNextAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DumpXmlToArray
public void DumpXmlToArray (string filename)
{
XmlTextReader reader = new XmlTextReader (filename);
reader.WhitespaceHandling = WhitespaceHandling.None;
int i = 0;
while (reader.Read ()) {
switch (reader.NodeType) {
case XmlNodeType.Element :
if (reader.Name == "album") {
reader.MoveToNextAttribute ();
album_name = reader.Value;
reader.MoveToNextAttribute ();
picture_count = Convert.ToInt64 (reader.Value);
}
break;
case XmlNodeType.Text :
if (reader.Name == "location")
picture_data [i].Location = reader.Value;
if (reader.Name == "title")
picture_data [i].Title = reader.Value;
if (reader.Name == "date")
picture_data [i].Date = reader.Value;
if (reader.Name == "keywords")
picture_data [i].Keywords = reader.Value;
if (reader.Name == "comments")
picture_data [i].Comments = reader.Value;
if (reader.Name == "index")
picture_data [i].Index = Convert.ToInt64 (reader.Value);
case XmlNodeType.EndElement :
if (reader.Name == "picture") {
i++;
picture_data [i] = new PictureInfo ();
}
break;
default :
continue;
break;
}
}
reader.Close ();
}
示例2: ReadXml
private static string ReadXml(string filename, int ID)
{
string strLastVersion = "";
XmlTextReader reader = new XmlTextReader(filename);
while (reader.Read())
{
if (reader.HasAttributes)
{
while (reader.MoveToNextAttribute())
{
if (reader.Name == "id")
{
if (reader.Value == ID.ToString())
{
strLastVersion = reader.ReadString();
reader.Close();
return strLastVersion;
}
}
}
}
}
return strLastVersion;
}
示例3: Read
public static void Read()
{
XmlTextReader reader = new XmlTextReader("books.xml");
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element: // The node is an element.
Console.Write("<" + reader.Name);
while (reader.MoveToNextAttribute()) // Read the attributes.
Console.Write(" " + reader.Name + "='" + reader.Value + "'");
Console.WriteLine(">");
break;
case XmlNodeType.Text: //Display the text in each element.
Console.WriteLine (reader.Value);
break;
case XmlNodeType. EndElement: //Display the end of the element.
Console.Write("</" + reader.Name);
Console.WriteLine(">");
break;
}
}
// Do some work here on the data.
Console.ReadLine();
}
示例4: GetTargetNamespace
public static string GetTargetNamespace (string src)
{
XmlTextReader reader = null;
try
{
reader = new XmlTextReader (src);
reader.WhitespaceHandling = WhitespaceHandling.None;
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element &&
reader.LocalName == "schema")
{
while (reader.MoveToNextAttribute ())
{
if (reader.Name == "targetNamespace")
return reader.Value;
}
}
}
return "";
}
finally
{
if (reader != null)
reader.Close ();
}
}
示例5: LoadItems
public bool LoadItems()
{
Item item = null;
if(File.Exists(file))
{
XmlTextReader reader = new XmlTextReader(file);
while(reader.Read())
{
switch(reader.Name.ToString().ToLower())
{
case "item": //assuming there is more than one item
item = new Item();
if(reader.HasAttributes)
{
while(reader.MoveToNextAttribute())
{
switch(reader.Name.ToString().ToLower())
{
case "id":
item.id = Convert.ToInt32(reader.Value);
break;
case "name":
item.name = reader.Value;
break;
case "description":
item.description = reader.Value;
break;
case "file":
item.fileDir = reader.Value;
break;
case "base": //base position declared
string val = reader.Value;
string[] split = val.Split(',');
item.basePosition = new Vector3(float.Parse(split[0]), float.Parse(split[1]), float.Parse(split[2]));
break;
}
}
//if we get this point, it's mean there is no more attrs to read
if (item != null)
{
items.Add(item);
}
}
break;
}
}
reader.Close();
loaded = true;
}
return loaded;
}
示例6: LoadCharacters
public bool LoadCharacters()
{
Character chart = null;
if (File.Exists(file))
{
XmlTextReader reader = new XmlTextReader(file);
while (reader.Read())
{
switch (reader.Name.ToString().ToLower())
{
case "character": //assuming there is more than one chart
chart = new Character();
if (reader.HasAttributes)
{
while (reader.MoveToNextAttribute())
{
switch (reader.Name.ToString().ToLower())
{
case "id":
chart.id = Convert.ToInt32(reader.Value);
break;
case "name":
chart.name = reader.Value;
break;
case "blocked":
chart.blocked = (Convert.ToInt32(reader.Value) == 1);
break;
case "file":
chart.fileDir = reader.Value;
break;
case "base": //base position declared
string val = reader.Value;
string[] split = val.Split(',');
chart.basePosition = new Vector3(float.Parse(split[0]), float.Parse(split[1]), float.Parse(split[2]));
break;
}
}
//if we get this point, it's mean there is no more attrs to read
if (chart != null)
{
characters.Add(chart);
}
}
break;
}
}
reader.Close();
loaded = true;
}
return loaded;
}
示例7: UserPrefs
public UserPrefs(String file)
{
userPrefsFile = new XmlTextReader(file);
userPrefs = new Hashtable();
String id ="", value="";
while (userPrefsFile.Read())
{
switch (userPrefsFile.NodeType)
{
case XmlNodeType.Element:
id = userPrefsFile.Name;
while (userPrefsFile.MoveToNextAttribute())
value = userPrefsFile.Value;
break;
}
if (id != "i" && value != "v")
importPreference(id, value);
id = "i";
value = "v";
}
}
示例8: ReadXml
private static string ReadXml(string filename, int id)
{
string lastVersion = string.Empty;
XmlTextReader reader = new XmlTextReader(filename);
while (reader.Read())
{
if (reader.HasAttributes)
{
while (reader.MoveToNextAttribute())
{
if (reader.Name == "id")
{
if (reader.Value == id.ToString())
{
return lastVersion = reader.ReadString();
}
}
}
}
}
return lastVersion;
}
示例9: readAllKeyValsInXML
private static Hashtable readAllKeyValsInXML(string LangFilePath)
{
Hashtable AllKeyVals = new Hashtable();
XmlTextReader reader = new XmlTextReader(LangFilePath);
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element: // The node is an element.
if (reader.Name == "Row")
{
string tmpKey = string.Empty;
string tmpVal = string.Empty;
while (reader.MoveToNextAttribute()) // Read the attributes.
{
if (reader.Name == "key") tmpKey = reader.Value;
else if (reader.Name == "value") tmpVal = reader.Value;
}
if (!AllKeyVals.ContainsKey(tmpKey))
{
AllKeyVals.Add(tmpKey, tmpVal);
}
}
break;
case XmlNodeType.Text: //Display the text in each element.
break;
case XmlNodeType.EndElement: //Display the end of the element.
break;
}
}
reader.Close();
return AllKeyVals;
}
示例10: getClientLangXML
/// <summary>
///
/// </summary>
/// <param name="KeyValsRelativePath">@"~\Stock\language\en\DI_English [en].xml"</param>
/// <param name="PageMappingRelativePath">@"~\Stock\language\PageKeyMapping_DataView.xml"</param>
/// <returns></returns>
public static string getClientLangXML(string KeyValsRelativePath, string PageMappingRelativePath)
{
XmlDocument doc = new XmlDocument();// Create the XML Declaration, and append it to XML document
Hashtable AllKeyVals = readAllKeyValsInXML(KeyValsRelativePath);
XmlTextReader reader = new XmlTextReader(PageMappingRelativePath);
XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);
doc.AppendChild(dec);// Create the root element
XmlElement root = doc.CreateElement("Language");
try
{
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element: // The node is an element.
if (reader.Name == "Associate")
{
XmlElement lng = doc.CreateElement("lng");
while (reader.MoveToNextAttribute()) // Read the attributes.
{
if (reader.Name == "MasterKey")
{
if (AllKeyVals.Contains(reader.Value))
{
lng.SetAttribute("val", AllKeyVals[reader.Value].ToString());
}
}
else if (reader.Name == "ElementID")
{
lng.SetAttribute("id", reader.Value);
}
else if (reader.Name == "ElementProperty")
{
lng.SetAttribute("prop", reader.Value);
}
else
{
lng.SetAttribute(reader.Name, reader.Value);
}
}
root.AppendChild(lng);
}
break;
case XmlNodeType.Text: //Display the text in each element.
break;
case XmlNodeType.EndElement: //Display the end of the element.
break;
}
}
reader.Close();
doc.AppendChild(root);
}
catch (Exception ex)
{
Global.CreateExceptionString(ex, "KeyValsRelativePath :" + KeyValsRelativePath + "reader.Name : " + reader.Name + " reader.Value : " + reader.Value);
}
return doc.OuterXml;
}
示例11: loadFromFile
private void loadFromFile(string file)
{
string key = "", value = "";
XmlTextReader reader = new XmlTextReader(file);
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element: // The node is an element.
while (reader.MoveToNextAttribute()) // Read the attributes.
{
if (reader.Name.Equals("key"))
key = reader.Value;
}
break;
case XmlNodeType.Text: //Display the text in each element.
if (!key.Equals(""))
value = reader.Value;
break;
case XmlNodeType.EndElement: //Display the end of the element.
break;
}
if (key != "" && value != "")
{
list.Add(key, value);
key = value = "";
}
}
reader.Close();
}
示例12: ReadConfigsIndex
private void ReadConfigsIndex()
{
XmlTextReader reader = new XmlTextReader(Program.ProgramSettings.ConfigsIndexURL);
ConfigPack temp = new ConfigPack();
while (reader.Read())
{
if (temp.FriendlyName != null && temp.URL != null && temp.upd != 0)
temp = new ConfigPack();
switch (reader.NodeType)
{
case XmlNodeType.Element:
if (reader.Name == "cpack-index-sheet")
continue;
//Console.Write("<{0}", reader.Name);
while (reader.MoveToNextAttribute())
{
//Console.Write(" {0}='{1}'", reader.Name, reader.Value);
switch (reader.Name)
{
case "name":
temp.FriendlyName = reader.Value;
break;
case "upd":
temp.upd = int.Parse(reader.Value);
break;
}
}
//Console.Write(">");
break;
case XmlNodeType.Text:
//Console.WriteLine(reader.Value);
temp.URL = reader.Value;
if (temp.URL != null && temp.FriendlyName != null)
ConfigList.Add(temp);
break;
case XmlNodeType.EndElement:
//Console.WriteLine("</{0}>", reader.Name);
if (temp.URL != null && temp.FriendlyName != null)
ConfigList.Add(temp);
break;
}
}
}
示例13: LoadConfigFile
void LoadConfigFile()
{
try
{
XmlTextReader doc = new XmlTextReader("reddit_api.xml");
while (doc.Read())
{
if (doc.NodeType == XmlNodeType.Element)
{
switch (doc.Name)
{
case "seconds_between_api_calls":
m_seconds_between_calls = doc.ReadElementContentAsDouble();
break;
case "seconds_before_cache_invalid":
m_seconds_before_cache_invalid = doc.ReadElementContentAsDouble();
break;
case "default_content_limit":
m_content_limit = doc.ReadElementContentAsInt();
break;
case "object_mappings":
string kind = "", objectname = "";
while (doc.MoveToNextAttribute())
{
if (doc.Name == "kind")
{
kind = doc.Value;
}
else if (doc.Name == "object")
{
objectname = doc.Value;
}
}
if (m_object_mapping.ContainsKey(kind))
m_object_mapping["kind"] = objectname;
else
m_object_mapping.Add(kind, objectname);
break;
case "domain":
m_domain = doc.ReadElementContentAsString();
break;
}
}
}
doc.Close();
}
catch (FileNotFoundException)
{
StreamWriter s = new StreamWriter("reddit_api.xml");
s.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
s.WriteLine("<reddit_api_config>");
s.WriteLine("<seconds_between_api_calls>2</seconds_between_api_calls>" );
s.WriteLine("<seconds_before_cache_invalid>30</seconds_before_cache_invalid>");
s.WriteLine("<default_content_limit>25</default_content_limit>");
s.WriteLine("<object_mappings kind=\"comment_kind\" object=\"t1\"/>");
s.WriteLine("<object_mappings kind=\"message_kind\" object=\"t4\"/>");
s.WriteLine("<object_mappings kind=\"more_kind\" object =\"more\"/>");
s.WriteLine("<object_mappings kind=\"redditor_kind\" object=\"t2\"/>");
s.WriteLine("<object_mappings kind=\"submission_kind\" object=\"t3\"/>");
s.WriteLine("<object_mappings kind=\"subreddit_kind\" object=\"t5\"/>");
s.WriteLine("<object_mappings kind=\"userlist_kind\" object=\"UserList\"/>");
s.WriteLine("<domain>http://www.reddit.com/</domain>");
s.WriteLine("<!--");
s.WriteLine("message_kind: t7");
s.WriteLine("submission_kind: t6");
s.WriteLine("subreddit_kind: t5");
s.WriteLine(" -->");
s.WriteLine("</reddit_api_config>");
s.Close();
LoadConfigFile();
}
}
示例14: GetAttrValue
private string GetAttrValue( XmlTextReader xtr, string strName )
{
xtr.MoveToFirstAttribute();
do
{
if( xtr.LocalName.Equals( strName ) )
return xtr.Value;
} while( xtr.MoveToNextAttribute() );
return null;
}
示例15: ProcessXml
/// <summary>
/// Parse the downloaded XML file.
/// </summary>
private static void ProcessXml()
{
if (!File.Exists(_Filename))
{
throw new Exception("The currencies haven't been downloaded.");
}
Dictionary<string, double> currencies = new Dictionary<string, double>();
currencies.Add("EUR", 1.0);
using (FileStream fs = new FileStream(_Filename, FileMode.Open, FileAccess.Read, FileShare.Read))
{
using (XmlTextReader xmlReader = new XmlTextReader(fs))
{
while (xmlReader.Read())
{
for (int i = 0; i < xmlReader.AttributeCount; i++)
{
AddCurrency(currencies, xmlReader);
xmlReader.MoveToNextAttribute();
}
}
}
}
_Currencies = currencies;
OnUpdateComplete();
}