ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-xml
perl-xml
Re: Newbee question: how to manipulate xml file
by A. Pagaltzis other posts by this author
Mar 17 2006 8:52PM messages near this date
view in the new Beta List Site
Re: Newbee question: how to manipulate xml file | [ANN] XML::Atom::Syndication v0.9
& XSLT * lemkemch@[...].de <lemkemch@[...].de>  [2006-03-18 00:00]:
> What I basically want  to do is
> 
>   $xml = readxmlfromfile "file";
>   add/manipulate some elements
>   writexmltofile "newfile";
> 
> To get started, how to read a xml file and write it back such
> that the new file is semantically identical to the original?

I use XML::LibXML for pretty nearly everything I want to do with
XML nowadays. For step 3, you simple using the `toString` method
of a document object. For step 2, you can use DOM, which is an
excercise in masochism, or XPath, which is elegantly simple. In
comparison, navigating the data structures generated by
XML::Simple is clunky, ugly and error-prone.

Before XML::LibXML brought XPath to Perl, I used to use
XML::Twig. For some things, that is still a good choice (you can
keep memory usage low on extremely large documents without having
to resort to SAX, at the expense of speed). Nowadays, it too has
XPath support.

Another reason I prefer ::LibXML is its companion, ::LibXSLT,
which is a devilishly fast and very compliant XSLT 1.0 processor.
For complex XML manipulation tasks, XSLT often beats Perl hands
down (though there are *some* things that are much easier in Perl
than XSLT); you just have to get over the fact that the syntax
being expressed in XML makes it awkawrdly verbose.

I never thought Iâ??d say that I like XML. Then I learned about
XPathâ?¦

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/> 
_______________________________________________
Perl-XML mailing list
Perl-XML@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
lemkemch
Grant McLean
lemkemch
A. Pagaltzis

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved