【发布时间】:2013-08-14 21:39:19
【问题描述】:
到目前为止,我的代码如下所示。
using (XmlReader r = XmlReader.Create(stream, new XmlReaderSettings() { Async = true }))
{
while (await r.ReadAsync())
{
switch (r.NodeType) {
case XmlNodeType.Element:
if (r.IsEmptyElement) // no attributes
{
OnReceive("<" + r.Name + " />");
}
else // has attributes
{
OnReceive("<" + r.Name + ">");
while (r.MoveToNextAttribute())
{
OnReceive(r.Name + " -> " + r.Value);
}
}
break;
}
}
}
我的 XML 如下所示。
<?xml version='1.0' encoding='UTF-8'?>
<start>
<a>
<b></b>
<c>
<d>TEXT01</d>
<d>TEXT01</d>
<d>TEXT01</d>
<d>TEXT01</d>
</c>
<e>
<f>TEST01</f>
</e>
<g/>
<h/>
</a>
...
当我点击 XML 元素 <a> 时,我想将它读到最后(直到我点击 </a>),然后用整个元素及其子元素触发一个事件。
我该怎么做?是否有某种机制可以让我像这样读取流(等到元素结束)然后继续处理其他 XML 部分?
【问题讨论】:
-
你看过ReadSubtree吗?
标签: c# xml-parsing async-await c#-5.0 networkstream