Re: Help using XML::Parser
Thomas R Wyant_III wrote: snip The things that XML::Simple will lose for you include: snip * The order of duplicate tags (e.g. multiple Member tags). Does this mean that contents of the value array in the code below could be out of order? I ran it through 10 value/value tags and I couldn't find one out of order. I could see that the tags could be messed up if I ran the hash through a XMLout.. #!/usr/bin/perl -w use XML::Simple; my $xmltext = 'beginanother'; foreach my $i (0 .. 10) { $xmltext .= value$i/value; } $xmltext .= '/another/begin'; my $xs = new XML::Simple(suppressempty = undef); #save a reference of the hash to $upperref. my $upperref = $xs-XMLin($xmltext); print looking for a number out of sequence\n; my $last_number = -1; my $count = 0; foreach my $j (@{$upperref-{another}{value}}) { unless (($j - $last_number) == 1) { print Error: $j is out of order\n ; $count ++; } $last_number = $j; } print There are $count objects out of order\n; ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Help using XML::Parser
That's what I use. I have some sample code of how to use it if you would like. -Original Message- From: Philip Morley [mailto:PMorley;edisonmission.com] Sent: Wednesday, October 30, 2002 8:28 AM To: [EMAIL PROTECTED] Subject: Help using XML::Parser I am new to using XML, so can someone please help me out. Suffice to say, in my perl script a scalar variable gets set with a valid XML string. For example, let's say: Family FamilySurnameFlintstone/FamilySurname Members MemberNameFred/MemberName MemberRoleFather/MemberRole /Members /FamilySurname /Family I could carry on with this example, but hopefully you get the drift. There will be repetitions in the XML document. For example there will be other Members nested in the FaimilySurname group. What I want to do be able to extract the fields from the document (Flintstone, Father, Fred, etc). Is XML::Parser the right module to use? Any general pointers would be much appreciated. Any code snippets as well. Thanks, Phil. ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Help using XML::Parser
Phil - You might want to look at XML::Simple. I get the impression XML::Parser is the foundation of a _lot_ of XML code (including XML::Simple). XML::Simple will load the XML into a data structure that looks a lot more like what you probably want to massage with Perl. It goes to considerable lengths to normalize the internal representation of XML, and you will find that they don't call it data reduction for nothing. The things that XML::Simple will lose for you include: * The top-level pair of tags (but you can configure it to keep them) * Text (or at least whitespace) which is not enclosed by the innermost set of tags (e.g. the newline and two spaces before the FamilySurname tag in your example. * The order of duplicate tags (e.g. multiple Member tags). * Some of its normalization obfuscates the difference between values and attributes. This is a feature, and is to a certain extent configurable. What I would recommend is write stub scripts to just load the XML, using both XML::Parser and XML::Simple. Use Data::Dumper to dump the output, see which output you like best, and go. Tom Wyant This communication is for use by the intended recipient and contains information that may be privileged, confidential or copyrighted under applicable law. If you are not the intended recipient, you are hereby formally notified that any use, copying or distribution of this e-mail, in whole or in part, is strictly prohibited. Please notify the sender by return e-mail and delete this e-mail from your system. Unless explicitly and conspicuously designated as E-Contract Intended, this e-mail does not constitute a contract offer, a contract amendment, or an acceptance of a contract offer. This e-mail does not constitute a consent to the use of sender's contact information for direct marketing purposes or for transfers of data to third parties. Francais Deutsch Italiano Espanol Portugues Japanese Chinese Korean http://www.DuPont.com/corp/email_disclaimer.html ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs