in reply to Re: Perl and XML
in thread Perl and XML
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Perl and XML
by shmem (Chancellor) on Apr 29, 2008 at 17:58 UTC | |
Did you lather, rinse, repeat? You would have found out that the data structure you want with XML::Simple is as follows:
Output:
Getting rid of the outer <opt> tag is left as an exercise to the reader. As dragonchild wrote above, you need to transform your hash so as to fit the module you are using. --shmem
| [reply] [d/l] [select] |
by Bugz (Acolyte) on Apr 29, 2008 at 19:48 UTC | |
I think I made my questions confusing. I apologise. Let me rephrase my question: I have a Perl Hash as shown I need to convert it to a Valid XML File. I tried using XML::Simple, but it changes '1' to <1> which is invalid XML Tag. I checked CPAN docs on XML::Simple, and while they talk about KeyAttr ValueAttr, I am unsure How I can do what you and dragonchild suggest. I wanted to know if I could handle this conversion better using XML::Writer or XML::Twig and if so how? Thanks, Bugz | [reply] [d/l] |
by shmem (Chancellor) on Apr 29, 2008 at 22:17 UTC | |
Let me rephrase my question: You don't rephrase, you just repeat the contents of your OP... ;) I am unsure How I can do what you and dragonchild suggest. Did you even try? You provided me with a hash; I showed you the correct structure which would produce the output you described as desired. You have to transform your original hash, either in-place or by stuffing members into another temporary structure. What pieces of the hash transformation are difficult for you? Okay, here' a complete working example. Since you provide sample data which is a bit inconsistent compared to the expected output (there's no structure member for the "No" attribute, so I just deduce them from the sorted hash keys) you will have to adapt the following for your real data, I guess.
Hope that helps. I won't repeat the example for XML::Writer or XML::Twig; their requirements for input data might be different. But AFAIK there's no module which produces valid XML from your hash as is. --shmem
| [reply] [d/l] |