Re: how to load uneven XML file into an array
| From: | Dan Joseph | Date: | Fri, 27 Jun 2008 16:52:14 +0000 |
| Subject: | Re: how to load uneven XML file into an array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-276071@lists.php.net to get a copy of this message | ||
On Fri, Jun 27, 2008 at 12:34 PM, John A DAVIS <John.A.Davis@state.or.us>
wrote:
> I need an array filled with an XML file made from the CSV example below.
> bactisample row has 14 "columns"
> bactiresult row has 11 "columns"
> CSV is taken and run through an XML creator (we have no control over this
> piece).
>
> bactisample,20802016AA,OR4195079,DIST-A,A,STATE,OR100033,Kitchen
> Sink,RT,,,TC,Y,06202008
> bactisample,20802017AA,OR4101020,DIST-A,A,STATE,OR100033,Mobile SP#
> 8,RT,,,TC,Y,06202008
> bactisample,20802018AA,OR4100341,DIST-A,A,STATE,OR100033,Well
> Tap,RT,,,TC,Y,06202008
> bactisample,20802019AA,OR4100350,DIST-A,A,STATE,OR100033,Well
> Tap,RT,,,TC,Y,06202008
> bactisample,20802024AA,OR4100342,DIST-A,A,STATE,OR100033,2137 SW Mendi
> Way,RT,,0.64,TC,Y,06202008
>
> bactiresult,20802016AA,06202008,OR4195079,STATE,OR100033,3100,06232008,A,COLILERT,A
>
> bactiresult,20802017AA,06202008,OR4101020,STATE,OR100033,3100,06232008,A,COLILERT,A
>
> bactiresult,20802018AA,06202008,OR4100341,STATE,OR100033,3100,06232008,A,COLILERT,A
>
> bactiresult,20802019AA,06202008,OR4100350,STATE,OR100033,3100,06232008,A,COLILERT,A
>
> bactiresult,20802024AA,06202008,OR4100342,STATE,OR100033,3100,06232008,A,9222B,A
>
> Here is the XML file. I am going to paste the whole thing and hope it
> doesn't slow down the internet too much.
> Any insites on how to parse this file with PHP into some sort of "loop" we
> can use to validate every item would be very helpful.
> <?xml version="1.0" encoding="UTF-8"?>
> <EN:eDWR xmlns:EN="urn:us:net:exchangenetwork"
> xmlns:SDWIS="http://www.epa.gov/sdwis"
> xmlns:ns3="http://www.epa.gov/xml"
> xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance">
> <EN:Submission EN:submissionFileCreatedDate="2008-06-23"
> EN:submissionFileName="CSV_06-23-2008_1_35_53PM.csv"
> EN:submissionID="53">
> <EN:LabReport>
> <EN:LabIdentification>
> <EN:LabAccreditation>
>
> <EN:LabAccreditationIdentifier>OR100033</EN:LabAccreditationIdentifier>
>
> <EN:LabAccreditationAuthorityName>STATE</EN:LabAccreditationAuthorityName>
> </EN:LabAccreditation>
> </EN:LabIdentification>
> <EN:Sample>
> <EN:SampleIdentification>
>
> <EN:LabSampleIdentifier>20802016AA</EN:LabSampleIdentifier>
> <EN:PWSIdentifier>OR4195079</EN:PWSIdentifier>
>
> <EN:PWSFacilityIdentifier>DIST-A</EN:PWSFacilityIdentifier>
> <EN:SampleRuleCode>TC</EN:SampleRuleCode>
>
> <EN:SampleMonitoringTypeCode>RT</EN:SampleMonitoringTypeCode>
>
> <EN:ComplianceSampleIndicator>Y</EN:ComplianceSampleIndicator>
>
> <EN:SampleCollectionEndDate>2008-06-20</EN:SampleCollectionEndDate>
> <EN:SampleComments>
> <EN:Comments>Kitchen Sink</EN:Comments>
> </EN:SampleComments>
> </EN:SampleIdentification>
> <EN:SampleLocationIdentification>
>
> <EN:SampleLocationIdentifier>A</EN:SampleLocationIdentifier>
> </EN:SampleLocationIdentification>
> </EN:Sample>
> <EN:Sample>
> <EN:SampleIdentification>
>
> <EN:LabSampleIdentifier>20802017AA</EN:LabSampleIdentifier>
> <EN:PWSIdentifier>OR4101020</EN:PWSIdentifier>
>
> <EN:PWSFacilityIdentifier>DIST-A</EN:PWSFacilityIdentifier>
> <EN:SampleRuleCode>TC</EN:SampleRuleCode>
>
> <EN:SampleMonitoringTypeCode>RT</EN:SampleMonitoringTypeCode>
>
> <EN:ComplianceSampleIndicator>Y</EN:ComplianceSampleIndicator>
>
> <EN:SampleCollectionEndDate>2008-06-20</EN:SampleCollectionEndDate>
> <EN:SampleComments>
> <EN:Comments>Mobile SP# 8</EN:Comments>
> </EN:SampleComments>
> </EN:SampleIdentification>
> <EN:SampleLocationIdentification>
>
> <EN:SampleLocationIdentifier>A</EN:SampleLocationIdentifier>
> </EN:SampleLocationIdentification>
> </EN:Sample>
> <EN:Sample>
> <EN:SampleIdentification>
>
> <EN:LabSampleIdentifier>20802018AA</EN:LabSampleIdentifier>
> <EN:PWSIdentifier>OR4100341</EN:PWSIdentifier>
>
> <EN:PWSFacilityIdentifier>DIST-A</EN:PWSFacilityIdentifier>
> <EN:SampleRuleCode>TC</EN:SampleRuleCode>
>
> <EN:SampleMonitoringTypeCode>RT</EN:SampleMonitoringTypeCode>
>
> <EN:ComplianceSampleIndicator>Y</EN:ComplianceSampleIndicator>
>
> <EN:SampleCollectionEndDate>2008-06-20</EN:SampleCollectionEndDate>
> <EN:SampleComments>
> <EN:Comments>Well Tap</EN:Comments>
> </EN:SampleComments>
> </EN:SampleIdentification>
> <EN:SampleLocationIdentification>
>
> <EN:SampleLocationIdentifier>A</EN:SampleLocationIdentifier>
> </EN:SampleLocationIdentification>
> </EN:Sample>
> <EN:Sample>
> <EN:SampleIdentification>
>
> <EN:LabSampleIdentifier>20802019AA</EN:LabSampleIdentifier>
> <EN:PWSIdentifier>OR4100350</EN:PWSIdentifier>
>
> <EN:PWSFacilityIdentifier>DIST-A</EN:PWSFacilityIdentifier>
> <EN:SampleRuleCode>TC</EN:SampleRuleCode>
>
> <EN:SampleMonitoringTypeCode>RT</EN:SampleMonitoringTypeCode>
>
> <EN:ComplianceSampleIndicator>Y</EN:ComplianceSampleIndicator>
>
> <EN:SampleCollectionEndDate>2008-06-20</EN:SampleCollectionEndDate>
> <EN:SampleComments>
> <EN:Comments>Well Tap</EN:Comments>
> </EN:SampleComments>
> </EN:SampleIdentification>
> <EN:SampleLocationIdentification>
>
> <EN:SampleLocationIdentifier>A</EN:SampleLocationIdentifier>
> </EN:SampleLocationIdentification>
> </EN:Sample>
> <EN:Sample>
> <EN:SampleIdentification>
>
> <EN:LabSampleIdentifier>20802024AA</EN:LabSampleIdentifier>
> <EN:PWSIdentifier>OR4100342</EN:PWSIdentifier>
>
> <EN:PWSFacilityIdentifier>DIST-A</EN:PWSFacilityIdentifier>
> <EN:SampleRuleCode>TC</EN:SampleRuleCode>
>
> <EN:SampleMonitoringTypeCode>RT</EN:SampleMonitoringTypeCode>
>
> <EN:ComplianceSampleIndicator>Y</EN:ComplianceSampleIndicator>
>
> <EN:SampleCollectionEndDate>2008-06-20</EN:SampleCollectionEndDate>
> <EN:SpecializedMeasurement>
> <EN:MeasurementValue>0.64</EN:MeasurementValue>
>
> <EN:MeasurementSignificantDigit>2</EN:MeasurementSignificantDigit>
>
>
> <EN:SpecializedMeasurementTypeCode>FreeChlorineResidual</EN:SpecializedMeasurementTypeCode>
> </EN:SpecializedMeasurement>
> <EN:SampleComments>
> <EN:Comments>2137 SW Mendi Way</EN:Comments>
> </EN:SampleComments>
> </EN:SampleIdentification>
> <EN:SampleLocationIdentification>
>
> <EN:SampleLocationIdentifier>A</EN:SampleLocationIdentifier>
> </EN:SampleLocationIdentification>
> </EN:Sample>
> <EN:SampleAnalysisResults>
> <EN:LabSampleIdentifier>20802016AA</EN:LabSampleIdentifier>
> <EN:PWSIdentifier>OR4195079</EN:PWSIdentifier>
>
> <EN:SampleCollectionEndDate>2008-06-20</EN:SampleCollectionEndDate>
> <EN:LabAnalysisIdentification>
> <EN:LabAccreditation>
>
> <EN:LabAccreditationIdentifier>OR100033</EN:LabAccreditationIdentifier>
>
> <EN:LabAccreditationAuthorityName>STATE</EN:LabAccreditationAuthorityName>
> </EN:LabAccreditation>
> <EN:SampleAnalyticalMethod>
> <EN:MethodIdentifier>COLILERT</EN:MethodIdentifier>
> </EN:SampleAnalyticalMethod>
> </EN:LabAnalysisIdentification>
> <EN:AnalyteIdentification>
> <EN:AnalyteCode>3100</EN:AnalyteCode>
> </EN:AnalyteIdentification>
> <EN:AnalysisResult>
> <EN:Result>
> <EN:MeasurementQualifier>A</EN:MeasurementQualifier>
> </EN:Result>
>
> <EN:ResultStateNotificationDate>2008-06-23</EN:ResultStateNotificationDate>
> </EN:AnalysisResult>
> <EN:QAQCSummary>
> <EN:DataQualityCode>A</EN:DataQualityCode>
> </EN:QAQCSummary>
> </EN:SampleAnalysisResults>
> <EN:SampleAnalysisResults>
> <EN:LabSampleIdentifier>20802017AA</EN:LabSampleIdentifier>
> <EN:PWSIdentifier>OR4101020</EN:PWSIdentifier>
>
> <EN:SampleCollectionEndDate>2008-06-20</EN:SampleCollectionEndDate>
> <EN:LabAnalysisIdentification>
> <EN:LabAccreditation>
>
> <EN:LabAccreditationIdentifier>OR100033</EN:LabAccreditationIdentifier>
>
> <EN:LabAccreditationAuthorityName>STATE</EN:LabAccreditationAuthorityName>
> </EN:LabAccreditation>
> <EN:SampleAnalyticalMethod>
> <EN:MethodIdentifier>COLILERT</EN:MethodIdentifier>
> </EN:SampleAnalyticalMethod>
> </EN:LabAnalysisIdentification>
> <EN:AnalyteIdentification>
> <EN:AnalyteCode>3100</EN:AnalyteCode>
> </EN:AnalyteIdentification>
> <EN:AnalysisResult>
> <EN:Result>
> <EN:MeasurementQualifier>A</EN:MeasurementQualifier>
> </EN:Result>
>
> <EN:ResultStateNotificationDate>2008-06-23</EN:ResultStateNotificationDate>
> </EN:AnalysisResult>
> <EN:QAQCSummary>
> <EN:DataQualityCode>A</EN:DataQualityCode>
> </EN:QAQCSummary>
> </EN:SampleAnalysisResults>
> <EN:SampleAnalysisResults>
> <EN:LabSampleIdentifier>20802018AA</EN:LabSampleIdentifier>
> <EN:PWSIdentifier>OR4100341</EN:PWSIdentifier>
>
> <EN:SampleCollectionEndDate>2008-06-20</EN:SampleCollectionEndDate>
> <EN:LabAnalysisIdentification>
> <EN:LabAccreditation>
>
> <EN:LabAccreditationIdentifier>OR100033</EN:LabAccreditationIdentifier>
>
> <EN:LabAccreditationAuthorityName>STATE</EN:LabAccreditationAuthorityName>
> </EN:LabAccreditation>
> <EN:SampleAnalyticalMethod>
> <EN:MethodIdentifier>COLILERT</EN:MethodIdentifier>
> </EN:SampleAnalyticalMethod>
> </EN:LabAnalysisIdentification>
> <EN:AnalyteIdentification>
> <EN:AnalyteCode>3100</EN:AnalyteCode>
> </EN:AnalyteIdentification>
> <EN:AnalysisResult>
> <EN:Result>
> <EN:MeasurementQualifier>A</EN:MeasurementQualifier>
> </EN:Result>
>
> <EN:ResultStateNotificationDate>2008-06-23</EN:ResultStateNotificationDate>
> </EN:AnalysisResult>
> <EN:QAQCSummary>
> <EN:DataQualityCode>A</EN:DataQualityCode>
> </EN:QAQCSummary>
> </EN:SampleAnalysisResults>
> <EN:SampleAnalysisResults>
> <EN:LabSampleIdentifier>20802019AA</EN:LabSampleIdentifier>
> <EN:PWSIdentifier>OR4100350</EN:PWSIdentifier>
>
> <EN:SampleCollectionEndDate>2008-06-20</EN:SampleCollectionEndDate>
> <EN:LabAnalysisIdentification>
> <EN:LabAccreditation>
>
> <EN:LabAccreditationIdentifier>OR100033</EN:LabAccreditationIdentifier>
>
> <EN:LabAccreditationAuthorityName>STATE</EN:LabAccreditationAuthorityName>
> </EN:LabAccreditation>
> <EN:SampleAnalyticalMethod>
> <EN:MethodIdentifier>COLILERT</EN:MethodIdentifier>
> </EN:SampleAnalyticalMethod>
> </EN:LabAnalysisIdentification>
> <EN:AnalyteIdentification>
> <EN:AnalyteCode>3100</EN:AnalyteCode>
> </EN:AnalyteIdentification>
> <EN:AnalysisResult>
> <EN:Result>
> <EN:MeasurementQualifier>A</EN:MeasurementQualifier>
> </EN:Result>
>
> <EN:ResultStateNotificationDate>2008-06-23</EN:ResultStateNotificationDate>
> </EN:AnalysisResult>
> <EN:QAQCSummary>
> <EN:DataQualityCode>A</EN:DataQualityCode>
> </EN:QAQCSummary>
> </EN:SampleAnalysisResults>
> <EN:SampleAnalysisResults>
> <EN:LabSampleIdentifier>20802024AA</EN:LabSampleIdentifier>
> <EN:PWSIdentifier>OR4100342</EN:PWSIdentifier>
>
> <EN:SampleCollectionEndDate>2008-06-20</EN:SampleCollectionEndDate>
> <EN:LabAnalysisIdentification>
> <EN:LabAccreditation>
>
> <EN:LabAccreditationIdentifier>OR100033</EN:LabAccreditationIdentifier>
>
> <EN:LabAccreditationAuthorityName>STATE</EN:LabAccreditationAuthorityName>
> </EN:LabAccreditation>
> <EN:SampleAnalyticalMethod>
> <EN:MethodIdentifier>9222B</EN:MethodIdentifier>
> </EN:SampleAnalyticalMethod>
> </EN:LabAnalysisIdentification>
> <EN:AnalyteIdentification>
> <EN:AnalyteCode>3100</EN:AnalyteCode>
> </EN:AnalyteIdentification>
> <EN:AnalysisResult>
> <EN:Result>
> <EN:MeasurementQualifier>A</EN:MeasurementQualifier>
> </EN:Result>
>
> <EN:ResultStateNotificationDate>2008-06-23</EN:ResultStateNotificationDate>
> </EN:AnalysisResult>
> <EN:QAQCSummary>
> <EN:DataQualityCode>A</EN:DataQualityCode>
> </EN:QAQCSummary>
> </EN:SampleAnalysisResults>
> </EN:LabReport>
> <EN:SubmissionCertification>
> <EN:CertificationIdentifier>53</EN:CertificationIdentifier>
> <EN:CertifierName>user1</EN:CertifierName>
> <EN:CertificationDate>2008-06-23T01:42:24</EN:CertificationDate>
>
>
> <EN:CertifiedPhysicalFileName>C:\labtostate\docBase\jobFolders\2008-06-23.13-42-05-421.70772\eDWR.xml</EN:CertifiedPhysicalFileName>
> </EN:SubmissionCertification>
> </EN:Submission>
> </EN:eDWR>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Have a look at SimpleXML. http://us3.php.net/simplexml
That should put it in an easy to work with format, then you can just foreach
thru it.
--
-Dan Joseph
www.canishosting.com - Plans start @ $1.99/month.
"Build a man a fire, and he will be warm for the rest of the day.
Light a man on fire, and will be warm for the rest of his life."