xml - 如何获取 <?来自 xml 的标签与 vb.net

标签 xml vb.net linq xelement

我正在使用 vb.net 将一些 xml 文件提取到数据库中,但我无法识别 xml 标记中的一行

xml 看起来像这样:

<article type="article">
   <id>0103-0002-004</id>
   <?article zz="3100222857"?>
</article>

我正在使用:

Dim articles As IEnumerable(Of XElement) = docIssues...<article>
For Each article As XElement In articles
   strIdXML = article.Element("id")
   strIdXML = IIf(strIdXML Is Nothing, "element does not exist", strIdXML)

   strGaleId = article.Element("ariticle")
   strGaleId = IIf(strGaleId Is Nothing, "element does not exist", strGaleId)
next

id 没问题,但我无法获取它

有什么线索吗?

非常感谢

最佳答案

它不是元素,因此通过 Element() 函数访问它似乎是错误的。我认为是这样的:

Dim articlePI = article.DescendantNodes()
  .SingleOrDefault(
       Function(node)
         If Typeof node is XProcessingInstruction
           Dim pi = DirectCast(node,XProcessingInstruction)
           Return pi.Target = "article"
         End If
         Return False
       End Function
  )

提取项目。然后您希望将其转换为 XProcessingInstruction 以访问它的 Data

关于xml - 如何获取 <?来自 xml 的标签与 vb.net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24367589/

相关文章:

C# LINQ 错误帮助

php - 尝试从 XML 中提取元素并将其放入数组中

asp.net - xml 响应 http post - 将 request.inputstream 转换为字符串 - asp.net

android - 生成签名 APK - 错误 :(57) Error parsing XML: duplicate attribute in cardview?

mysql - 通过datagrid View 删除数据mySQL Vb.net

c# - Linq查询返回空值时如何返回null?

xml - XSD all 和 XSD sequence 之间的中间方式

.net - VB.net使用system.directoryservices获取显示名称

mysql - 合并两个 mysql 表并将结果放入 VB.NET 中的数据网格中

c# - 在字符串上构建表达式时如何实现 LessThan 等