本文整理汇总了C#中XmlTextReader.Read方法的典型用法代码示例。如果您正苦于以下问题:C# XmlTextReader.Read方法的具体用法?C# XmlTextReader.Read怎么用?C# XmlTextReader.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlTextReader
的用法示例。
在下文中一共展示了XmlTextReader.Read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDialogById
public List<string> GetDialogById(string id)
{
XmlTextReader reader = new XmlTextReader(XMLFileName);
List<string> texts = new List<string>();
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element && reader.Name == id)
{
int i = 0;
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.EndElement && reader.Name == id)
{
break;
}
if (reader.NodeType == XmlNodeType.Element && reader.Name == ("text_" + i))
{
texts.Add(reader.ReadElementContentAsString());
i++;
}
}
}
}
reader.Close();
return texts;
}
示例2: readXML
private void readXML()
{
string fileName = "/home/nasser/Desktop/ncg/ncg/sampledata.xml";
if (File.Exists (fileName)) {
XmlTextReader xreader = new XmlTextReader(fileName);
label1.Text="";
while(xreader.Read ())
{
if(xreader.NodeType==XmlNodeType.Element)
{
xreader.Read();
if(xreader.NodeType==XmlNodeType.Text)
{
}
}
/*label1.Text+="\nnode type :\t"+xreader.NodeType.ToString ();
label1.Text+="\nname : \t\t"+xreader.Name;
label1.Text+="\nvalue :\t\t"+xreader.Value;
label1.Text+="\n-----------------";*/
}
//label1.Text+="\n"+xreader.GetAttribute("version").ToString ();
}
else
label1.Text="file not exists";
}
示例3: ReadXml
public static List<string> ReadXml(string path, string colum)
{
List<string> listOfElements = new List<string>();
XmlTextReader textReader = new XmlTextReader(path);
int foundName = 0;
while (textReader.Read())
{
if (foundName > 0 && textReader.Name != string.Empty && !String.Equals(textReader.Name, colum, StringComparison.CurrentCultureIgnoreCase))
foundName = 0;
if (foundName == 2 && String.Equals(textReader.Name, colum, StringComparison.CurrentCultureIgnoreCase))
{
foundName = 0; continue;
}
if (foundName == 0 && String.Equals(textReader.Name, colum, StringComparison.CurrentCultureIgnoreCase))
{
foundName = 1; continue;
}
if (foundName != 1 || textReader.Name != string.Empty) continue;
listOfElements.Add(textReader.Value);
}
textReader.Close();
return listOfElements;
}
示例4: 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();
}
示例5: 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 ();
}
}
示例6: RunNotWellFormedTest
static void RunNotWellFormedTest (string subdir, bool isSunTest)
{
string basePath = @"xml-test-suite/xmlconf/" + subdir + @"/not-wf";
DirectoryInfo [] dirs = null;
if (isSunTest)
dirs = new DirectoryInfo [] {new DirectoryInfo (basePath)};
else
dirs = new DirectoryInfo (basePath).GetDirectories ();
foreach (DirectoryInfo di in dirs) {
foreach (FileInfo fi in di.GetFiles ("*.xml")) {
try {
XmlTextReader xtr = new XmlTextReader (fi.FullName);
xtr.Namespaces = false;
while (!xtr.EOF)
xtr.Read ();
Console.WriteLine ("Incorrectly wf: " + subdir + "/" + di.Name + "/" + fi.Name);
} catch (XmlException) {
// expected
} catch (Exception ex) {
Console.WriteLine ("Unexpected Error: " + subdir + "/" + di.Name + "/" + fi.Name + "\n" + ex.Message);
}
}
}
}
示例7: GetItemsList
public string[] GetItemsList(string prefixText, int count)
{
List<string> suggestions = new List<string>();
using (XmlTextReader reader = new XmlTextReader(HttpContext.Current.Server.MapPath("flightdata.xml")))
{
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element && reader.Name == "departurelocation")
{
string itemName = reader.ReadInnerXml();
if (itemName.StartsWith(prefixText, StringComparison.InvariantCultureIgnoreCase))
{
if (!suggestions.Contains(itemName))
suggestions.Add(itemName);
if (suggestions.Count == count) break;
}
}
if (reader.NodeType == XmlNodeType.Element && reader.Name == "destinationlocation")
{
string itemName = reader.ReadInnerXml();
if (itemName.StartsWith(prefixText, StringComparison.InvariantCultureIgnoreCase))
{
if (!suggestions.Contains(itemName))
suggestions.Add(itemName);
if (suggestions.Count == count) break;
}
}
}
}
return suggestions.ToArray();
}
示例8: Main
static void Main(string[] args)
{
string localURL = @"http://ip-address.domaintools.com/myip.xml";
XmlTextReader xmlreader = null;
xmlreader = new XmlTextReader (localURL);
while (xmlreader.Read())
{
if(xmlreader.NodeType == XmlNodeType.Element)
{
Console.WriteLine("Element : " + xmlreader.Name);
}
if(xmlreader.NodeType == XmlNodeType.Text)
{
Console.WriteLine("Value : " +xmlreader.Value);
}
}
if (xmlreader != null)
xmlreader.Close();
}
示例9: Mirror
public Mirror(string spec)
{
objectStack = new Stack();
objectStack.Push(null);
// Register the commands
commands = new List<Command>();
commands.Add(new ElementCommand());
commands.Add(new EndElementCommand());
commands.Add(new AttributeCommand());
Reader = new XmlTextReader(spec);
while (Reader.Read())
{
InterpretCommands();
var b = Reader.IsEmptyElement;
if (Reader.HasAttributes)
{
for (var i = 0; i < Reader.AttributeCount; i++)
{
Reader.MoveToAttribute(i);
InterpretCommands();
}
}
if (b) Pop();
}
}
示例10: LevelDataXML
public void LevelDataXML(string pathToXml)
{
parseFile = Resources.Load(pathToXml) as TextAsset;
platforms = new List<PlatformData>();
metadata = new List<MetaData>();
portalSpawns = new List<Portal>();
hazardSpawns = new List<Hazard>();
playerSpawns = new List<Vector2>();
enemySpawns = new List<Vector2>();
items = new List<Vector2>();
XmlTextReader mapReader = new XmlTextReader(new StringReader(parseFile.text));
mapReader.Read();
XmlDocument doc = new XmlDocument();
doc.LoadXml(mapReader.ReadOuterXml());
mapSize = new Vector2((float)int.Parse(doc.ChildNodes[0].Attributes[0].Value)/16, (float)int.Parse(doc.ChildNodes[0].Attributes[1].Value)/16);
for (int x = 0; x < doc.ChildNodes[0].ChildNodes.Count; x++)
{
if (doc.ChildNodes[0].ChildNodes[x].Name.ToLower().Equals("frontlayer")) {
LoadTiles(doc.ChildNodes[0].ChildNodes[x], platforms);
}
if (doc.ChildNodes[0].ChildNodes[x].Name.ToLower().Equals("entities"))
{
LoadSpawnPoints(doc.ChildNodes[0].ChildNodes[x]);
}
}
}
示例11: ReadXML
void ReadXML()
{
int typesCount = (int)MessageType.Count;
messages = new List<string>[typesCount];
for(int i = 0; i < typesCount; i++) {
messages[i] = new List<string>();
}
XmlTextReader reader = new XmlTextReader (file.text, XmlNodeType.Element, null);
while(reader.Read()) {
string typeName = reader.Name;
if(string.IsNullOrEmpty(typeName)) {
continue;
}
string message = reader.ReadString();
int mTypeIndex = (int)((MessageType)System.Enum.Parse(typeof(MessageType), typeName));
if(mTypeIndex >= 0 && mTypeIndex < typesCount) {
messages[mTypeIndex].Add(message);
// Debug.Log("Adding message: " + message + " for type " + typeName);
} else {
Debug.LogError("Unknown type " + typeName);
}
}
}
示例12: 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;
}
示例13: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
XmlReader rd = new XmlTextReader("http://www.tcmb.gov.tr/kurlar/today.xml");
string kur="",capraz="";
if (!this.IsPostBack)
{
while (rd.Read())
{
if (rd.NodeType == XmlNodeType.Element)
{
if (rd.Name == "Isim")
{
kur = rd.ReadString();
}
if (rd.Name == "CrossRateUSD")
{
capraz = rd.ReadString();
}
if (kur != "" && capraz != "")
{
kurlar.Items.Add(new ListItem(kur, capraz));
kur = "";
capraz = "";
}
}
}
}
}
示例14: GetAlbumArt
protected void GetAlbumArt(string albumId, string album, string artist)
{
string path = Server.MapPath(@"~/images/cover-art/");
if(!File.Exists(path + albumId + ".png")){
string url = "http://ws.audioscrobbler.com/2.0/?method=album.getinfo&api_key=b25b959554ed76058ac220b7b2e0a026&artist=" + artist + "&album=" + album;
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
XmlTextReader reader = new XmlTextReader(response.GetResponseStream());
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element && reader.Name == "image")
{
if (reader.GetAttribute("size").Equals("large"))
{
url = reader.ReadInnerXml();
WebClient webClient = new WebClient();
webClient.DownloadFile(url, path + albumId + ".png");
}
}
}
}
catch (Exception e)
{
}
}
}
示例15: ReadXML
private void ReadXML()
{
string xmlFile = Server.MapPath("DvdList.xml");
// Create the reader.
XmlTextReader reader = new XmlTextReader(xmlFile);
StringBuilder str = new StringBuilder();
reader.ReadStartElement("DvdList");
// Read all the <DVD> elements.
while (reader.Read())
{
if ((reader.Name == "DVD") && (reader.NodeType == XmlNodeType.Element))
{
reader.ReadStartElement("DVD");
str.Append("<ul><b>");
str.Append(reader.ReadElementString("Title"));
str.Append("</b><li>");
str.Append(reader.ReadElementString("Director"));
str.Append("</li><li>");
str.Append(String.Format("{0:C}",
Decimal.Parse(reader.ReadElementString("Price"))));
str.Append("</li></ul>");
}
}
// Close the reader and show the text.
reader.Close();
XmlText.Text = str.ToString();
}