问题描述
我遇到 XmlReader.ReadInnerXmlAsync()
方法的奇怪的行为。而下面code工作...
I encounter strange behavior of the XmlReader.ReadInnerXmlAsync()
method. While the following code works...
using (XmlReader r = XmlReader.Create(stream, new XmlReaderSettings() { Async = true }))
{
while (await r.ReadAsync())
{
switch (r.NodeType) {
case XmlNodeType.Element:
if (r.Name.Equals("c"))
{
string x = await r.ReadInnerXmlAsync();
OnReceive("[ " + x + " ]");
}
break;
}
}
}
......,整个元素< C>< / C方式>
从以下XML读为字符串
...and the whole element <c></c>
from the following XML is read as string.
<?xml version='1.0' encoding='UTF-8'?>
<namespace:open>
<namespace:a>
<b></b>
<c>
<d>TEXT01</d>
<d>TEXT01</d>
<d>TEXT01</d>
<d>TEXT01</d>
</c>
<e>
<f>TEST01</f>
</e>
<g/>
<h/>
</namespace:a>
...
我不能读&LT;命名空间:A&GT;
与同code( r.Name.Equals(命名空间:一个 )
)。为什么?在code就在串块 X =等待r.ReadInnerXmlAsync();
,我确实知道数据在几秒钟内到达
I cannot read <namespace:a>
with the same code (r.Name.Equals("namespace:a")
). Why? The code just blocks at string x = await r.ReadInnerXmlAsync();
and I know for sure that the data arrives in seconds.
是因为这样的事实,如果读者定位在叶节点上,呼吁ReadInnerXml相当于调用读。 (哪些块,直到更多的数据被发送),这是在?我该如何解决这个问题?
Is it because of the fact that "If the reader is positioned on a leaf node, calling ReadInnerXml is equivalent to calling Read." (which blocks until more data is sent) which is documented at http://msdn.microsoft.com/de-de/library/system.xml.xmlreader.readinnerxml.aspx? How do I get around this?
我如何读取内部或外部XML,而无需等待更多的XML数据?
更新:
我找到了一个解决方案。
I found one solution.
XmlDocument doc = new XmlDocument();
doc.Load(r.ReadSubtree());
doc.DocumentElement.OuterXml;
也许有人会提供一些更优雅。
Maybe someone will provide something more elegant.
推荐答案
我找到了一个解决方案。
I found one solution.
XmlDocument doc = new XmlDocument();
doc.Load(r.ReadSubtree());
doc.DocumentElement.OuterXml;
也许有人会提供一些更优雅。
Maybe someone will provide something more elegant.
这篇关于为什么XmlReader.ReadInnerXmlAsync挂读,LT时; NS:组件&gt ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!