XmlTextReaderを使用してXMLドキュメントのノードを循環させるのに助けが必要です。 XmlTextReader以外のものを使用することは、残念なことにオプションではありません。XmlTextReader - ノードを反復処理する方法
マイコード:
class Program { private static void Main(string[] args) { XmlTextReader reader = new XmlTextReader("http://api.own3d.tv/liveCheck.php?live_id=180491"); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Text: Console.WriteLine("Live: " + reader.Value); break; } } Console.ReadLine(); } }
XML used:
<own3dReply>
<liveEvent>
<isLive>true</isLive>
<liveViewers>225</liveViewers>
<liveDuration>1222</liveDuration>
</liveEvent>
</own3dReply>
What it's outputting to console:
Live: true Live: 225 Live: 1222
What it needs to output:
Live: true Viewers: 225 Duration: 1222
It needs to iterate through each node and do this, and I just can't figure it out. I tried using switch and while statements, but I just can't seem to get it to work.
*なぜ* XmlReader以外のオプションはありませんか?制限を与えるとき、答えに影響を及ぼす可能性があるので、理由を提示することは常に有用です。 –
また、 'new XmlTextReader()'も使わないでください。 'XmlReader.Create()'を使用してください。 –
私はそれを処分するのが良いと思いますので、使用してください:using(var xtr = XmlReader.Create(uri)) –