How to obtain the relevant values of a specified attribute in an XML file?

Source: Internet
Author: User

Two methods:

First, use the selectnodes method. The following example shows how to use this method.

Second, use the XQuery method.

 

''' <Summary>
''' Get the language value of the corresponding ID from the XML file
''' </Summary>
''' <Param name = "textid"> input id </param>
''' <Returns> </returns>
''' <Remarks> </remarks>
Private shared function getcancagetextfromxml (byval textid as string) as langtext
Dim _ return as langtext = nothing

Try
If not isnothing (_ xmldoc) then

Dim nodelist as xmlnodelist
Nodelist = _ xmldoc. selectnodes ("// item [@ text_id = '" & textid. tolower & "']")

Dim node as xmlnode
Dim _ languageid as string '= IIF (Language = elanguage. English, "eng", "CHN ")
For each node in nodelist
_ Languageid = node. attributes ("language"). value. toupper
Select case _ languageid
Case "eng"
_ Return. Eng = node. innerxml
Case "CHN"
_ Return. CHN = node. innerxml
End select
Next
Else
_ Return = nothing
End if
Catch
_ Return = nothing
Finally
End try

Return _ return

End Function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.