开发者

Need LINQ query to read XML file that returns a list

In this is XML file I have to get all the Source dlls in a list. I am trying with below query.

Dim appManifest As String = New System.IO.StreamReader(Application.GetResourceStream(New System.Windows.Resources.StreamResourceInfo(e.Result, Nothing), New Uri("AppManifest.xaml", UriKind.Relative)).Stream).ReadToEnd()

Dim deploymentRoot As XElement = XDocument.Parse(appManifest).Root **Dim parts As List(Of XElement) = (From assemblyParts In _ deploymentRoot.Elements().Elements() Select assemblyParts).ToList()**

but patrs contains count.It is not a list. How can I do this?

Below is the XML document.

<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" 
            RuntimeVersion="4.0.50826.0">
    <Deployment.OutOfBrowserSettings>
        <OutOfBrowserSettings ShortName="WebPortalUI Application" 
                              EnableGPUAcceleration="False" 
                              ShowInstallMenuItem="True">
            <OutOfBrowserSettings.Blurb>
                WebPortalUI Application on your desktop; 
                at home, at work or on the go.
            </OutOfBrowserSettings.Blurb>
            <OutOfBrowserSettings.WindowSettings>
                <WindowSettings Title="WebPortalUI Application" 
                                Height="400" Width="928" />
            </OutOfBrowserSettings.WindowSettings>
            <OutOfBrowserSettings.Icons />
        </OutOfBrowserSettings>
    </Deployment.OutOfBrowserSettings>

    <Deployment.Parts>
        <AssemblyPart x:Name="WebPortalUI" 
                      Source="WebPortalUI.dll" />
        <AssemblyPart x:Name="System.ComponentModel.Composition"
                      Source="System.ComponentModel.Composition.dll" />
        <AssemblyPart x:Name="System.ComponentModel.Composition.Initialization"
                      Source="System.ComponentModel.Composition.Initialization.dll" />
        <AssemblyPart x:Name="System.ComponentModel.DataAnnotations"
                      Source="System.ComponentModel.DataAnnotations.dll" />
        <AssemblyPart x:Name="System.Windows.Controls.Data.Input"
                      Source="System.Windows.Controls.Data.Input.dll" />
        <AssemblyPart x:Name="System.Windows.Controls.Navigation"
                      Source="System.Windows.Controls.Navigation.dll" />
    开发者_运维技巧    <AssemblyPart x:Name="System.Xml.Linq" 
                      Source="System.Xml.Linq.dll" />
        <AssemblyPart x:Name="System.Xml.Serialization"
                      Source="System.Xml.Serialization.dll" />
        <AssemblyPart x:Name="Telerik.Windows.Controls"
                      Source="Telerik.Windows.Controls.dll" />
        <AssemblyPart x:Name="Telerik.Windows.Controls.Docking"
                      Source="Telerik.Windows.Controls.Docking.dll" />
        <AssemblyPart x:Name="Telerik.Windows.Controls.GridView"
                      Source="Telerik.Windows.Controls.GridView.dll" />
        <AssemblyPart x:Name="Telerik.Windows.Controls.Input"
                      Source="Telerik.Windows.Controls.Input.dll" />
        <AssemblyPart x:Name="Telerik.Windows.Controls.Navigation"
                      Source="Telerik.Windows.Controls.Navigation.dll" />
        <AssemblyPart x:Name="Telerik.Windows.Data" 
                      Source="Telerik.Windows.Data.dll" />
        <AssemblyPart x:Name="ViewModel" 
                      Source="ViewModel.dll" />
        <AssemblyPart x:Name="System.Windows.Data" 
                      Source="System.Windows.Data.dll" />
    </Deployment.Parts>

</Deployment>


have u tried to use xpath instead? the query would be something like that //AssemblyPart/[Source]

XPath general: http://www.w3schools.com/xpath/default.asp

XPath & .Net: http://www.developer.com/net/net/article.php/3383961/NET-and-XML-XPath-Queries.htm

cheers


An answer that uses LINQ is at: http://forums.asp.net/t/1681678.aspx/1

copying from there:

Dim assemblySources  = From aPart In XDocument.Load().Descendants("AssemblyPart") select a.Attribute("Source").Value  
For Each item As string In assemblySources 
  Console.WriteLine(item)  
Next
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜