How to: Access XML Child Elements (Visual Basic)
This example shows how to use a child axis property to access all XML child elements that have a specified name in an XML element. In particular, it uses the Value property to get the value of the first element in the collection that the name
child axis property returns. The name
child axis property gets all child elements named phone
in the contact
object. This example also uses the phone
child axis property to access all child elements named phone
that are contained in the contact
object.
Example
Dim contact As XElement =
<contact>
<name>Patrick Hines</name>
<phone type="home">206-555-0144</phone>
<phone type="work">425-555-0145</phone>
</contact>
Console.WriteLine("Contact name: " & contact.<name>.Value)
Dim phoneTypes As XElement =
<phoneTypes>
<%= From phone In contact.<phone>
Select <type><%= phone.@type %></type>
%>
</phoneTypes>
Console.WriteLine(phoneTypes)
Compile the code
This example requires:
- A reference to the System.Xml.Linq namespace.
See also
GitHub पर हमारे साथ सहयोग करें
इस सामग्री का स्रोत GitHub पर पाया जा सकता है, जहाँ आप समस्याएँ बना और समीक्षा भी कर सकते हैं और अनुरोध खींच सकते हैं. अधिक जानकारी के लिए, हमारे योगदानकर्ता गाइड देखें.