使用SOAP :: Lite解析XML响应

问题描述 投票:0回答:1

使用SOAP::Lite我正在尝试解析XML响应;但是,SOAP :: SOM没有给我想要的值。它似乎采取了与我尝试查找的路径不同的路径。

    #!/usr/bin/env perl
    use strict;
    use warnings;
    use SOAP::Lite;
    use Data::Dumper;

    my $xml  = <<'__XML__';
    <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
      <S:Body>
        <GetResponse>
          <services>
            <communication>
              <ruleset>
                <rule id="CD22222222">
                  <id>CD22222222</id>
                  <conditions>
                    <xtra>
                      <one id="sip:+22222222@ims">
                        <id>sip:+22222222@ims</id>
                      </one>
                      <one id="tel:+22222222">
                        <id>tel:+22222222</id>
                      </one>
                    </xtra>
                  </conditions>
                  <actions>
                    <allow>false</allow>
                  </actions>
                </rule>
                <rule id="CD33333333">
                  <id>CD33333333</id>
                  <conditions>
                    <xtra>
                      <one id="sip:+33333333@ims">
                        <id>sip:+33333333@ims</id>
                      </one>
                      <one id="tel:+33333333">
                        <id>tel:+33333333</id>
                      </one>
                    </xtra>
                  </conditions>
                  <actions>
                    <allow>false</allow>
                  </actions>
                </rule>
              </ruleset>
            </communication>
            <common-data>
              <subscription-list>
                <subscription id="PD11111111">
                  <id>PD11111111</id>
                  <number>11111111</number>
                  <key>alpha</key>
                  <default-subscription/>
                </subscription>
                <subscription id="CD22222222">
                  <id>CD22222222</id>
                  <number>22222222</number>
                  <key>beta</key>
                </subscription>
                <subscription id="CD33333333">
                  <id>CD33333333</id>
                  <number>33333333</number>
                  <key>gama</key>
                </subscription>
              </subscription-list>
            </common-data>
          </services>
        </GetResponse>
      </S:Body>
    </S:Envelope>
    __XML__

    my $som = SOAP::Deserializer->deserialize($xml);

    print Dumper($som->valueof('//services/common-data/subscription-list/'));

我正在使用不同的XML路径获取相同ID的值。

我想从请求的XML路径中获取其余ID的<key>,例如betagamma

xml perl xpath soap xml-parsing
1个回答
1
投票

<number>元素获取所有日期的xpath表达式:

//services/common-data//subscription//number/text()

[仅从<number>内的<subscription-list>内的<default-subscription/>元素中获取数据,请使用:

//services/common-data//subscription[.//child::*[name()='default-subscription']]//number/text()
© www.soinside.com 2019 - 2024. All rights reserved.