在VB.NET中,如何使用命名空间下的LINQ查询?

2026-05-06 11:381阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计371个文字,预计阅读时间需要2分钟。

在VB.NET中,如何使用命名空间下的LINQ查询?

我有这个XML文件: idNuSpecID/id 1.0.0/version NuSpec Sample/title Jim Bob/authors Billy Joel/owners licen

我有这个 XML文件:

<?xml version="1.0"?> <package xmlns="schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> <metadata> <id>NuSpecID</id> <version>1.0.0</version> <title>NuSpec Sample</title> <authors>Jim Bob</authors> <owners>Billy Joel</owners> <licenseUrl>url.goes.here</licenseUrl> <projectUrl>url.goes.there</projectUrl> <requireLicenseAcceptance>ture</requireLicenseAcceptance> <description>this is a sample nuget.</description> <summary> </metadata> </package>

而这段代码:

Module Module1 Sub Main() Dim root As XElement = XElement.Load("c:\tmp\nuspec.xml") Dim tests As IEnumerable(Of XElement) = _ From el In root.<metadata> _ Select el For Each el As XElement In tests Console.WriteLine(el.<id>.Value) Next Console.ReadKey() End Sub End Module

如果我取出xmlns =“HTTP …”我的代码输出“NuSpecID”,但我找不到一个解决方案,允许我解析/查询这个XML仍然附加名称空间.

我也有一些没有命名空间或有不同名称的文件,我如何确定是否使用一个和哪个使用?

您需要在XML文字中使用 import the namespace.

在模块的顶部,放:

Imports <xmlns:ns="schemas.microsoft.com/packaging/2010/07/nuspec.xsd">

然后在你的功能:

Dim tests = root.<ns:metadata> For Each el In tests Console.WriteLine(el.<ns:id>.Value) Next

显然你可以使用任何东西而不是ns.

在VB.NET中,如何使用命名空间下的LINQ查询?

标签:Linq

本文共计371个文字,预计阅读时间需要2分钟。

在VB.NET中,如何使用命名空间下的LINQ查询?

我有这个XML文件: idNuSpecID/id 1.0.0/version NuSpec Sample/title Jim Bob/authors Billy Joel/owners licen

我有这个 XML文件:

<?xml version="1.0"?> <package xmlns="schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> <metadata> <id>NuSpecID</id> <version>1.0.0</version> <title>NuSpec Sample</title> <authors>Jim Bob</authors> <owners>Billy Joel</owners> <licenseUrl>url.goes.here</licenseUrl> <projectUrl>url.goes.there</projectUrl> <requireLicenseAcceptance>ture</requireLicenseAcceptance> <description>this is a sample nuget.</description> <summary> </metadata> </package>

而这段代码:

Module Module1 Sub Main() Dim root As XElement = XElement.Load("c:\tmp\nuspec.xml") Dim tests As IEnumerable(Of XElement) = _ From el In root.<metadata> _ Select el For Each el As XElement In tests Console.WriteLine(el.<id>.Value) Next Console.ReadKey() End Sub End Module

如果我取出xmlns =“HTTP …”我的代码输出“NuSpecID”,但我找不到一个解决方案,允许我解析/查询这个XML仍然附加名称空间.

我也有一些没有命名空间或有不同名称的文件,我如何确定是否使用一个和哪个使用?

您需要在XML文字中使用 import the namespace.

在模块的顶部,放:

Imports <xmlns:ns="schemas.microsoft.com/packaging/2010/07/nuspec.xsd">

然后在你的功能:

Dim tests = root.<ns:metadata> For Each el In tests Console.WriteLine(el.<ns:id>.Value) Next

显然你可以使用任何东西而不是ns.

在VB.NET中,如何使用命名空间下的LINQ查询?

标签:Linq