in reply to Perl parsing XML using XML::Simple

1. What is your question? What in your current code or XML files doesn't work and how doesn't it work? I can't tell, because...
2. I can't read those files: Undeclared prefix: xs at /usr/local/lib/perl5/site_perl/5.8.5/XML/NamespaceSupport.pm line 293.
3. For anything more complex than very straightforward config files etc I wouldn't use XML::Simple. I prefer XML::Twig.

How do I post a question effectively?

Replies are listed 'Best First'.
Re^2: Perl parsing XML using XML::Simple
by thickice97 (Initiate) on Jan 21, 2008 at 19:50 UTC
    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
      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.