|P is for Practical|
Getting started with XMLby pileofrogs (Priest)
|on Oct 21, 2009 at 20:04 UTC||Need Help??|
pileofrogs has asked for the
wisdom of the Perl Monks concerning the following question:
Greetings monks, ye great and powerful...
Every now and again I have to deal with some XML (as much as I hate the stuff) and I pretty much always cludge it. Sometimes I'll use XML::Simple, or other times I'll just use some regexes. I think it's about time I learned how to handle it properly. I'll describe my present problem, but please keep in mind that I really want general XML guidance.
I'm working with Google's contacts API and when you edit a contact, you need to not only parse the blob of XML but you have to edit it and return the whole thing or the contact gets screwed up. IE, it overwrites the existing contact with the contents of the returned XML blob. So, I need to be able to read some XML, turn it into useful data structures and then turn it back into the same XML with a few values changed.(If you've never worked with XML, that's not easily done because XML does not map directly to data structures the way that, say JSON and YAML do. So, you can't convert an arbatrary data structure into XML and assume another XML implementation would produce the same XML.) XML does have things like a DTD (which I've never used).
To summarize, I need to be able to convert XML into data and back to XML preserving the XML format (not sure if format is the word here... layout?). I think DTD's might be involved, but I don't know how to use them. I'm working with a Google API which uses ATOM feeds, but I really want more general advice that will apply to XML that isn't a Google API ATOM feed. What i'd really like is recommendations of perl modules that can turn XML to data and back again without breaking the XML and links to web pages that tell me why it works the way it does.
Thank you all for wasting your time reading this and possibly even helping me.