문제

My xml looks like

<article>
    <article-id pub-id-type="local">ABC</article-id>
    <article-id pub-id-type="external">XYZ</article-id>
</article>

I can do the following

dim articleId as string =  doc.SelectSingleNode("./article/article-id", nsm).InnerText

and the result is ABC

I don't know how to get the result to be XYZ - I assume because I'm using SelectSingleNode it is getting the First item. Is there a way to tell it to get the second?

Please note, although I've shown an example with only 2 nodes, there could be any number so it must be 'searchable' by the name 'external'

I've not really used .NET 2.0 before and the MSDN didn't really help me.

Any help would be great, thank you.

도움이 되었습니까?

해결책

You can use the following XPath:

"./article/article-id[@pub-id-type='external']"

The [@pub-id-type='external'] is an attribute filter.

If you have multiple possible elements, you could add [last()] to get the last of them.

For more XPath info, check out this page.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top