Imports System.Collections.Generic
Imports System.Collections
Imports System.Collections.ObjectModel
Imports System.Reflection
Imports System.Xml.Serialization
Imports System.Xml.Schema
Dim xml as String = GetXml()
Dim xml_Doc = XDocument.Parse(xml)
Dim sampleText = "sample text 1"
(From c In xml_Doc.Descendants("catalog")
From v in c.Elements("val")
Where v.Value.Contains(sampleText)
Select New With {.index = v.Attribute("index").Value, .name = c.Attribute("name").Value })
For Each s In search_result
Console.WriteLine("index:{0} , name:{1}", s.index, s.name)
Function GetXml() As String
Dim xml as String = <list>
<catalog index="1" name="n1">
<val index="1">sample text 1</val>
<val index="2">sample text 2</val>
<val index="3">sample text 3</val>
<catalog index="2" name="n2">
<val index="1">sample text 0</val>
<val index="2">sample text 2</val>
<val index="3">sample text 3</val>
<val index="4">sample text 1</val>
<val index="5">sample text 5</val>
<val index="6">sample text 6</val>
<catalog index="3" name="n3">
<val index="1">sample text 8</val>
<val index="2">sample text 9</val>
<val index="3">sample text 10</val>
Public Module XmlSerializationHelper
<System.Runtime.CompilerServices.Extension> _
Public Function LoadFromXML(Of T)(xmlString As String) As T
Using reader As New StringReader(xmlString)
Return DirectCast(New XmlSerializer(GetType(T)).Deserialize(reader), T)
<System.Runtime.CompilerServices.Extension> _
Public Function GetXml(Of T)(obj As T, Optional omitStandardNamespaces As Boolean = False) As String
Dim ns As XmlSerializerNamespaces = Nothing
If omitStandardNamespaces Then
ns = New XmlSerializerNamespaces()
<System.Runtime.CompilerServices.Extension> _
Public Function GetXml(Of T)(obj As T, ns as XmlSerializerNamespaces) As String
Using textWriter = New StringWriter()
Dim settings = New XmlWriterSettings() With { _
Using xmlWriter = System.Xml.XmlWriter.Create(textWriter, settings)
Dim serializer as New XmlSerializer(obj.GetType())
serializer.Serialize(xmlWriter, obj, ns)
Return textWriter.ToString()
<System.Runtime.CompilerServices.Extension> _
Public Function GetOuterXml(node as XmlNode, Optional indent as Boolean = true) as String
Using textWriter = New StringWriter()
Dim settings = New XmlWriterSettings() With { _
.OmitXmlDeclaration = true _
Using xmlWriter = System.Xml.XmlWriter.Create(textWriter, settings)
Return textWriter.ToString()