in reply to hashref with(out) arrays
Ok, so taking a stab at XML::Rules and the first thing I find in my XML is a namespace tag prefixed on all of my data elements.
<ns2:Height Units="inches">1.00</ns2:Height> <ns2:Length Units="inches">1.00</ns2:Length> <ns2:Width Units="inches">1.00</ns2:Width> <ns2:Weight Units="pounds">0.01</ns2:Weight>
In my rules, do I refer to this tag as "ns2:Height" or as "Height" somehow accounting for the namespace?
Update:
And do I need to deal with every tag in the XML? For example, if my XML is:
<ns2:Item> <ns2:Attributes> <ns2:Height Units="inches">1.00</ns2:Height> <ns2:Length Units="inches">1.00</ns2:Length> <ns2:Width Units="inches">1.00</ns2:Width> <ns2:Weight Units="pounds">0.01</ns2:Weight> </ns2:Attributes> </ns2:Item>
Can I have rules that just deal with Height, Length, Width, Weight, etc? Or do I have to have rules for Item and Attributes to get to the other attributes? I am unclear from reading the XML::Rules documentation. The example has a _default tag which looks like it is supposed to deal with all items not otherwise specified but so far, I am only getting Item in my output as:
0 HASH(0x36a9310) 'Item' => undef
The rules that I am using are:
my @rules_prod = ( _default => sub { $_[0] => $_[1]->{_content}}, 'ns2:Weight' => sub { weight => $_[1]->{_content} }, 'ns2:Height' => sub { height => $_[1]->{_content} }, );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: hashref with(out) arrays
by haukex (Archbishop) on Nov 23, 2017 at 09:16 UTC | |
by bfdi533 (Friar) on Nov 23, 2017 at 17:09 UTC |