Perl5 compatible regular expression to retrieve some values in the middle of xml



I want a regular expression (Perl5-compatible regular expressions) to retrieve a tag value based on some other tag value inside a xml. For example, I have a xml as below in which I want to retrieve customerid and participationtype tag values only if the participationtype tag value is either clmt or insrd.


I have tried the following expression which is not working when the order of the tags are not matching the expression. Because the tags may be in any order.


I have tried the following which is not working when the order of the tags change.



<ASObject mappedClass="com.taliantsoftware.insurance.participation.ParticipantSummaryDTO">([^^]*?)<customerid tagClass="double">(.*)</customerid>([^^]*?)<participationtype tagClass="String">(clmt|insrd)</participationtype>([^^]*?)</ASObject>


XML is here:



<participantsummarydtos tagClass="object-array">
<ASObject mappedClass="com.taliantsoftware.insurance.participation.ParticipantSummaryDTO">
<customertype tagClass="String">prsn</customertype>
<linkednoteindicator tagClass="boolean">false</linkednoteindicator>
<new tagClass="boolean">true</new>
<customerid tagClass="double">3209053.0</customerid>
<participationtype tagClass="String">clmt</participationtype>
<updated tagClass="boolean">true</updated>
<voided tagClass="boolean">false</voided>
<blockexist tagClass="boolean">false</blockexist>
<participationid tagClass="double">2664273.0</participationid>
<customername tagClass="String">MELISSA M. CORNWELL</customername>
<customerphonenumber tagClass="String">3303660069</customerphonenumber>
<effectivedate tagClass="Date">1997-03-02 19:00:00.0 EST</effectivedate>
</ASObject>
<ASObject mappedClass="com.taliantsoftware.insurance.participation.ParticipantSummaryDTO">
<participationtype tagClass="String">clmt_atty</participationtype>
<blockexist tagClass="boolean">false</blockexist>
<customertype tagClass="String">busn</customertype>
<linkednoteindicator tagClass="boolean">false</linkednoteindicator>
<new tagClass="boolean">true</new>
<customerid tagClass="double">8017633.0</customerid>
<updated tagClass="boolean">true</updated>
<voided tagClass="boolean">false</voided>
<customerfaxnumber tagClass="String">3307433451</customerfaxnumber>
<participationid tagClass="double">8.841391E7</participationid>
<effectivedate tagClass="Date">1997-05-28 20:00:00.0 EDT</effectivedate>
<customername tagClass="String">GREEN HAINES SGAMBATI CO, LPA</customername>
<customerphonenumber tagClass="String">3307435101</customerphonenumber>
</ASObject>
<ASObject mappedClass="com.taliantsoftware.insurance.participation.ParticipantSummaryDTO">
<participationtype tagClass="String">emp_rep</participationtype>
<blockexist tagClass="boolean">false</blockexist>
<customertype tagClass="String">busn</customertype>
<linkednoteindicator tagClass="boolean">false</linkednoteindicator>
<new tagClass="boolean">true</new>
<customerid tagClass="double">8021870.0</customerid>
<updated tagClass="boolean">true</updated>
<voided tagClass="boolean">false</voided>
<customerfaxnumber tagClass="String">6147666888</customerfaxnumber>
<enddate tagClass="Date">2011-01-04 19:00:00.0 EST</enddate>
<participationid tagClass="double">7.7477885E7</participationid>
<effectivedate tagClass="Date">2010-04-11 20:00:00.0 EDT</effectivedate>
<customerphonenumber tagClass="String">8008256755</customerphonenumber>
<customername tagClass="String">COMPMANAGEMENT, INC.</customername>
</ASObject>
<ASObject mappedClass="com.taliantsoftware.insurance.participation.ParticipantSummaryDTO">
<participationtype tagClass="String">insrd</participationtype>
<blockexist tagClass="boolean">false</blockexist>
<customertype tagClass="String">busn</customertype>
<linkednoteindicator tagClass="boolean">false</linkednoteindicator>
<new tagClass="boolean">true</new>
<customerid tagClass="double">1011089.0</customerid>
<updated tagClass="boolean">true</updated>
<voided tagClass="boolean">false</voided>
<customerfaxnumber tagClass="String">3305452444</customerfaxnumber>
<participationid tagClass="double">1.7638265E7</participationid>
<effectivedate tagClass="Date">1997-03-02 19:00:00.0 EST</effectivedate>
<customername tagClass="String">OMNI MANOR, INC</customername>
<customerphonenumber tagClass="String">3305451550</customerphonenumber>
</ASObject>
</participantsummarydtos>

No comments:

Post a Comment