0

下面提到的是我的 XML 的一部分:

<ParentNode>
    <NewCommentID>UniqueID02</NewCommentID>
    <Comment>
        <CommentId>UniqueID01</CommentId> 
        <CommentDesc>Some comments</CommentDesc> 
        <CommentTypeCd>Code1</CommentTypeCd> 
        <CreatedDt>2013-11-29</CreatedDt> 
        <CreatedByUserId>user01</CreatedByUserId> 
        <GivenName>Mitchell</GivenName> 
        <Surname>Johnson</Surname> 
    </Comment>
    <Comment>
        <CommentId>UniqueID02</CommentId> 
        <CommentDesc>Some Comments....</CommentDesc> 
        <CommentTypeCd>Code2</CommentTypeCd> 
        <CreatedDt>2013-11-29</CreatedDt> 
        <CreatedByUserId>user02</CreatedByUserId> 
        <GivenName>Mike</GivenName> 
        <Surname>Jobs</Surname> 
    </Comment>
</ParentNode>

我想获取 Comment 部分下所有节点的详细信息,但选择哪个部分将由 Node (NewCommentID) 决定。在上面的示例中,作为“NewCommentID = UniqueID02”中的值,我想使用 XPathDocument 获取 CommentID = UniqueID02 的 Comment 部分下的所有标签及其值。

有人可以指导如何使用 VB.net 实现相同的目标吗?

4

1 回答 1

0

您可以尝试这种方式:

Dim xpathDoc As New XPathDocument("Path_to_xml_file.xml")
Dim navigator As XPathNavigator

navigator = xpathDoc.CreateNavigator()
Dim result = navigator.Select("//Comment[./CommentId=../NewCommentID]")
于 2014-02-28T10:02:45.103 回答