xpath - 是否可以选择 XPATH 节点的属性?
问题描述
我有一个 XML 格式:
<articleslist>
<articles>
<originalId>507948</originalId>
<title>Hogan Lovells Training Contract</title>
<slug>hogan-lovells-training-contract</slug>
<metaTitle>Hogan Lovells Training Contract</metaTitle>
<metaDescription>Find out about the Hogan Lovells Training Contract and Application Process</metaDescription>
<language>en</language>
<disableAds>false</disableAds>
<shortUrl>false</shortUrl>
<category_slug>law</category_slug>
<subcategory_slug>industry</subcategory_slug>
<updatedAt>2021-03-15T18:38:51.058+00:00</updatedAt>
<createdAt>2018-11-29T06:42:51.665+00:00</createdAt>
</articles>
</articlelist>
我可以使用 XPATH 选择行值//articles
。
如何选择文章的子属性(即列标题),所以我得到一个表单列表:
originalId
title
slug
etc...
解决方案
取决于您的 XPath 版本。
在 XPath 2.0 中,它很简单//articles/*/name()
在 1.0 中这是不可能的,因为没有像“字符串序列”这样的数据类型。您必须将元素集返回为//articles/*
,然后在调用程序中提取它们的名称。
推荐阅读
- python - Python 和 Julia 卷积之间的区别?
- php - 如何检查数组是否包含对象中的某些属性?
- powerbi - Power BI (DAX) 对于按日期过滤的空行显示 0
- python - App Engine Standard 上的 Python 3 Django:应用程序无法启动
- c# - 在 mvc 上使用 ajax 发送文件和文本参数
- php - 成功更新数据,但在 codeigniter 中插入数据有错误(1264 超出范围)
- twitter-bootstrap - 并排的按钮
- python - 从 PYTHON 中的文件中读取特定字节
- java - 有没有办法一次定义一组按钮
- python - 这个 re 表达式有什么区别?