本文整理汇总了C#中XmlTextReader类的典型用法代码示例。如果您正苦于以下问题:C# XmlTextReader类的具体用法?C# XmlTextReader怎么用?C# XmlTextReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlTextReader类属于命名空间,在下文中一共展示了XmlTextReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToDataSet
public static DataSet ToDataSet(DataSetData dsd)
{
DataSet ds = new DataSet();
UTF8Encoding encoding = new UTF8Encoding();
Byte[] byteArray = encoding.GetBytes(dsd.DataXML);
MemoryStream stream = new MemoryStream(byteArray);
XmlReader reader = new XmlTextReader(stream);
ds.ReadXml(reader);
XDocument xd = XDocument.Parse(dsd.DataXML);
foreach (DataTable dt in ds.Tables)
{
var rs = from row in xd.Descendants(dt.TableName)
select row;
int i = 0;
foreach (var r in rs)
{
DataRowState state = (DataRowState)Enum.Parse(typeof(DataRowState), r.Attribute("RowState").Value);
DataRow dr = dt.Rows[i];
dr.AcceptChanges();
if (state == DataRowState.Deleted)
dr.Delete();
else if (state == DataRowState.Added)
dr.SetAdded();
else if (state == DataRowState.Modified)
dr.SetModified();
i++;
}
}
return ds;
}
示例2: process
public static void process(XamlOptions options, string input) {
if (!input.EndsWith(".xaml")) {
Console.WriteLine("Input filenames must end in .xaml");
return;
}
if (Environment.Version.Major < 2 && options.Partial) {
Console.WriteLine("This runtime version does not support partial classes");
return;
}
if (options.OutputFile == null) {
options.OutputFile = input + ".out";
}
ICodeGenerator generator = getGenerator(options.OutputLanguage);
XmlTextReader xr = new XmlTextReader(input);
try {
string result = ParserToCode.Parse(xr, generator, options.Partial);
TextWriter tw = new StreamWriter(options.OutputFile);
tw.Write(result);
tw.Close();
}
catch (Exception ex) {
Console.WriteLine("Line " + xr.LineNumber + ", Column " + xr.LinePosition);
throw ex;
}
}
示例3: 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();
}
示例4: 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();
}
}
示例5: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
string userName = "simonbegg";
string password = "techn0l0gy";
DataSet ds = new DataSet();
Twitter twitter = new Twitter();
XmlDocument xmlDoc = twitter.GetUserTimelineAsXML(userName, password, "simonbegg", Twitter.OutputFormatType.XML);
var query = (from c in xmlDoc.DocumentElement.ChildNodes.Cast<XmlNode>()
select c.SelectSingleNode("text").InnerXml).Take(2);
XmlTextReader xtr = new XmlTextReader(new StringReader(xmlDoc.OuterXml));
XElement xe = XElement.Load(xtr);
string tweets = String.Empty;
var foo = (from c in xe.Elements("status")
select c.Element("text")).First();
foreach (string tweet in query)
tweets += tweet + "<br />";
this.litTweet.Text = foo.ToString();
this.litTweetHeader.Text = "Latest tweets from talamh";
}
示例6: 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]);
}
}
}
示例7: 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;
}
示例8: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack) //sürekli japon yeni ni ekliyodu butonda bu yüzden bunu ekledik sadece ilk postback olduğunda yapar sonraki postbackları yapmaz
{
ListItem aa;
//ddlKurlar.Items.Add(new ListItem("japon yeni", "2,2")); 7/merkez bankasından xml alıcaz
XmlTextReader re = new XmlTextReader("http://www.tcmb.gov.tr/kurlar/today.xml");
string txt = "";
string value = "";
while (re.Read()) {
if(re.NodeType==XmlNodeType.Element)
if (re.Name == "Isim") {
txt = re.ReadString();
}
if (re.Name == "CrossRateUSD")
{
value = re.ReadString();
if (value == "")
continue; //boş değerleri böylece götürdük ddl deki
aa = new ListItem();
aa.Text = txt;
aa.Value = value.Replace(".", ",");
ddlKurlar.Items.Add(aa);
}
}
}
}
示例9: SetAppTypeProduct
public void SetAppTypeProduct()
{
try
{
XmlDocument doc = new XmlDocument();
string xpath = Server.MapPath("../data/xml/configproduct.xml");
XmlTextReader reader = new XmlTextReader(xpath);
doc.Load(reader);
reader.Close();
XmlNodeList nodes = doc.SelectNodes("/root/product");
int numnodes = nodes.Count;
for (int i = 0; i < numnodes; i++)
{
string nameapp = nodes.Item(i).ChildNodes[0].InnerText;
string idtype = nodes.Item(i).ChildNodes[1].InnerText;
string appunit = nodes.Item(i).ChildNodes[2].InnerText;
string unit = nodes.Item(i).ChildNodes[3].InnerText;
if (nameapp.Length > 0 && idtype.Length > 0)
{
Application[nameapp] = int.Parse(idtype);
}
if (appunit.Length > 0 && unit.Length > 0)
{
Application[appunit] = unit;
}
}
}
catch
{
}
}
示例10: ReadOrthographicSize
void ReadOrthographicSize(XmlTextReader textReader, GameObject go)
{
ScanToNode(textReader, "OrthographicSize");
float size = GetFloat(textReader);
Camera camera = go.GetComponent(typeof(Camera)) as Camera;
camera.orthographicSize = size;
}
示例11: 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();
}
示例12: 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();
}
示例13: 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);
}
}
}
}
示例14: 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";
}
示例15: Button1_ServerClick
protected void Button1_ServerClick(object sender, EventArgs e)
{
try
{
string currency = idChoice.Value;
XmlDocument doc = new XmlDocument();
string url = Server.MapPath("../data/xml/configproduct.xml");
XmlTextReader reader = new XmlTextReader(url);
doc.Load(reader);
reader.Close();
if (doc.IsReadOnly)
{
diverr.Visible = true;
diverr.InnerHtml = "File XML đã bị khóa. Không thể thay đổi";
return;
}
XmlNode nodeEdit = doc.SelectSingleNode("root/product[nameappunit='currency']/unit");
string value = nodeEdit.InnerText;
if (!value.Equals(currency))
{
nodeEdit.InnerText = currency;
doc.Save(url);
Application["currency"] = currency;
diverr.Visible = true;
diverr.InnerHtml = "Đã thay đổi cách hiển thị tiền tệ";
}
else
{
diverr.Visible = true;
diverr.InnerHtml = "Hệ thống đang hiển thị kiểu tiền này.";
}
}catch
{}
}