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="00 1" RepresentativeBranchName=" Morgan Cole branch 1" RepresentativeID="CR00028" RepresentativeName="Morgan Cole" RepresentativeOrgPath="/CR 00028"/>
<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="020089182 73645"> <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="COM P028" 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="N H814365B" 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>
<RepairsAndAlternativeVehi cleProvisi on>
<Repairs ClaiimingDamageOwnVehicle= "0">
<AlternativeCompany/>
</Repairs>
<AlternativeVehicleProvisi on ClaimantEntitled="0">
<Provider>
<Vehicle/>
</Provider>
</AlternativeVehicleProvis ion>
</RepairsAndAlternativeVeh icleProvis ion>
<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/> <InsuranceCompanyInformati ion> <Address AddressType="A"/> </InsuranceCompanyInformat iion> <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="020089182 73645">
<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> <ClaimantRequestForInterim Payment/> <DefendantResponsesToInter imPaymentR equest/>
</InterimPayment>
<StatementOfTruth/>
<Phase2ClaimantDefendantDa tes>
<ClaimantRepresentativeDat es/>
<DefendantRepresentativeDa tes/>
</Phase2ClaimantDefendantD ates>
</InterimSettlementPack>
<Stage2SettlementPack>
<ClaimantRepresentative>
<CompanyDetails CompanyName="Morgan Cole" ContactName="a" ContactSurname="a" ReferenceNumber="a" TelephoneNumber="020089182 73645">
<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/>
<Phase2ClaimantDefendantDa tes>
<ClaimantRepresentativeDat es/>
<DefendantRepresentativeDa tes/>
</Phase2ClaimantDefendantD ates>
</Stage2SettlementPack>
<CourtProceedingsPack>
<ClaimantRepresentative>
<CompanyDetails CompanyName="Morgan Cole" ContactName="a" ContactSurname="a" ReferenceNumber="a" TelephoneNumber="020089182 73645">
<Address AddressType="A"/>
</CompanyDetails>
</ClaimantRepresentative>
<DefendantRepresentative>
<DefendantsInsurer/>
</DefendantRepresentative>
<LossesToDate>
<ClaimantLosses/>
<DefendantReplies/>
</LossesToDate>
<CourtProceedingsPackPartA />
<DisbursmentDisputed/>
<CourtProceedingsPackPartB > <FixedCosts/> </CourtProceedingsPackPart B>
<StatementOfTruth/>
<Phase2ClaimantDefendantDa tes>
<ClaimantRepresentativeDat es/>
<DefendantRepresentativeDa tes/>
</Phase2ClaimantDefendantD ates>
</CourtProceedingsPack>
<Timeouts>
<CurrentTimeout TimeOutType="" SelectedTimeOut="2010-05-0 7"/>
<PreCalculatedTimeouts>
<ClaimNotificationForm>
<Insurer LiabilityDecisionTimeout=" " Stage1PaymentTimeout=""/>
<MIBorArt75 LiabilityDecisionTimeout=" " Stage1PaymentTimeout=""/>
</ClaimNotificationForm>
<InterimSettlementPack>
<LowPayment InterimPaymentTimeout=""/>
<HighPayment InterimPaymentTimeout=""/>
</InterimSettlementPack>
<Stage2SettlementPack>
<Stage2DecisionOrCounterOf fer Stage2DecisionOrCounterOff erTimeout= ""/>
</Stage2SettlementPack>
<CourtProceedingsPack>
<CourtProceedings CourtProceedingsTimeout="" />
</CourtProceedingsPack>
</PreCalculatedTimeouts>
</Timeouts>
</Data>
This is the relevant part of my script:
open(NEWFILE, '>C:\Perl\getHospitalsList \SendWaiti ng_Directo ry\GetClai m\Received \NewGetCla imData_Rec eived.xml' ) or die $!;
my $secondfile= '\\\ITL019\SendWaiting_Dir ectory\Get Claim\Rece ived\TestG etClaimDat a_Received .xml';
my $secondparser = new XML::DOM::Parser;
my $seconddoc = $secondparser->parsefile($ secondfile );
my $testvar=$seconddoc->getEl ementsByTa gName('Def endantDeta ils')->ite m(0)->getF irstChild- >getNodeVa lue;
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?
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"
<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="020089182
</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="COM
<CompanyDetails>
<Address AddressType="A"/>
</CompanyDetails>
</DefendantDetails>
<ClaimantDetails ChildClaim="0" NationalInsuranceNumber="N
</ClaimAndClaimantDetails>
<MedicalDetails>
<Injury BoneInjury="0" HospitalAttendance="0" InjurySustainedDescription
<Rehabilitation RehabilitationNeeds="0" RehabilitationUndertaken="
<HospitalSearch/>
</MedicalDetails>
<RepairsAndAlternativeVehi
<Repairs ClaiimingDamageOwnVehicle=
<AlternativeCompany/>
</Repairs>
<AlternativeVehicleProvisi
<Provider>
<Vehicle/>
</Provider>
</AlternativeVehicleProvis
</RepairsAndAlternativeVeh
<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/> <InsuranceCompanyInformati
<BusCoach BussOrCoach="0"/>
</AccidentData>
<OtherPartyDetails/>
<LiabilityFunding>
<Liability DefendantResponsability="v
<Funding FundingUndertaken="0"/>
</LiabilityFunding>
<InsurerResponse>
<LiabilityCausation> <DefendantAdmits/> </LiabilityCausation>
<ProvidedServices NotificationDate="2010-04-
</InsurerResponse>
<InterimSettlementPack>
<ClaimantRepresentative PaymentMoreRequested="">
<CompanyDetails CompanyName="Morgan Cole" ContactName="a" ContactSurname="a" ReferenceNumber="a" TelephoneNumber="020089182
<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> <ClaimantRequestForInterim
</InterimPayment>
<StatementOfTruth/>
<Phase2ClaimantDefendantDa
<ClaimantRepresentativeDat
<DefendantRepresentativeDa
</Phase2ClaimantDefendantD
</InterimSettlementPack>
<Stage2SettlementPack>
<ClaimantRepresentative>
<CompanyDetails CompanyName="Morgan Cole" ContactName="a" ContactSurname="a" ReferenceNumber="a" TelephoneNumber="020089182
<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/>
<Phase2ClaimantDefendantDa
<ClaimantRepresentativeDat
<DefendantRepresentativeDa
</Phase2ClaimantDefendantD
</Stage2SettlementPack>
<CourtProceedingsPack>
<ClaimantRepresentative>
<CompanyDetails CompanyName="Morgan Cole" ContactName="a" ContactSurname="a" ReferenceNumber="a" TelephoneNumber="020089182
<Address AddressType="A"/>
</CompanyDetails>
</ClaimantRepresentative>
<DefendantRepresentative>
<DefendantsInsurer/>
</DefendantRepresentative>
<LossesToDate>
<ClaimantLosses/>
<DefendantReplies/>
</LossesToDate>
<CourtProceedingsPackPartA
<DisbursmentDisputed/>
<CourtProceedingsPackPartB
<StatementOfTruth/>
<Phase2ClaimantDefendantDa
<ClaimantRepresentativeDat
<DefendantRepresentativeDa
</Phase2ClaimantDefendantD
</CourtProceedingsPack>
<Timeouts>
<CurrentTimeout TimeOutType="" SelectedTimeOut="2010-05-0
<PreCalculatedTimeouts>
<ClaimNotificationForm>
<Insurer LiabilityDecisionTimeout="
<MIBorArt75 LiabilityDecisionTimeout="
</ClaimNotificationForm>
<InterimSettlementPack>
<LowPayment InterimPaymentTimeout=""/>
<HighPayment InterimPaymentTimeout=""/>
</InterimSettlementPack>
<Stage2SettlementPack>
<Stage2DecisionOrCounterOf
</Stage2SettlementPack>
<CourtProceedingsPack>
<CourtProceedings CourtProceedingsTimeout=""
</CourtProceedingsPack>
</PreCalculatedTimeouts>
</Timeouts>
</Data>
This is the relevant part of my script:
open(NEWFILE, '>C:\Perl\getHospitalsList
my $secondfile= '\\\ITL019\SendWaiting_Dir
my $secondparser = new XML::DOM::Parser;
my $seconddoc = $secondparser->parsefile($
my $testvar=$seconddoc->getEl
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.