<?xml version="1.0" encoding="windows-1252"?>
<node id="1002448" title="How to return two and more values by parsing XML with XML::Rules?" created="2012-11-06 04:45:20" updated="2012-11-06 04:45:20">
<type id="115">
perlquestion</type>
<author id="917684">
vagabonding electron</author>
<data>
<field name="doctext">
Dear Monks,&lt;br&gt;
I use  [mod://XML::Rules] to parse a huge XML document. As a Perl amateur I'm generally happy with the module since it does what I mean. Now however I'm stuck with the following problem.&lt;br&gt;
Here is the XML chunk.
&lt;code&gt;
&lt;Outpatient_Services&gt;
&lt;Outpatient_Service&gt;
&lt;Outpatient_Clinic&gt;
&lt;AM_Key&gt;AM01&lt;/AM_Key&gt;
&lt;Description&gt;Description of the Outpatient_Clinic&lt;/Description&gt;
&lt;Explanations&gt;Explanations to the Outpatient_Clinic&lt;/Explanations&gt;
&lt;/Outpatient_Clinic&gt;
&lt;/Outpatient_Service&gt;

&lt;Outpatient_Service&gt;
&lt;Outpatient_Clinic&gt;
&lt;AM_Key&gt;AM01&lt;/AM_Key&gt;
&lt;Description&gt;Description of the Outpatient_Clinic&lt;/Description&gt;
&lt;Explanations&gt;Explanations to the Outpatient_Clinic&lt;/Explanations&gt;
&lt;/Outpatient_Clinic&gt;
&lt;/Outpatient_Service&gt;

&lt;Outpatient_Service&gt;
&lt;Outpatient_Clinic&gt;
&lt;AM_Key&gt;AM02&lt;/AM_Key&gt;
&lt;Description&gt;Description of the Outpatient_Clinic&lt;/Description&gt;
&lt;Capacities_Outpatient_Clinic&gt;
&lt;Care_Point&gt;
&lt;VA_VU_Key_Outpatient_Clinic&gt;VA01&lt;/VA_VU_Key_Outpatient_Clinic&gt;
&lt;/Care_Point&gt;
&lt;Care_Point&gt;
&lt;Other&gt;
&lt;VA_VU_Other_Key_Outpatient_Clinic&gt;VA00&lt;/VA_VU_Other_Key_Outpatient_Clinic&gt;
&lt;Description&gt;Other Care Point of the Outpatient Clinic&lt;/Description&gt;
&lt;/Other&gt;
&lt;/Care_Point&gt;
&lt;/Capacities_Outpatient_Clinic&gt;
&lt;/Outpatient_Clinic&gt;
&lt;/Outpatient_Service&gt;

&lt;Outpatient_Service&gt;
&lt;Outpatient_Clinic_Special&gt;
&lt;AM_Special_Key&gt;AM06&lt;/AM_Special_Key&gt;
&lt;Description&gt;Description of the Outpatient_Clinic&lt;/Description&gt;
&lt;Capacities_Outpatient_Clinic_Special&gt;
&lt;Capacity&gt;
&lt;LK_Key&gt;LK01&lt;/LK_Key&gt;
&lt;/Capacity&gt;
&lt;Capacity&gt;
&lt;LK_Key&gt;LK02&lt;/LK_Key&gt;
&lt;/Capacity&gt;
&lt;/Capacities_Outpatient_Clinic_Special&gt;
&lt;Explanations&gt;Explanations to the Outpatient_Clinic&lt;/Explanations&gt;
&lt;/Outpatient_Clinic_Special&gt;
&lt;/Outpatient_Service&gt;

&lt;Outpatient_Service&gt;
&lt;Outpatient_Clinic&gt;
&lt;AM_Key&gt;AM04&lt;/AM_Key&gt;
&lt;/Outpatient_Clinic&gt;
&lt;/Outpatient_Service&gt;

&lt;Outpatient_Service&gt;
&lt;Outpatient_Clinic&gt;
&lt;Other&gt;
&lt;AM_Other_Key&gt;AM00&lt;/AM_Other_Key&gt;
&lt;Type&gt;Type of the other Outpatient Clinic&lt;/Type&gt;
&lt;/Other&gt;
&lt;Description&gt;Description of the Outpatient Clinic&lt;/Description&gt;
&lt;Capacities_Outpatient_Clinic&gt;
&lt;Care_Point&gt;
&lt;VA_VU_Key_Outpatient_Clinic&gt;VA02&lt;/VA_VU_Key_Outpatient_Clinic&gt;
&lt;/Care_Point&gt;
&lt;Care_Point&gt;
&lt;Other&gt;
&lt;VA_VU_Other_Key_Outpatient_Clinic&gt;VA00&lt;/VA_VU_Other_Key_Outpatient_Clinic&gt;
&lt;Description&gt;Other Care Point of the Outpatient Clinic&lt;/Description&gt;
&lt;/Other&gt;
&lt;/Care_Point&gt;
&lt;/Capacities_Outpatient_Clinic&gt;
&lt;Explanations&gt;Explanations to the Outpatient_Clinic&lt;/Explanations&gt;
&lt;/Outpatient_Clinic&gt;
&lt;/Outpatient_Service&gt;
&lt;/Outpatient_Services&gt;
&lt;/code&gt;

&lt;br&gt;&lt;b&gt;Update:&lt;/b&gt;The desired output presentation was not correct in the original, you can see it in the spoiler below.&lt;br&gt;
The output ought to be the following:
&lt;c&gt;
- Outpatient_Services:
    AM11: 1
    AM07: 1
    AM04: 1
&lt;/c&gt;
&lt;spoiler&gt;
I need the result in the following form (YAML-style):
&lt;code&gt;
- Outpatient_Services:
    Outpatient_Service:
    - AM11: 1
    - AM07: 1
    - AM04: 1
&lt;/code&gt;
&lt;/spoiler&gt;

However I need this not only for the AM-Keys but also for the LK-Keys and that is what I cannot achieve since there are two of them, not one.&lt;br&gt;
The following code chunk is a way out so that I at least get an info about the "Outpatient_Clinic_Special", but it is just a description, not the keys.
&lt;code&gt;
'Outpatient_Service' =&gt; sub {
	if (exists $_[1]-&gt;{Outpatient_Clinic}) 
	{
       if ( exists $_[1]-&gt;{Outpatient_Clinic}-&gt;{Other} )
		{
			return $_[1]-&gt;{Outpatient_Clinic}-&gt;{Description} =&gt; 1
		}
		else
		{
			return $_[1]-&gt;{Outpatient_Clinic}-&gt;{AM_Key} =&gt; 1 
		}
    } 
	elsif ( exists $_[1]-&gt;{Outpatient_Clinic_Special} ) 
	{
		return $_[1]-&gt;{Outpatient_Clinic_Special}-&gt;{Description} =&gt; 1; # as a way out.
	}
	else
		{ }
},
&lt;/code&gt;

Could you please give me a hint?&lt;br&gt;
Thanks in advance!&lt;br&gt;
VE</field>
</data>
</node>
