Link to home
Start Free TrialLog in
Avatar of PERLfisher
PERLfisher

asked on

Perl - Trying to Parse XML File

Hi,

I am trying to "read" an XML file with PERL with a view to converting some of the element names. Unfortunately I am a bit stuck!

This is my XML:

<?xml version="1.0" encoding="UTF-8"?>
<Data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ApplicationData>
<ApplicationIDs ClaimID="0000000000002801" InsurerAcceptingBranchID="001" InsurerAcceptingBranchName="Morgan Cole COMP branch 1" InsurerBranchID="001" InsurerBranchName="Morgan Cole COMP branch 1" InsurerID="COMP028" InsurerName="Morgan Cole COMP" MainApplicant="a, a " RepresentativeBranchID="001" RepresentativeBranchName="Morgan Cole branch 1" RepresentativeID="CR00028" RepresentativeName="Morgan Cole" RepresentativeOrgPath="/CR00028"/>
<ClaimDetails SentDate="2010-04-13"/>
<FraudStated/>
<StatementOfTruth SignatoryType="S" RetainedSignedCopy="1"/>
</ApplicationData>
<ClaimAndClaimantDetails>
<ClaimantRepresentative>
<CompanyDetails CompanyName="Morgan Cole" ContactName="a" ContactSurname="a" ReferenceNumber="a" TelephoneNumber="02008918273645">                  <Address AddressType="A" City="City" Country="United Kingdom" County="County" District="District" HouseName="House" HouseNumber="3" Street1="Street"/>               </CompanyDetails>
</ClaimantRepresentative>
<DefendantDetails DefendantStatus="P" PolicyNumberReference="a">
<PersonalDetails Surname="a" TitleType="1">      <Address AddressType="A" City="a" Country="a" County="a" District="a" HouseName="a" HouseNumber="1" PostCode="a" Street1="a" Street2="a"/>    </PersonalDetails>
<Vehicle VRN="a"/>
<InsurerInformation InsurerName="Morgan Cole" InsurerOrganizationID="COMP028" InsurerOrganizationPath="/COMP028" InsurerType="I">      <BranchDetails BranchID="001" BranchName="Morgan Cole COMP branch 1" BranchPath="/COMP028/001"/>    </InsurerInformation>
<CompanyDetails>
<Address AddressType="A"/>
</CompanyDetails>
</DefendantDetails>
<ClaimantDetails ChildClaim="0" NationalInsuranceNumber="NH814365B" Occupation="a">    <PersonalDetails DateOfBirth="1956-06-16" Name="a" Surname="a" TitleType="1">      <Address AddressType="A" City="a" Country="a" County="a" District="a" HouseName="q" HouseNumber="11" PostCode="a" Street1="a" Street2="a"/>    </PersonalDetails>    <Vehicle VRN="a"/>  </ClaimantDetails>
</ClaimAndClaimantDetails>
<MedicalDetails>
<Injury BoneInjury="0" HospitalAttendance="0" InjurySustainedDescription="v" MedicalAttentionSeeking="0" Other="0" SoftTissue="0" TimeOffRequired="0" Whiplash="1"/>
<Rehabilitation RehabilitationNeeds="0" RehabilitationUndertaken="1"/>
<HospitalSearch/>
</MedicalDetails>
<RepairsAndAlternativeVehicleProvision>
<Repairs ClaiimingDamageOwnVehicle="0">
<AlternativeCompany/>
</Repairs>
<AlternativeVehicleProvision ClaimantEntitled="0">
<Provider>
<Vehicle/>
</Provider>
</AlternativeVehicleProvision>
</RepairsAndAlternativeVehicleProvision>
<AccidentData>
<AccidentDetails AccidentDate="2010-03-01" AccidentDescription="v" AccidentLocation="here" AccidentTime="16:17" ClaimantType="0" OccupantsNumber="1" PoliceReported="0" Seatbelt="1">    <Driver>
<Address/>
</Driver>    <Owner>
<Address/>
</Owner>    <Vehicle/>    <InsuranceCompanyInformatiion>      <Address AddressType="A"/>    </InsuranceCompanyInformatiion>    <WeatherConditions Fog="0" Ice="0" Other="0" Rain="0" Snow="0" Sun="1"/>    <RoadConditions Dry="1" Ice="0" Mud="0" Oil="0" Other="0" Snow="0" Wet="0"/>    <AccidentCircumstances AccidCarPark="0" AccidChangingLanes="0" AccidRoundabout="0" ConcertinaCollision="1" Other="0" VhclHitInRear="0" VhclHitSideRoad="0" VhclHitWhilstParked="0"/>    <PoliceDetails/>  </AccidentDetails>
<BusCoach BussOrCoach="0"/>
</AccidentData>
<OtherPartyDetails/>
<LiabilityFunding>
<Liability DefendantResponsability="v"/>
<Funding FundingUndertaken="0"/>
</LiabilityFunding>
<InsurerResponse>
<LiabilityCausation>    <DefendantAdmits/>  </LiabilityCausation>
<ProvidedServices NotificationDate="2010-04-13">    <DefendantsInsurer>      <Address/>    </DefendantsInsurer>  </ProvidedServices>
</InsurerResponse>
<InterimSettlementPack>
<ClaimantRepresentative PaymentMoreRequested="">
<CompanyDetails CompanyName="Morgan Cole" ContactName="a" ContactSurname="a" ReferenceNumber="a" TelephoneNumber="02008918273645">
<Address AddressType="A" City="City" Country="United Kingdom" HouseNumber="3" Street1="Street"/>
</CompanyDetails>
</ClaimantRepresentative>
<DefendantRepresentative>
<DefendantsInsurer/>
</DefendantRepresentative>
<MedicalReport MedicalReportStage2_1=""/>
<LossesToDate SeatbeltContributory="">
<ClaimantLosses/>
<DefendantReplies/>
<Total>
<LossesTotal CRUDeductions=""/>
</Total>
</LossesToDate>
<InterimPayment>  <ClaimantRequestForInterimPayment/>  <DefendantResponsesToInterimPaymentRequest/>
</InterimPayment>
<StatementOfTruth/>
<Phase2ClaimantDefendantDates>
<ClaimantRepresentativeDates/>
<DefendantRepresentativeDates/>
</Phase2ClaimantDefendantDates>
</InterimSettlementPack>
<Stage2SettlementPack>
<ClaimantRepresentative>
<CompanyDetails CompanyName="Morgan Cole" ContactName="a" ContactSurname="a" ReferenceNumber="a" TelephoneNumber="02008918273645">
<Address AddressType="A" City="City" Country="United Kingdom" HouseNumber="3" Street1="Street"/>
</CompanyDetails>
</ClaimantRepresentative>
<DefendantRepresentative>
<DefendantsInsurer/>
</DefendantRepresentative>
<MedicalReport MedicalReportStage2=""/>
<LossesToDate>
<ClaimantLosses/>
<DefendantReplies/>
<Total>
<CurrentTotal CRUDeductions=""/>
</Total>
</LossesToDate>
<AgreementData>
<FinalAgreementDetails>
<AgreementDetails/>
</FinalAgreementDetails>
</AgreementData>
<LastExtendedTime/>
<StatementOfTruth/>
<Phase2ClaimantDefendantDates>
<ClaimantRepresentativeDates/>
<DefendantRepresentativeDates/>
</Phase2ClaimantDefendantDates>
</Stage2SettlementPack>
<CourtProceedingsPack>
<ClaimantRepresentative>
<CompanyDetails CompanyName="Morgan Cole" ContactName="a" ContactSurname="a" ReferenceNumber="a" TelephoneNumber="02008918273645">
<Address AddressType="A"/>
</CompanyDetails>
</ClaimantRepresentative>
<DefendantRepresentative>
<DefendantsInsurer/>
</DefendantRepresentative>
<LossesToDate>
<ClaimantLosses/>
<DefendantReplies/>
</LossesToDate>
<CourtProceedingsPackPartA/>
<DisbursmentDisputed/>
<CourtProceedingsPackPartB>    <FixedCosts/>  </CourtProceedingsPackPartB>
<StatementOfTruth/>
<Phase2ClaimantDefendantDates>
<ClaimantRepresentativeDates/>
<DefendantRepresentativeDates/>
</Phase2ClaimantDefendantDates>
</CourtProceedingsPack>
<Timeouts>
<CurrentTimeout TimeOutType="" SelectedTimeOut="2010-05-07"/>
<PreCalculatedTimeouts>
<ClaimNotificationForm>
<Insurer LiabilityDecisionTimeout="" Stage1PaymentTimeout=""/>
<MIBorArt75 LiabilityDecisionTimeout="" Stage1PaymentTimeout=""/>
</ClaimNotificationForm>
<InterimSettlementPack>
<LowPayment InterimPaymentTimeout=""/>
<HighPayment InterimPaymentTimeout=""/>
</InterimSettlementPack>
<Stage2SettlementPack>
<Stage2DecisionOrCounterOffer Stage2DecisionOrCounterOfferTimeout=""/>
</Stage2SettlementPack>
<CourtProceedingsPack>
<CourtProceedings CourtProceedingsTimeout=""/>
</CourtProceedingsPack>
</PreCalculatedTimeouts>
</Timeouts>
</Data>

This is the relevant part of my script:

open(NEWFILE, '>C:\Perl\getHospitalsList\SendWaiting_Directory\GetClaim\Received\NewGetClaimData_Received.xml') or die $!;
my $secondfile= '\\\ITL019\SendWaiting_Directory\GetClaim\Received\TestGetClaimData_Received.xml';
my $secondparser = new XML::DOM::Parser;
my $seconddoc = $secondparser->parsefile($secondfile);
my $testvar=$seconddoc->getElementsByTagName('DefendantDetails')->item(0)->getFirstChild->getNodeValue;
print NEWFILE $testvar;
close NEWFILE;

I was hoping that this would print out the value of the DefendantDetails node and that, using this, I could navigate down to the PersonalDetails node and change the name to DefendantPersonalDetails. However, nothing is printed out! (there are no error messages though).

Any ideas anyone?
ASKER CERTIFIED SOLUTION
Avatar of wilcoxon
wilcoxon
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial