我正在使用 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/