[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] MacPerl and XML



Chris has posted XML-Parser-2.19 on CPAN. Here are a few comments to go
along with that.

XML represents all line-ends as octal 12 (\012). Contrary to what most of
the XML module authors fondly imagine, this isn't guaranteed to be the
same as \n.

Passing *in* text to be parsed is not a problem. The Mac \015 gets
translated to \012 internally. Where we currently have a problem is when
we request text back, as a *string*. None of the XML modules are
translating \012 back to \n (which for us in MacPerl is actually \015, and
on Unix would stay as \012).

So here's a suggestion. When it comes time to use a stringification
method, either put in something like

$str =~ tr/\012/\n/;

after your

$str = $xml_obj->string();

call, before you print out $str, or if you're going to be using
stringification methods a lot, make this change in the module for each
method that you aim to use.

As it stands right now, _all_ of the XML modules are functional in
MacPerl, with this caveat. If you run the 't' tests, a few of the failures
ae due to Unix paths, the rest are due to this newline problem. Other than
that, the modules work.

As an illustration, this code snippet works fine (assuming you've got
XML-Parser-2.19, and all of the other modules that you need to run
XML-XQL, which latter by the way I've tested through 0.58). The code is
essentially that in the POD Synopsis:

 use XML::XQL; 
 use XML::XQL::DOM; 

 $parser = new XML::DOM::Parser; 
 $doc = $parser->parsefile ("bookstore.xml"); 

 # return 2nd and 3rd author elements
 $query = new XML::XQL::Query (Expr => '//author[1 $to$ 2]'); 
 @result = $query->solve ($doc); 

 # @result contains XML::DOM::Element objects
 foreach $elm (@result) {
    my $author = $elm->toString;
    $author =~ tr/\012/\n/;
    print $author, "\n";
 }

__END__

and this works just fine. Alternatively, you can take the translation, and
stick it right in the toString method if you're going to be using it a
lot.

I'm in the process of touching base with the XML module authors about
this, so as to possibly avoid the work associated with porting an XML
module every time a new one comes out. We have the right on our side. :-)

Other note: XML::XQL works very nicely, and is a lot of fun. Be advised,
though, aspects of it are bleeding-edge, so don't expect evrything to work
- yet. The author, Enno Dirksen, is very easy to work with and welcomes
bug reports. If you could, though, could you CC me when something comes
up, so I can take a look at it, and make sure it's not a MacPerl issue?
And try to make sure it's not the newline thing discussed above.

Thanks. Arved



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch