in reply to Re: Perl parsing XML using XML::Simple
in thread Perl parsing XML using XML::Simple

There are various structures in the XML file. I have written most of the structures in the if else loop. But for the structure below I have attached the piece of code which I have added to the actual one. <xs:complexType name="ActiveOrHistoricCurrencyAnd13DecimalAmount"> <xs:simpleContent> <xs:extension base="ActiveOrHistoricCurrencyAnd13DecimalAmount_SimpleType"> <xs:attribute name="Ccy" type="ActiveOrHistoricCurrencyCode" use="required"/> </xs:extension> </xs:simpleContent> </xs:complexType>
my $data = $xml->XMLin($file, ForceArray=>['xs:element','xs:attribute' +]); my $seq_1 = $data->{'xs:complexType'}->{$complex}->{'xs:simpleContent' +}; if (exists($seq_1->{'xs:attribute'})){ print "I am here"; $elementref = $seq_1->{'xs:attribute'};}
Doesn't seem to work. It is not parsing the above structure. Please advise

Replies are listed 'Best First'.
Re^3: Perl parsing XML using XML::Simple
by Joost (Canon) on Jan 21, 2008 at 20:18 UTC
    Ok, here's some advice: boil the program and example code down as small as possible but keep it working.

    Something like this:

    <myxml xmlns:xs='bla'> <xs:complexType name="AlternateSecurityIdentification1"> <xs:sequence> <xs:element name="Id" type="Max35Text"/> <xs:choice> <xs:element name="DmstIdSrc" type="CountryCode"/> <xs:element name="PrtryIdSrc" type="Max35Text"/> </xs:choice> </xs:sequence> </xs:complexType> </myxml>
    Will parse.

    Also:

    foreach my $complex(keys %{$data->{'xs:complexType'}}) { print $complex; my $seq = $data->{'xs:complexType'}->{$complex}->{'xs:sequence'};
    Is probably easier written as:
    foreach my $subseq (values %{$data->{'xs:complexType'}}) { my $seq = $subseq->{'xs:sequence'};
    Then print()/Dump() the data you've got at various stages and see which line(s) are causing problems.

      Thanks for the info. Will try that.