XPATH多条件排除一些元素

时间:2019-12-01 05:03:14

标签: xpath

我想使用XPATH解析模式数据。 这是一个简单的结构。

<div itemscope itemtype="http://www.schema.org/Product">

  <div itemscope itemtype="http://www.schema.org/Person">
  <span itemprop="birthday" datetime="2009-05-10">May 10th 2009</span>
  </div>

  <div itemprop="name"> Product name </div>
  <div itemprop="offers" itemscope itemtype="https://schema.org/Offer">
    <span itemprop="price" content="500.00"> USD 500 </span>
  </div>

</div>

我想解析的结果是这样的:

1. Category: http://www.schema.org/Product
  v name: Product name
  v Offers
      - price: USD 500
2. Category: http://www.schema.org/Person
  v birthday: May 10th 2009

要对“ http://www.schema.org/Product”和“ http://www.schema.org/Person”进行分类,我使用了以下代码:

var category = $x("//*[@itemtype and not(@itemprop)]");

所以类别[0]:

<div itemscope itemtype="http://www.schema.org/Product">

  <div itemscope itemtype="http://www.schema.org/Person">
  <span itemprop="birthday" datetime="2009-05-10">May 10th 2009</span>
  </div>

  <div itemprop="name"> Product name </div>
  <div itemprop="offers" itemscope itemtype="https://schema.org/Offer">
    <span itemprop="price" content="500.00"> USD 500 </span>
  </div>

</div>

类别[1]:

<div itemscope itemtype="http://www.schema.org/Person">
  <span itemprop="birthday" datetime="2009-05-10">May 10th 2009</span>
</div>

在解析itemprop之前,我必须清除类别[0]上的该内容,以防止重复数据,

...
<div itemscope itemtype="http://www.schema.org/Person">
  <span itemprop="birthday" datetime="2009-05-10">May 10th 2009</span>
  </div>
...

如何排除类别[0]中的那些东西?

I would like to exclude this one under category[0]-> 
Final expression I would like to make:
Select category[0] not select ([contains(@itemtype,'schema.org/') and not(@itemprop)]/descendant-or-self::*)

请阐明此事。 谢谢:)

0 个答案:

没有答案