|
XML::Simple Module
Part:
1
2
3
4
5
(Continued from previous part...)
Here is the output of the program:
Hash dump without suppressempty => '':
$VAR1 = {
'system' => [
{
'content' => [
'
This is a testing system.
',
'
Needs to add more entries later.
'
],
'user' => [
{
'first_name' => [
'Mike'
],
'status' => 'active',
'last_name' => [
'Lee'
],
'email' => [
'mike@lee.com'
]
},
{
'first_name' => [
{}
],
'last_name' => [
'Wong'
],
'content' => '
Missing first name and email.
',
'email' => [
{}
]
}
]
}
]
};
XML output without suppressempty => '':
<system>
<content>
This is a testing system.
</content>
<content>
Needs to add more entries later.
</content>
<user status="active">
<first_name>Mike</first_name>
<last_name>Lee</last_name>
<email>mike@lee.com</email>
</user>
<user>
Missing first name and email.
<first_name></first_name>
<last_name>Wong</last_name>
<email></email>
</user>
</system>
Hash dump with suppressempty => '':
$VAR1 = {
'system' => [
{
'content' => [
'
This is a testing system.
',
'
Needs to add more entries later.
'
],
'user' => [
{
'first_name' => [
'Mike'
],
'status' => 'active',
'last_name' => [
'Lee'
],
'email' => [
'mike@lee.com'
]
},
{
'first_name' => [
''
],
'last_name' => [
'Wong'
],
'content' => '
Missing first name and email.
',
'email' => [
''
]
}
]
}
]
};
XML output with suppressempty => '':
<system>
<content>
This is a testing system.
</content>
<content>
Needs to add more entries later.
</content>
<user status="active">
<first_name>Mike</first_name>
<last_name>Lee</last_name>
<email>mike@lee.com</email>
</user>
<user>
Missing first name and email.
<first_name></first_name>
<last_name>Wong</last_name>
<email></email>
</user>
</system>
A couple of the interesting things to note here:
- Text in mixed context was parsed into a hash entry with the key hard coded as "content".
- Texts separated by child elements were parsed into a single hash entry with the value
as a reference to an array of multiple entries.
- Child elements with the same tag name were parsed into a single hash entry
with the value as a reference to an array of multiple entries.
- Child elements with the same tag name were grouped together, even if they were
separated by other child elements in the XML input. This will change the order of
child elements in the XML output.
- Without "suppressempty => ''", empty elements were indeed parsed as empty hashes.
- With "suppressempty => ''", empty elements were indeed parsed as empty strings.
(Continued on next part...)
Part:
1
2
3
4
5
|