VB.Net/XML LINQ/XNamespace — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Текущая версия на 12:45, 26 мая 2010

Import namespace

  
Imports System
Imports System.Xml.Linq
Imports <xmlns:gfh="www.yourDomain.ru">
    Public Class MainClass
        Public Shared Sub Main()
            Dim employees As XElement = XElement.Load("EmployeesWithNS.xml")
            Dim gfhEmployees = From ele In employees.Descendants _
                               Order By ele.<Name>.Value() _
                               Where (ele.Name.Namespace = GetXmlNamespace(gfh)) _
                               Select ele.<Name>.Value()
            For Each emp In gfhEmployees
                Console.WriteLine(emp)
            Next
        End Sub
    End Class


Using the Xml name space in the query

  
Imports System
Imports System.Reflection
Imports System.Xml
Module Module1
    Sub Main()
        Dim xml As XElement = XElement.Load("XLINQ.xml")
        Dim o As XNamespace = "urn:schemas-microsoft-com:office:office"
        Dim query = From w In xml.Descendants(o + "Author") _
            Select w
        For Each record In query
            Console.WriteLine("Author: {0}", record.Value)
        Next
    End Sub
End Module