這是我的代碼如下所示:使用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