List Info

Thread: Re: want to Convert XML to FLAT file




Re: want to Convert XML to FLAT file
country flaguser name
United States
2007-02-06 12:32:51
Thanks a  lot for immediate response.i was able to produce a flat file by using XML::Simple and a small piece of code ,but the xml file comes with fields which are neither in order nor consistent, meaning not every field will come in all child records so my flat file is of no use as i donno where a particular field comes
 
one more thing is :
 
my $t= XML::Twig->new(
       # the twig will include just the root and selected titles 
      twig_roots  ; => { 'title' => &print_n_purge,}
  ;  
       ;           ;    );
sub print_n_purge
    {
 my( $t, $elt)= _;
 print $elt->text ;    # print the text (including sub-element texts)
print"n";
 $t->purge;      ;     # frees the memory
    }
 
This code is able to print all values record wise but is there any option to separate the values with some delimiter and sort them before printing in this twig_roots  ; or any other code..
 
im not familiar with these packages..any reference with good num of exampleswould also be helpful
Thanks in advance
Shlomi Fish <shlomifiglu.org.il> wrote:
Hi!

On Saturday 03 February 2007 14:22, vikram veer wrote:
>; hi all,
> I have the following tasks to do in PERL
>

First of all see:

http://www.perl.org.il/misc.html#pl_vs_pl

> 1)xml file to flat file(only values not tags) where i can distinguish
> between attribute values and tag values
>;
> 2)Extract and print tags alone and number of times each field has occured
&gt;
> is there any package which can do this for me ..If so please suggest me a
> place where i can get simple examples.
>

There are many packages that can do this. I recommend XML::LibXML:

http://search.cpan.org/dist/XML-LibXML/

It has both a DOM/XPath and a SAX interface. You can use the DOM unless the
files you're processing are extremely large and won't fit inside your
computer's memory at once. If not, use SAX, which is an event-based parser.

Regards,

Shlomi Fish

---------------------------------------------------------------------
Shlomi Fish shlomifiglu.org.il
Homepage: http://www.shlomifish.org/

Chuck Norris wrote a complete Perl 6 implementation in a day but then
destroyed all evidence with his bare hands, so no one will know his secrets.


Here’s a new way to find what you're looking for - Yahoo! Answers
RE: want to Convert XML to FLAT file
country flaguser name
United States
2007-02-06 14:09:27


vikram veer wrote:

> Thanks a lot for immediate response.i was able to
produce a flat file
> by using XML::Simple and a small piece of code ,but the
xml file comes
> with fields which are neither in order nor consistent,
meaning not
> every field will come in all child records so my flat
file is of no
> use as i donno where a particular field comes

A small example would be helpful (showing input and desired
output).

- Mark.

_______________________________________________
Perl-XML mailing list
Perl-XMLlistserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs

RE: want to Convert XML to FLAT file
country flaguser name
United States
2007-02-06 17:04:39

XML Simple by default deparses things into a hash when possible&#8230;which will not guarantee order.&nbsp; Take a look at the options you can send XML::Simple on the CPAN doc page, those may or may not give you enough flexibility.  If not, you may have to look at something like writing an XML SAX filter (more work than XML Simple, but better control over your data processing).

 

-Mike

 


From: perl-xml-bounceslistserv.ActiveState.com [mailto:perl-xml-bounceslistserv.ActiveState.com] On Behalf Of vikram veer
Sent: Tuesday, February 06, 2007 11:33 AM
To: Shlomi Fish; perl-xmllistserv.activestate.com
Subject: Re: want to Convert XML to FLAT file

 

Thanks a  lot for immediate response.i was able to produce a flat file by using XML::Simple and a small piece of code ,but the xml file comes with fields which are neither in order nor consistent, meaning not every field will come in all child records so my flat file is of no use as i donno where a particular field comes

 

one more thing is :

 

my $t= XML::Twig->new(
 &nbsp;   ;  # the twig will include just the root and selected titles&nbsp;
   ; &nbsp; twig_roots  ; => { 'title' => &amp;print_n_purge,}
&nbsp; &nbsp; 
 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp;  );

sub print_n_purge
 &nbsp;  {
 my( $t, $elt)= _;
 ;print ;$elt->text ; &nbsp;  # print the text (including sub-element texts)

print";n";
 $t-&gt;purge;&nbsp; &nbsp;   ; &nbsp; &nbsp; # frees the memory

 &nbsp;  }

 

This code is able to print all values record wise but is there any option to separate the values with some delimiter and sort them before printing in this twig_roots  ; or any other code..

 

im not familiar with these packages..any reference with good num of exampleswould also be helpful

Thanks in advance
Shlomi Fish <shlomifiglu.org.il> wrote:

Hi!

On Saturday 03 February 2007 14:22, vikram veer wrote:
&gt; hi all,
>; I have the following tasks to do in PERL
>;

First of all see:

http://www.perl.org.il/misc.html#pl_vs_pl

> 1)xml file to flat file(only values not tags) where i can distinguish
> between attribute values and tag values
&gt;
> 2)Extract and print tags alone and number of times each field has occured
>
> is there any package which can do this for me ..If so please suggest me a
> place where i can get simple examples.
>

There are many packages that can do this. I recommend XML::LibXML:

http://search.cpan.org/dist/XML-LibXML/

It has both a DOM/XPath and a SAX interface. You can use the DOM unless the
files you're processing are extremely large and won't fit inside your
computer's memory at once. If not, use SAX, which is an event-based parser.

Regards,

Shlomi Fish

---------------------------------------------------------------------
Shlomi Fish shlomifiglu.org.il
Homepage: http://www.shlomifish.org/

Chuck Norris wrote a complete Perl 6 implementation in a day but then
destroyed all evidence with his bare hands, so no one will know his secrets.

 

 &nbsp;


Here̵7;s a new way to find what you're looking for - Yahoo! Answers

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )