Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Zaurus addressbook.xml parser

by Ryszard (Priest)
on Nov 20, 2003 at 14:54 UTC ( [id://308585]=CUFP: print w/replies, xml ) Need Help??

A pretty rough addressbook.xml parser i whipped up. I intend to use it in combination with apache and gnokii to send sms's..

Given the addressbook is actually xml one could probably install one of the many xml parsers available on CPAN, but this is good enuff for me.. :-)

Improvements welcome.. ;-)

#!/usr/bin/perl -w use strict; undef $/; open(FH, 'addressbook.xml') || die "$!"; my $ab = <FH>; $ab =~ s/\/\>//g; my @book = split(/\<Contact/, $ab); my %addresses; foreach my $address (@book) { if ($address =~ /Uid/) { my $tmp = $address; $tmp =~ /(Uid\=.+\")/; my $Uid = $1; my @fields = split(/\"\s+/ , $address); foreach my $field (@fields) { $field =~ s/\"//g; my @data = split(/=/,$field); $addresses{$Uid}{$data[0]} = $data[1]; } } } foreach my $Uid (keys %addresses) { print "$Uid: \n"; foreach (keys %{$addresses{$Uid}} ) { print " $_=$addresses{$Uid}{$_}\n"; } print "\n"; }

Replies are listed 'Best First'.
Re: Zaurus addressbook.xml parser
by davido (Cardinal) on Nov 20, 2003 at 17:57 UTC
    It's my understanding that Sharp moved away from the XML format for the Zaurus's PIM applications in favor of a proprietary format as of the v3.10 Sharp ROM version update.

    Only pre-3.10 Sharp ROM's (and presumably the various Open Source ROMs) store their PIM data in XML format. The unfortunate thing is that the 3.10 ROM is so far superior to the older Sharp ROM's (IMHO) that it's worth upgrading even if it means having to use the proprietary PIM data format.


    "If I had my life to live over again, I'd be a plumber." -- Albert Einstein
Re: Zaurus addressbook.xml parser
by Aristotle (Chancellor) on Nov 22, 2003 at 08:40 UTC
    I think you're going through way too much effort for a breakable parser. XML::LibXML or XML::Twig make proper parsing for simple stuff no more difficult than a bit of regex twiddling is, and will also handle complex cases. If you post a representative snippet of your input I can whip up some libxml code that won't be longer than half your script. And much easier to read.

    Makeshifts last the longest.

      Yup, I agree, using an XMP Parser would be better, (and i'm pretty familiar with some of the ones on CPAN).

      The goal here was to produce something that had zero dependencies for use on my Zaurus, which is a PDA.

      I wanted something that i could carry around or have quick access to which was the simplest to install / use. I acknowledge all the failings, i agree / know about the parsers, this is just "something cool" which works for me and my data.

      FYI, a sample record,

      <Contact FirstName="FFFFFF" LastName="LLLL" FileAs="LLLL, FFFFFF" Busi +nessMobile="+12345678901" DefaultEmail="wwwwwwwwww@wwwwww.ww" Emails= +"wwwwwwwwww@wwwwww.ww " HomePhone="1111 111 111" Gender="0" WorkEma +il="wwwwwwwwww@wwwwwwww.ww" rid="53" rinfo="0" Uid="-1068731722" />

      Update:The entire program is now on the Zaurus-users mailing list.

Re: Zaurus addressbook.xml parser
by William G. Davis (Friar) on Nov 20, 2003 at 17:51 UTC

    [O]ne could probably install one of the many xml parsers available on CPAN

    Or use one of the parsers that came with your distribution, like XML::Parser.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://308585]
Approved by ybiC
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-05-30 15:53 GMT
Find Nodes?
    Voting Booth?

    No recent polls found