查找某些外部节点中是否缺少嵌套的XML节点

时间:2018-09-05 13:11:58

标签: xml xpath nodes amazon amazon-mws

在遵循有关XML的一些非常有用的建议之前,我对Amazon MWS响应有一个小问题。 响应有时没有内部节点的数据,例如:

build site:
  image: node:10.8
  stage: build
  script:
    - npm install --progress=false
    - npm run build
  artifacts:
    expire_in: 1 week
    paths:
      - dist

unit test:
  image: node:10.8
  stage: test
  script:
    - npm install --progress=false
    - npm run unit

deploy:
  image: alpine
  stage: deploy
  script:
    - apk add --no-cache rsync openssh
    - mkdir -p ~/.ssh
    - echo "$SSH_PRIVATE_KEY" >> ~/.ssh/id_dsa
    - chmod 600 ~/.ssh/id_dsa
    - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
    - rsync -rav --delete dist/ user@server.com:/your/project/path/

第二个ASIN“ B07GFN1N8Q”没有CurrencyCode等值。为了使用xpath将所有其他数据存储在数组中,我需要检查这些值是否丢失。 但是,由于我使用xpath填充了一个'ASIN数组',然后填充了'CurrencyCode数组',因此某些ASIN缺少数据这一事实使得数组无法``排队''(包含相同数量的结果)。 因此,我需要检查ASIN树是否缺少CurrencyCode等-然后可以将0或其他内容放置在CurrencyCode数组中作为占位符。

将数据放入数组的代码如下:

  <GetMyPriceForASINResult ASIN="B0713SH24R" status="Success">
    <Product>
      <Identifiers>
        <MarketplaceASIN>
          <MarketplaceId>ATVPDKIKX0DER</MarketplaceId>
          <ASIN>B0713SH24R</ASIN>
        </MarketplaceASIN>
      </Identifiers>
      <Offers>
        <Offer>
          <BuyingPrice>
            <LandedPrice>
              <CurrencyCode>USD</CurrencyCode>
              <Amount>7.70</Amount>
            </LandedPrice>
            <ListingPrice>
              <CurrencyCode>USD</CurrencyCode>
              <Amount>7.70</Amount>
            </ListingPrice>
            <Shipping>
              <CurrencyCode>USD</CurrencyCode>
              <Amount>0.00</Amount>
            </Shipping>
          </BuyingPrice>
          <RegularPrice>
            <CurrencyCode>USD</CurrencyCode>
            <Amount>13.99</Amount>
          </RegularPrice>
          <FulfillmentChannel>AMAZON</FulfillmentChannel>
          <ItemCondition>New</ItemCondition>
          <ItemSubCondition>New</ItemSubCondition>
          <SellerId>A2G0HWSQG6JL91</SellerId>
          <SellerSKU>3 Paper Sm - Lined Cream</SellerSKU>
        </Offer>
      </Offers>
    </Product>
  </GetMyPriceForASINResult>
  <GetMyPriceForASINResult ASIN="B07GFN1N8Q" status="Success">
    <Product>
      <Identifiers>
        <MarketplaceASIN>
          <MarketplaceId>ATVPDKIKX0DER</MarketplaceId>
          <ASIN>B07GFN1N8Q</ASIN>
        </MarketplaceASIN>
      </Identifiers>
      <Offers/>
    </Product>
  </GetMyPriceForASINResult>
  <GetMyPriceForASINResult ASIN="B01NAU635T" status="Success">
    <Product>
      <Identifiers>
        <MarketplaceASIN>
          <MarketplaceId>ATVPDKIKX0DER</MarketplaceId>

但是,这会循环所有ASIN,然后循环所有CurrencyCodes。我需要检查与特定ASIN相关的特定CurrencyCode。

0 个答案:

没有答案