다음을 통해 공유


방법: XML 하위 요소 액세스(Visual Basic)

이 예제에서는 하위 축 속성을 사용하여 지정한 이름을 가지며 지정된 XML 요소 아래에 포함된 모든 XML 요소에 액세스하는 방법을 보여줍니다. 특히 Value 속성을 사용하여 name 하위 축 속성이 반환하는 컬렉션의 첫 번째 요소 값을 가져옵니다. name 하위 축 속성은 contacts 개체에 포함된 name으로 명명된 모든 요소를 가져옵니다. 또한 이 예제에서는 phone 하위 축 속성을 사용하여 contacts 개체에 포함된 phone이라고 명명된 모든 하위 항목에 액세스합니다.

예시

Dim contacts As XElement = 
<contacts>
    <contact>
        <name>Patrick Hines</name>
        <phone type="home">206-555-0144</phone>
        <phone type="work">425-555-0145</phone>
    </contact>
</contacts>

Console.WriteLine("Name: " & contacts...<name>.Value)

Dim phoneTypes As XElement = 
  <phoneTypes>
      <%= From phone In contacts...<phone> 
          Select <type><%= phone.@type %></type> 
      %>
  </phoneTypes>

Console.WriteLine(phoneTypes)

코드 컴파일

이 예제에는 다음 사항이 필요합니다.

참고 항목