Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

I love XML::Twig

by Skeeve (Parson)
on Oct 06, 2006 at 07:23 UTC ( [id://576622]=perlmeditation: print w/replies, xml ) Need Help??

Good Morning fellow monks!

Yesterday I got a task from my boss to come up with some XML code to be used as input for one of our programs. This program extracts information from XML documents and needs a kind of recipe I had to create.

I could have done this relatively fast "by hand". But this would have been boring, so I decided to do it the Perl way.

I already discovered XML::Twig about 3 years ago and I used it quite often. Since all the data I had to deal with for that task is XML, I used XML::Twig again.

Extracting the information from the document's templates was very easy and I was done real fast. I simply dumped it to STDOUT and wanted to create the input file by hand.

But then I realised: XML::Twig can't just parse! It can also create my XML output! The output part was done even faster! XML::Twig's perldoc pages are always a great help.

I really, really like this module! I only wish there were an "XML::Twig for Java". You know: Sometimes you simply have to use this Language.


s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Replies are listed 'Best First'.
Re: I love XML::Twig
by mirod (Canon) on Oct 06, 2006 at 08:28 UTC

    Well, first thanks for the praise, I appreciate. And this is Open-Source, you can port the module to Java, provided there is a Java interface with expat (although I don't see one in the list of expat wrappers).

    This reminds me that a few years back, around 2000 I think, I got an email from a PHP guy, who seemed to be quite new to the language actually, who wanted to port XML::Twig to PHP. So I sent him an email explaining the design of the module, what I thought would be easy to do, and what might be a little harder... that was a pretty long email... and that's the last I ever heard from him!

      Hi mirod!

      I didn't know XML::Twig's developer is a monk too... OTOH: This is the logical place to be, isn't it?

      In regards to poreting to Java: I'd love to be able to do that. Unfortunately I'm pretty sure I can't. My Java knowledge is not even near average, I think.


      s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
      +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
Re: I love XML::Twig
by prasadbabu (Prior) on Oct 06, 2006 at 10:23 UTC

    Skeeve++

    I think this is the time to give my experience as well with XML::Twig and mirod. I too love XML::Twig

    Six months back my boss assigned a tool for fresh development to convert XML file (inhouse DTD elements) to another XML file (customer based element). In this project we have to handle many attributes processing, elements replacement etc. He planned to develop the tool in usual method, using regex. I suggested XML::Twig to my boss and he gave approval to proceed further.

    Then I started using XML::Twig in my project. I developed the whole tool using XML::Twig and with less than 2% of regex. During development i asked many questions like 'ID' generation issue and 'ID' format in XML::Twig in SOPW and got help from monks and from mirod as well. In our company we are dealing fully with text processing and we use to develop many tools with 90% of regex. The disadvantage in using regex in our work is, text deletion use to happen if the regex is not good. After started using this module, we have avoided using regex wherever XML::Twig can be used efficiently and text deletion chance is very very low. Now we are developing 50% of our work using XML::Twig. I learned a lot from this module and always love to use this in my projects.

    I take this moment to convey my thanks to our monks and special thanks to mirod who helped me patiently (when i ask help through /msg) to complete my project successfully.

    Prasad

Re: I love XML::Twig
by dimar (Curate) on Oct 06, 2006 at 16:19 UTC
    Congrats on your enthusiasm for XML::Twig. One of its most noteworthy attributes is its ability to make XML itself more 'perlish'. Consequently, you may have many AHA! moments when you realize how much more flexibility you have when dealing with XML.
    I only wish there were an "XML::Twig for Java".
    You aren't the only one. In fact, many features of perl and its progeny are slowly sneaking into a JVM near you through any of several back doors. See [Groovy] and "Groovy XML Handling" for example. Another example of cross-language "idea borrowing" ... to put it charitably.
    http://www.developer.com/lang/article.php/10924_3548721_2 (search for "XML Handling")
    =oQDlNWYsBHI5JXZ2VGIulGIlJXYgQkUPxEIlhGdgY2bgMXZ5VGIlhGV
Re: I love XML::Twig
by Joost (Canon) on Oct 06, 2006 at 16:12 UTC
    XML::Twig is great stuff. I use it quite a bit. The only issue I've had with it is that for some reason (seems to be XML::Parser's fault, but I'm not sure) the utf8 flag isn't set on the output strings (i.e. on $_->text(), $_->xml_string() etc) even though they return utf8 encoded by default.

    update (2006-10-20) This appears to be a problem in a very old version of XML::Twig, I cannot reproduce it with later versions. (v3.15 and up)

      Hum, I'll have to check that. Does this happen with a specific version of Perl, or in any 5.8.*?

      As you mention, the problem most likely comes from XML::Parser, which was written when 5.5 was still cutting edge, and has been in "light maintenance mode" for quite some time now. That doesn't prevent me from fixing it in XML::Twig though (the length of the RT queue leaves me little hope that XML::Parser itself will be fixed anytime soon).

      More generally, please, please, let me know if you find any bug in the module, I am more than happy to fix them if I can.

Re: I love XML::Twig
by pandega (Initiate) on Oct 06, 2006 at 18:07 UTC
    I love XML::Twig too. Without it, I'd never have been that comfortable with XML. Also its tutorials are very helpful. Thank you mirod for your contribution and keep up the good work !

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://576622]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-03-28 19:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found