-2

Possible Duplicate:
XML Parsing with nested tags in perl

In the following xml structure. i need to parse the magnitudes lower and upper values in perl and need to parse the type attribute in the children tags

<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>
3
  • you can use xPath with XML parsing to retrieve the require information. let me know if you need a code for it. you can consider XML-Twig and libxml for xml parsing. Commented Apr 25, 2012 at 9:00
  • you have already asked same question in the previous post, stackoverflow.com/questions/10295506/… Commented Apr 25, 2012 at 9:01
  • @Nikil solution for that question is solved this is another that we cant resolve Commented Apr 25, 2012 at 9:29

1 Answer 1

1

Here is a small code using LibXML to parse this xml and get the required values.

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');

the @lower, @upper, $type are the nodes. to extract the string please call the to_lietral sub. e.g. $type->to_literal.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for the reply, all the children node has lower and upper node. We identified that the 5th children node has the required lower and upper value. Above code retreived all the values
@Thangaraj- please vote it if this is helpful to you:)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.