在这个XML文件中,我必须获取列表中的所有源dll。我正在尝试以下查询。
将 appManifest Dim As String = new System.IO.StreamReader(Application.GetResourceStream(New System.Windows.Resources.StreamResourceInfo(e.Result, Nothing), new Uri("AppManifest.xaml", UriKind.Relative)).流)。ReadToEnd()
Dim deploymentRoot As XElement = XDocument.Parse(appManifest).根**将部件调暗为 List(Of XElement) = (来自 assembly Parts In _ deploymentRoot.Elements()。元素() 选择装配零件)。ToList()**
但帕特尔斯包含计数。它不是一个列表。我该怎么做?
下面是 XML 文档。
<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>
你有没有尝试过使用 xpath?查询将是这样的//AssemblyPart/[Source]
XPath 一般: http://www.w3schools.com/xpath/default.asp
XPath & .Net: http://www.developer.com/net/net/article.php/3383961/NET-and-XML-XPath-Queries.htm
干杯
使用 LINQ 的答案位于:http://forums.asp.net/t/1681678.aspx/1
从那里复制:
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