| eurosnob@gmail.com 2006-12-15, 6:59 pm |
| I think I'm using the right terminology... I have a script that I'm
trying to get properly formed XML out of, using a hashref. I can't
find the right combination of parameters to get the XML looking
'right'. Here's what I'm trying to get:
<?xml version="1.0" encoding="UTF-8" ?>
<UploadResponseTransaction
xmlns:api="http://www.server-example.com/uploadapi">
<ResponseHeader>
<TransactionNumber>123456789</TransactionNumber>
</ResponseHeader>
</UploadResponseTransaction>
Here's the basic code I'm working with:
#!/usr/bin/perl
use warnings;
use strict;
use XML::Simple;
my $request = "FDXSubscriptionRequest";
my $submit = {
'UploadResponseTransaction' => {
'xmlns:api' =>
'http://www.server-example.com/uploadapi',
'ResponseHeader' => {
'TransactionNumber' => '123456789',
}
}
};
my $xs = XML::Simple->new(
# See below for options...
);
print $xs->XMLout($submit);
With the new() options set as so:
ForceArray => 1,
RootName => undef,
KeepRoot => 1,
KeyAttr => [ 'xmlns:api' ],
XMLDecl => '<?xml version="1.0" encoding="UTF-8" ?>'
I get the 'xmlns:api' value as an attribute, as needed, but everything
else is similarly collapsed:
<?xml version="1.0" encoding="UTF-8" ?>
<UploadResponseTransaction
xmlns:api="http://www.server-example.com/uploadapi">
<ResponseHeader TransactionNumber="123456789" />
</UploadResponseTransaction>
If I use 'NoAttr => 1' the rest of the XML is okay but of course
xmlns:api becomes an element instead of an attribute:
<?xml version="1.0" encoding="UTF-8" ?>
<UploadResponseTransaction>
<xmlns:api>http://www.server-example.com/uploadapi</xmlns:api>
<ResponseHeader>
<TransactionNumber>123456789</TransactionNumber>
</ResponseHeader>
</UploadResponseTransaction>
Is there a way of forcing certain key/value pairs into attributes, but
leaving / forcing everything else to be a nested element? I'm totally
bewildered by the docs at the CPAN site, and I've read through what
Google found on this group before posting, without finding anything
that was on-point.
Thanks!
|