Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Perl XML

by ramya2005 (Scribe)
on Aug 09, 2005 at 22:50 UTC ( #482459=perlquestion: print w/ replies, xml ) Need Help??
ramya2005 has asked for the wisdom of the Perl Monks concerning the following question:

Dear Users:

I am new to Perl programming. Please help me in doing XML parsing and editing.

In my project, the user will provide me with a user friendly hash which not necessarily have the same structure as the example XML. I should be able to read that hash and modify the corresponding tags in the example XML file.

Comment on Perl XML
by Joost (Canon) on Aug 09, 2005 at 23:11 UTC
      I can't use XML::Simple because it is not preserving attributes and elements.
      Also for my application, I have to preserve the order and structure of the XML that I am creating.
      Regarding my requirement, I should be able to parse the XML file going step by step from top to bottom.
      While parsing I should be able to edit some of the tags and so on. When I finish I should be able to create an XML which is similar to the original one in structure.
        I tend to use XML::Twig for most of my perl/XML work, but most "full featured" XML parsers should be able to deal with your data provided it's presented as actual XML (your <img> tag is missing an ending slash, so your input is not valid).

        If you have valid XML input, XML::Parser is probably one of the most flexible solutions, but IMO most problems can be solved easier with either XML::Twig or even XML::Simple. (See also the ForceArray and ForceContent options of XML::Simple)

        update: ignore the parts I striked - I was replying to 2 different XML threads at the same time, and I got confused. Luckily, most of the advise is reasonably sound. :-)

by chanakya (Friar) on Aug 10, 2005 at 05:49 UTC
    I fully agree to Joost post. XML::Twig and XML::Parser will be sufficient for your parsing/checking needs. The following link contains some good tutorials and examples to start you on the job xmltwig. The tutorials in this link may be of help XML::Twig tutorials

    Good Luck
    May the force be with you !!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://482459]
Approved by Joost
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2015-07-04 07:38 GMT
Find Nodes?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...

    Results (58 votes), past polls