in reply to perl parsing xml
The "kitchen sink" module for manipulating XML is XML::Twig.
A starting point using XML::Twig to solve you problem may be:
use strict; use warnings; use XML::Twig; my $xml = <<XML; <xs:complexType name="semt.002.001.01"> <xs:sequence> <xs:element name="PrvsRef" type="AdditionalReference2" minOccurs="0" m +axOccurs="unbounded"/> <xs:element name="RltdRef" type="AdditionalReference2" minOccurs="0" m +axOccurs="unbounded"/> <xs:element name="MsgPgntn" type="Pagination"/> <xs:element name="StmtGnlDtls" type="Statement3"/> <xs:element name="AcctDtls" type="SafekeepingAccount1"/> <xs:element name="BalForAcct" type="AggregateBalanceInformation1" minO +ccurs="0" maxOccurs="unbounded"/> <xs:element name="SubAcctDtls" type="SubAccountIdentification1" minOcc +urs="0" maxOccurs="unbounded"/> <xs:element name="TtlVals" type="TotalValueInPageAndStatement" minOccu +rs="0" maxOccurs="1"/> <xs:element name="Xtnsn" type="Extension1" minOccurs="0" maxOccurs="un +bounded"/> </xs:sequence> </xs:complexType> XML my $twig = XML::Twig->new (twig_handlers => {'[@name]' => \&showNestin +g}); $twig->parse ($xml); sub showNesting { my @path; for my $elt (reverse $_->ancestors_or_self ()) { next unless defined $elt->att ('name'); push @path, $elt->att ('name'); } print join ('.', @path), "\n" if @path; }
Prints:
semt.002.001.01.PrvsRef semt.002.001.01.RltdRef semt.002.001.01.MsgPgntn semt.002.001.01.StmtGnlDtls semt.002.001.01.AcctDtls semt.002.001.01.BalForAcct semt.002.001.01.SubAcctDtls semt.002.001.01.TtlVals semt.002.001.01.Xtnsn semt.002.001.01
which doesn't do exactly what you want (I can't see exactly what you want in any case), but should get you going.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: perl parsing xml
by thickice97 (Initiate) on Jan 23, 2008 at 02:53 UTC | |
by GrandFather (Saint) on Jan 23, 2008 at 03:26 UTC | |
by thickice97 (Initiate) on Jan 23, 2008 at 04:41 UTC | |
by GrandFather (Saint) on Jan 23, 2008 at 06:54 UTC | |
by thickice97 (Initiate) on Jan 23, 2008 at 15:29 UTC |