XmlTextReader读取行为 [英] XmlTextReader reading behavior

查看:62
本文介绍了XmlTextReader读取行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是:当使用经典方法使用XmlTextReader读取xml文件时,我注意到在使用Read()方法之后,读者有时会前进,有时则不会。我无法解决这个问题会导致问题,因为不同的逻辑是在相同的情况下执行

My question is this: when using classic methods for reading xml files using XmlTextReader I noticed that after using the Read() method reader sometimes advances and sometimes does not. My inability to figure this out causes problems as different logic is executed in simingly the same situations.

当我指定时,例如'/ TestSchema / FirstNode / SecondNode / ThirdNode然后,在执行我的阅读逻辑时,阅读器位于< / SecondNode>,循环aruond,执行doc.Read(),仍然保持(!!!)在< / SecondNode>然后进入
第三个swich案例(节点是结束元素)。

When I specify, for example, '/TestSchema/FirstNode/SecondNode/ThirdNode' then, upon executing my reading logic, reader is positioned at </SecondNode>, loops aruond, executes doc.Read(), still stays (!!!) at the </SecondNode> and then goes into the third swich case (node is an end element).

当我指定不同的路径'/ TestSchema / FirstNode / SecondNode'时,同样的事情发生如上所述,但这次doc.Read()实际上将读者推进到下一个节点,该节点可能是另一个节点< SecondNode>因此属于不同的开关
案例陈述。

When I specify a different path'/TestSchema/FirstNode/SecondNode' then the same thing happens as above but this time doc.Read() actually advances the reader to the next node, which might be another <SecondNode> and thus falls under different switch case statement.

这是样本XML


<TestSchema>
	<SomeField SomeAttribute="SomeAttributeValue" AnotherAttribute="AnotherAttributeValue">SomeValue</SomeField>
	<SomeAttributeNode NodeName="NodeValue"/>
	<SomeNode Name="Value"></SomeNode>
	<Field>FieldValue</Field>
	<FirstNode>
		<SecondNode>
			<ThirdNode>
				<FirstElement>First</FirstElement>
				<SecondElement>2</SecondElement>
			</ThirdNode>
			<ThirdNode>
				<ThirdElement>Third</ThirdElement>
				<FourthElement>4</FourthElement>
			</ThirdNode>
		</SecondNode>
	</FirstNode>
</TestSchema>

推荐答案

当我指定时,例如'/ TestSchema / FirstNode / SecondNode / ThirdNode'
When I specify, for example, '/TestSchema/FirstNode/SecondNode/ThirdNode'




其中 你指定了吗?我不知道任何XmlTextReader方法 将路径作为参数。


Where do you specify this? I don't know any XmlTextReader method taking a path as parameter.


这篇关于XmlTextReader读取行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆