tdane has asked for the wisdom of the Perl Monks concerning the following question:
I use perl a lot for "getting the job done." I'm in a corner now where I have to use perl for a production-y tool that calls an XML REST API. Normally for perl and XML I make do with XML::Simple. I know it is discouraged, but is *is* simple and gets the job done.
Now I need to read an XML document, modify it, and POST it back to that REST API compliant with an XML Schema. XML::Simple won't cut it -- too many ways it will write the XML out differently than the input. So I have turned to XML::Compile and XML::LibXML. I've got it working, but I think it can work better for my purpose.
I am loading my schema with XML::Compile and and I am reading in my XML document with a READER. I end up with a reference variable to XML::LibXML::Element. I am able to use method calls like ->addChild to do to this structure what I need to do, but then I found this blog post which shows me how I can construct a hash of hashes not dissimilar to what XML::Simple gives me. I am much more comfortable manipulating this kind of structure. The blog post shows how to get an "empty" template, fill it out, and use that structure to generate an XML document. This is great, but for my use case I don't want a completely empty structure where I have to populate every tag. I want a structure populated with values from an input XML document.
In other words, I have done a GET from my REST API and I have an XML document in a string compliant with my Schema (which I have successfully built with XML::Compile). Now instead of using the READER to get perl objects where I have to use methods to access and change the contents, I want to get the same kind of structure as the example from the blog:
warn $schema->template('PERL', 'addresses');
But instead of an empty structure, I want it initialized with the data from my XML string. Can anyone show me the way to do that? I am just NOT finding it...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::Compile template initialized from XML document
by Corion (Patriarch) on May 11, 2016 at 17:28 UTC | |
by tdane (Acolyte) on May 11, 2016 at 21:47 UTC | |
by markov (Scribe) on May 12, 2016 at 07:08 UTC | |
by tdane (Acolyte) on May 12, 2016 at 15:07 UTC | |
by tdane (Acolyte) on May 12, 2016 at 19:24 UTC | |
by tdane (Acolyte) on May 12, 2016 at 21:08 UTC | |
by markov (Scribe) on May 12, 2016 at 23:12 UTC | |
|
Re: XML::Compile template initialized from XML document
by markov (Scribe) on May 12, 2016 at 06:56 UTC |