这是我的代码如下所示:使用XMLTextReader,我怎么知道我在哪个元素上?
case "Creator":
br.Read();
br.MoveToContent(); // gives the content of the role
tbComposer.Text = br.Value;
br.Read();
br.MoveToContent(); // gives the content of the role
tbConductor.Text = br.Value;
br.Read();
br.MoveToContent(); // gives the content of the role
tbOrchestra.Text = br.Value;
break;
这是工作代码:(!感谢大家对你的输入...不能做它没有你)斯波坎 - 多德
case "Creator":
br.MoveToFirstAttribute();
if (br.Value == "Composer") {
br.Read();
tbComposer.Text = br.Value;
}
if (br.Value == "Conductor") {
br.Read();
tbConductor.Text = br.Value;
}
if (br.Value == "Orchestra") {
br.Read();
tbOrchestra.Text = br.Value;
}
break;
这是我的XML是什么样子:
<ItemLookupResponse>
<OperationRequest/>
<Items>
<Request/>
<Item>
<ItemAttributes>
<Binding>Audio CD</Binding>
<CatalogNumberList>
<CatalogNumberListElement>43850</CatalogNumberListElement>
</CatalogNumberList>
<Creator Role="Composer">Gioachino Rossini</Creator>
<Creator Role="Conductor">Riccardo Chailly</Creator>
<Creator Role="Orchestra">National Philharmonic Orchestra</Creator>
</ItemAttributes>
</Item>
</Items>
</ItemLookupResponse>
我需要知道,如果我读的元素造物主的角色=“作曲”或创建者角色=“指挥者”等
因此,如何使用XMLTextReader,如何确定元素文本是什么?
你发布的XML是无效的。请张贴实际的XML,或至少一个重现问题的小例子。 –
您使用的是什么版本的.NET? –
.NET是3.5 ...我如何发布XML(大约50行...) – SpokaneDude