简体   繁体   中英

How do I read and write XML from Perl?

I need to reading from XML and write to XML through Perl. I don't know which packages to be installed. I am using Fedora Core 6. Please help me out to resolve this.

XML::Twig (as recommended by Maxwell Troy Milton King) is certainly a powerful tool for XML processing in Perl. I can second that recommendation and offer an alternative.

An alternative would be XML::LibXML . This includes "standards-based" features such as XPath ( XML::LibXML::XPathContext is usually needed), SAX and I'm pretty sure there's an XSLT processor that accepts LibXML DOM objects.

It does of course depend on what kind of processing you're doing any any other requirements. Perhaps if you can't decide between the answers here, post some more detail on the processing.

If by "writing XML" , you mean outputting transformed documents then the tool you use to read in and transform should be all you need. If you wish to have something help you create correct new XML documents, I've never used a library for that but a former colleague of mine created XML::Genx , a wrapper around the C library genx - so presumably he thought that was good ;-)

Afraid I don't know how to install on Fedora, but I expect you would find it easier to consider that a separate problem to deciding which libraries to install ;-).

Twig used to be one of the best APIs (a few years back that was - so it might have changed)

There seems to be a Fedora package for it . I guess you can install it like this:

yum install perl-XML-Twig

That should install other dependencies like Expat, XML::Parser and so on.

you can try XML-Simple

or XML::Smart

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM