-2

重複の可能性:
perlでネストされたタグを使用したXML解析

次のxml構造。perlでマグニチュードの下限値と上限値を解析する必要があり、childrenタグのtype属性を解析する必要があります

<definition>
    <attributes>
        <children>
            <attributes>
                <children xsi:type="C_COMPLEX_OBJECT" >
                    <attributes>
                        <children>
                            <attributes>
                                <children><list><magnitude><lower>100</lower><upper>200</upper></magnitude></list></children>
                                <children><list><magnitude><lower>200</lower><upper>400</upper></magnitude></list></children>
                                <children><list><magnitude><lower>400</lower><upper>750</upper></magnitude></list></children>
                                <children><list><magnitude><lower>250</lower><upper>500</upper></magnitude></list></children>
                                <children><list><magnitude><lower>350</lower><upper>1000</upper></magnitude></list></children>
                            </attributes>
                        </children>
                    </attributes>
                </children>
               <children></children>
            </attributes>
        </children>
    </attributes>
</definition>
4

1 に答える 1

1

これは、LibXMLを使用してこのxmlを解析し、必要な値を取得する小さなコードです。

use XML::LibXML;
my $parser = XML::LibXML->new();
my $xml = $parser->parse_file('test.xml');

my @lower = $xml->find('//lower');
my @upper = $xml->find('//upper');

my $type = $xml->find('//children/@type');

@ lower、@ upper、$typeはノードです。文字列を抽出するには、to_lietralsubを呼び出してください。例:$type->to_literal。

于 2012-04-25T09:12:20.080 に答える