How to get the xml data in the form of array using php [duplicate]











up vote
-1
down vote

favorite













This question already has an answer here:




  • How do you parse and process HTML/XML in PHP?

    29 answers




I want to get the values of the XML below, which has time sheet details like XConsultant, personid, TimeSheet.WeekEnd , TimeRecord.WeekEnd and so on. I had tried with:



$fileData = simplexml_load_file($fileName);//where file name is the destination of my file url ..


When I am trying to load and print the array, it's only printing the timesheet details. I want to access the personid and [TimeSheet].[WeekEnd]



SimpleXMLElement Object
(
[@attributes] => Array
(
[weekdayStart] => Monday
)

[0] => 10/29/2018
)
SimpleXMLElement Object
(
[@attributes] => Array
(
[weekdayEnd] => Sunday
)

[0] => 11/04/2018
)
SimpleXMLElement Object
(
[@attributes] => Array
(
[weekdayStatement] => Wednesday
)

[0] => 11/07/2018
)
SimpleXMLElement Object
(
[@attributes] => Array
(
[weekdayLastRun] => Saturday
)

[0] => 10/29/2018
)
SimpleXMLElement Object
(
[0] => 11/07/2018 00:51:43
)
SimpleXMLElement Object
(
[XConsultant] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 27189
)

[ClientXrefNbr1] => SimpleXMLElement Object
(
)

[PersonID] => 24799
[PersonCode] => DHinkle12345
[Email] => test1@gmail.com
[FirstName] => David
[MiddleInitial] => SimpleXMLElement Object
(
)

[LastName] => hennry
[VendorXRefNbr1] => SimpleXMLElement Object
(
)

[VendorXRefNbr2] => SimpleXMLElement Object
(
)
)

[TimeSheet] => SimpleXMLElement Object
(
[@attributes] => Array
(
[WeekEnd] => 10/28/2018
[WeekBegin] => 10/22/2018
)

[ApprovalHistory] => SimpleXMLElement Object
(
[Activity] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[status] => SUBMITTED
[datetime] => 10/26/2018 7:30PM
[person] => David hennry
[role] => TimeSheetUser
[comment] =>
)
)

[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[status] => COMPLETED
[datetime] => 10/29/2018 11:56AM
[person] => David hennry
[role] => TimeSheetUser
[comment] =>
)
)

[2] => SimpleXMLElement Object
(
[@attributes] => Array
(
[status] => LOCKED
[datetime] => 11/01/2018 5:05AM
[person] => David hennry
[role] => TimeSheetUser
[comment] => Locked By System [4667]
)
)
)
)

[TimeRecord] => Array
(
[0] => 8.0000
[1] => 8.0000
[2] => 8.0000
[3] => 8.0000
[4] => 8.0000
)
)

)
SimpleXMLElement Object
(
[XConsultant] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 32971
)

[ClientXrefNbr1] => SimpleXMLElement Object
(
)

[PersonID] => 30305
[PersonCode] => mailk123
[Email] => test2@yahoo.com
[FirstName] => mailk
[MiddleInitial] => SimpleXMLElement Object
(
)

[LastName] => tom
[VendorXRefNbr1] => SimpleXMLElement Object
(
)

[VendorXRefNbr2] => SimpleXMLElement Object
(
)

)

[TimeSheet] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[WeekEnd] => 10/28/2018
[WeekBegin] => 10/22/2018
)

[ApprovalHistory] => SimpleXMLElement Object
(
[Activity] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[status] => SUBMITTED
[datetime] => 10/27/2018 10:45AM
[person] => mailk tom
[role] => TimeSheetUser
[comment] =>
)
)

[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[status] => COMPLETED
[datetime] => 10/30/2018 12:20PM
[person] => mailk tom
[role] => TimeSheetUser
[comment] =>
)
)

[2] => SimpleXMLElement Object
(
[@attributes] => Array
(
[status] => LOCKED
[datetime] => 11/01/2018 5:05AM
[person] => mailk tom
[role] => TimeSheetUser
[comment] => Locked By System [4667]
)
)
)
)

[TimeRecord] => Array
(
[0] => 8.0000
[1] => 8.0000
[2] => 8.0000
[3] => 8.0000
)
)

[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[WeekEnd] => 11/04/2018
[WeekBegin] => 10/29/2018
)

[ApprovalHistory] => SimpleXMLElement Object
(
[Activity] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[status] => SUBMITTED
[datetime] => 11/02/2018 7:46PM
[person] => mailk tom
[role] => TimeSheetUser
[comment] =>
)
)

[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[status] => COMPLETED
[datetime] => 11/05/2018 11:01AM
[person] => mailk tom
[role] => TimeSheetUser
[comment] =>
)
)
)
)
[TimeRecord] => Array
(
[0] => 8.0000
[1] => 8.0000
[2] => 8.0000
[3] => 7.7500
[4] => 8.0000
)
)
)
)


I used foreach and associative array key condition also, but I am unable to fetch the records. Where is <ConsultantTime>? I have many consult time data where I need to have foreach loop </ConsultantTime>. Any help would be appreciated.



Thanks in advance.






<TimeSheets><TimePeriod><Start weekdayStart="Monday" xmlns="">10/29/2018</Start><End weekdayEnd="Sunday" xmlns="">11/04/2018</End><StatementDate weekdayStatement="Wednesday" xmlns="">11/07/2018</StatementDate><LastRunDate weekdayLastRun="Saturday" xmlns="">12/28/2018</LastRunDate><SystemDate xmlns="">11/07/2018 00:51:43</SystemDate></TimePeriod><Client organization="abc">abc</Client><Supplier organization="fsdf, Inc." name="fsdf, Inc.">fsdf, Inc.

<ConsultantTime>
<XConsultant id="27189"><ClientXrefNbr1></ClientXrefNbr1><PersonID>24799</PersonID><PersonCode>DHinkle12345</PersonCode><Email>test1@gmail.com</Email><FirstName>David</FirstName><MiddleInitial></MiddleInitial><LastName>hennry</LastName><VendorXRefNbr1></VendorXRefNbr1><VendorXRefNbr2></VendorXRefNbr2></XConsultant>
<TimeSheet WeekEnd="10/28/2018" WeekBegin="10/22/2018">
<ApprovalHistory><Activity status="SUBMITTED" datetime="10/26/2018 7:30PM" person="David hennry" role="TimeSheetUser" comment="" /><Activity status="COMPLETED" datetime="10/29/2018 11:56AM" person="David hennry" role="TimeSheetUser" comment="" /><Activity status="LOCKED" datetime="11/01/2018 5:05AM" person="David hennry" role="TimeSheetUser" comment="Locked By System [4667]" /></ApprovalHistory>
<TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/22/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
<TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/23/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
<TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/24/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
<TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/25/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
<TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/26/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
</TimeSheet>
</ConsultantTime>

</Supplier></TimeSheets>












share|improve this question















marked as duplicate by gsamaras, IMSoP php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 9 at 10:13


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















    up vote
    -1
    down vote

    favorite













    This question already has an answer here:




    • How do you parse and process HTML/XML in PHP?

      29 answers




    I want to get the values of the XML below, which has time sheet details like XConsultant, personid, TimeSheet.WeekEnd , TimeRecord.WeekEnd and so on. I had tried with:



    $fileData = simplexml_load_file($fileName);//where file name is the destination of my file url ..


    When I am trying to load and print the array, it's only printing the timesheet details. I want to access the personid and [TimeSheet].[WeekEnd]



    SimpleXMLElement Object
    (
    [@attributes] => Array
    (
    [weekdayStart] => Monday
    )

    [0] => 10/29/2018
    )
    SimpleXMLElement Object
    (
    [@attributes] => Array
    (
    [weekdayEnd] => Sunday
    )

    [0] => 11/04/2018
    )
    SimpleXMLElement Object
    (
    [@attributes] => Array
    (
    [weekdayStatement] => Wednesday
    )

    [0] => 11/07/2018
    )
    SimpleXMLElement Object
    (
    [@attributes] => Array
    (
    [weekdayLastRun] => Saturday
    )

    [0] => 10/29/2018
    )
    SimpleXMLElement Object
    (
    [0] => 11/07/2018 00:51:43
    )
    SimpleXMLElement Object
    (
    [XConsultant] => SimpleXMLElement Object
    (
    [@attributes] => Array
    (
    [id] => 27189
    )

    [ClientXrefNbr1] => SimpleXMLElement Object
    (
    )

    [PersonID] => 24799
    [PersonCode] => DHinkle12345
    [Email] => test1@gmail.com
    [FirstName] => David
    [MiddleInitial] => SimpleXMLElement Object
    (
    )

    [LastName] => hennry
    [VendorXRefNbr1] => SimpleXMLElement Object
    (
    )

    [VendorXRefNbr2] => SimpleXMLElement Object
    (
    )
    )

    [TimeSheet] => SimpleXMLElement Object
    (
    [@attributes] => Array
    (
    [WeekEnd] => 10/28/2018
    [WeekBegin] => 10/22/2018
    )

    [ApprovalHistory] => SimpleXMLElement Object
    (
    [Activity] => Array
    (
    [0] => SimpleXMLElement Object
    (
    [@attributes] => Array
    (
    [status] => SUBMITTED
    [datetime] => 10/26/2018 7:30PM
    [person] => David hennry
    [role] => TimeSheetUser
    [comment] =>
    )
    )

    [1] => SimpleXMLElement Object
    (
    [@attributes] => Array
    (
    [status] => COMPLETED
    [datetime] => 10/29/2018 11:56AM
    [person] => David hennry
    [role] => TimeSheetUser
    [comment] =>
    )
    )

    [2] => SimpleXMLElement Object
    (
    [@attributes] => Array
    (
    [status] => LOCKED
    [datetime] => 11/01/2018 5:05AM
    [person] => David hennry
    [role] => TimeSheetUser
    [comment] => Locked By System [4667]
    )
    )
    )
    )

    [TimeRecord] => Array
    (
    [0] => 8.0000
    [1] => 8.0000
    [2] => 8.0000
    [3] => 8.0000
    [4] => 8.0000
    )
    )

    )
    SimpleXMLElement Object
    (
    [XConsultant] => SimpleXMLElement Object
    (
    [@attributes] => Array
    (
    [id] => 32971
    )

    [ClientXrefNbr1] => SimpleXMLElement Object
    (
    )

    [PersonID] => 30305
    [PersonCode] => mailk123
    [Email] => test2@yahoo.com
    [FirstName] => mailk
    [MiddleInitial] => SimpleXMLElement Object
    (
    )

    [LastName] => tom
    [VendorXRefNbr1] => SimpleXMLElement Object
    (
    )

    [VendorXRefNbr2] => SimpleXMLElement Object
    (
    )

    )

    [TimeSheet] => Array
    (
    [0] => SimpleXMLElement Object
    (
    [@attributes] => Array
    (
    [WeekEnd] => 10/28/2018
    [WeekBegin] => 10/22/2018
    )

    [ApprovalHistory] => SimpleXMLElement Object
    (
    [Activity] => Array
    (
    [0] => SimpleXMLElement Object
    (
    [@attributes] => Array
    (
    [status] => SUBMITTED
    [datetime] => 10/27/2018 10:45AM
    [person] => mailk tom
    [role] => TimeSheetUser
    [comment] =>
    )
    )

    [1] => SimpleXMLElement Object
    (
    [@attributes] => Array
    (
    [status] => COMPLETED
    [datetime] => 10/30/2018 12:20PM
    [person] => mailk tom
    [role] => TimeSheetUser
    [comment] =>
    )
    )

    [2] => SimpleXMLElement Object
    (
    [@attributes] => Array
    (
    [status] => LOCKED
    [datetime] => 11/01/2018 5:05AM
    [person] => mailk tom
    [role] => TimeSheetUser
    [comment] => Locked By System [4667]
    )
    )
    )
    )

    [TimeRecord] => Array
    (
    [0] => 8.0000
    [1] => 8.0000
    [2] => 8.0000
    [3] => 8.0000
    )
    )

    [1] => SimpleXMLElement Object
    (
    [@attributes] => Array
    (
    [WeekEnd] => 11/04/2018
    [WeekBegin] => 10/29/2018
    )

    [ApprovalHistory] => SimpleXMLElement Object
    (
    [Activity] => Array
    (
    [0] => SimpleXMLElement Object
    (
    [@attributes] => Array
    (
    [status] => SUBMITTED
    [datetime] => 11/02/2018 7:46PM
    [person] => mailk tom
    [role] => TimeSheetUser
    [comment] =>
    )
    )

    [1] => SimpleXMLElement Object
    (
    [@attributes] => Array
    (
    [status] => COMPLETED
    [datetime] => 11/05/2018 11:01AM
    [person] => mailk tom
    [role] => TimeSheetUser
    [comment] =>
    )
    )
    )
    )
    [TimeRecord] => Array
    (
    [0] => 8.0000
    [1] => 8.0000
    [2] => 8.0000
    [3] => 7.7500
    [4] => 8.0000
    )
    )
    )
    )


    I used foreach and associative array key condition also, but I am unable to fetch the records. Where is <ConsultantTime>? I have many consult time data where I need to have foreach loop </ConsultantTime>. Any help would be appreciated.



    Thanks in advance.






    <TimeSheets><TimePeriod><Start weekdayStart="Monday" xmlns="">10/29/2018</Start><End weekdayEnd="Sunday" xmlns="">11/04/2018</End><StatementDate weekdayStatement="Wednesday" xmlns="">11/07/2018</StatementDate><LastRunDate weekdayLastRun="Saturday" xmlns="">12/28/2018</LastRunDate><SystemDate xmlns="">11/07/2018 00:51:43</SystemDate></TimePeriod><Client organization="abc">abc</Client><Supplier organization="fsdf, Inc." name="fsdf, Inc.">fsdf, Inc.

    <ConsultantTime>
    <XConsultant id="27189"><ClientXrefNbr1></ClientXrefNbr1><PersonID>24799</PersonID><PersonCode>DHinkle12345</PersonCode><Email>test1@gmail.com</Email><FirstName>David</FirstName><MiddleInitial></MiddleInitial><LastName>hennry</LastName><VendorXRefNbr1></VendorXRefNbr1><VendorXRefNbr2></VendorXRefNbr2></XConsultant>
    <TimeSheet WeekEnd="10/28/2018" WeekBegin="10/22/2018">
    <ApprovalHistory><Activity status="SUBMITTED" datetime="10/26/2018 7:30PM" person="David hennry" role="TimeSheetUser" comment="" /><Activity status="COMPLETED" datetime="10/29/2018 11:56AM" person="David hennry" role="TimeSheetUser" comment="" /><Activity status="LOCKED" datetime="11/01/2018 5:05AM" person="David hennry" role="TimeSheetUser" comment="Locked By System [4667]" /></ApprovalHistory>
    <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/22/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
    <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/23/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
    <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/24/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
    <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/25/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
    <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/26/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
    </TimeSheet>
    </ConsultantTime>

    </Supplier></TimeSheets>












    share|improve this question















    marked as duplicate by gsamaras, IMSoP php
    Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Nov 9 at 10:13


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

















      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite












      This question already has an answer here:




      • How do you parse and process HTML/XML in PHP?

        29 answers




      I want to get the values of the XML below, which has time sheet details like XConsultant, personid, TimeSheet.WeekEnd , TimeRecord.WeekEnd and so on. I had tried with:



      $fileData = simplexml_load_file($fileName);//where file name is the destination of my file url ..


      When I am trying to load and print the array, it's only printing the timesheet details. I want to access the personid and [TimeSheet].[WeekEnd]



      SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [weekdayStart] => Monday
      )

      [0] => 10/29/2018
      )
      SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [weekdayEnd] => Sunday
      )

      [0] => 11/04/2018
      )
      SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [weekdayStatement] => Wednesday
      )

      [0] => 11/07/2018
      )
      SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [weekdayLastRun] => Saturday
      )

      [0] => 10/29/2018
      )
      SimpleXMLElement Object
      (
      [0] => 11/07/2018 00:51:43
      )
      SimpleXMLElement Object
      (
      [XConsultant] => SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [id] => 27189
      )

      [ClientXrefNbr1] => SimpleXMLElement Object
      (
      )

      [PersonID] => 24799
      [PersonCode] => DHinkle12345
      [Email] => test1@gmail.com
      [FirstName] => David
      [MiddleInitial] => SimpleXMLElement Object
      (
      )

      [LastName] => hennry
      [VendorXRefNbr1] => SimpleXMLElement Object
      (
      )

      [VendorXRefNbr2] => SimpleXMLElement Object
      (
      )
      )

      [TimeSheet] => SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [WeekEnd] => 10/28/2018
      [WeekBegin] => 10/22/2018
      )

      [ApprovalHistory] => SimpleXMLElement Object
      (
      [Activity] => Array
      (
      [0] => SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [status] => SUBMITTED
      [datetime] => 10/26/2018 7:30PM
      [person] => David hennry
      [role] => TimeSheetUser
      [comment] =>
      )
      )

      [1] => SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [status] => COMPLETED
      [datetime] => 10/29/2018 11:56AM
      [person] => David hennry
      [role] => TimeSheetUser
      [comment] =>
      )
      )

      [2] => SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [status] => LOCKED
      [datetime] => 11/01/2018 5:05AM
      [person] => David hennry
      [role] => TimeSheetUser
      [comment] => Locked By System [4667]
      )
      )
      )
      )

      [TimeRecord] => Array
      (
      [0] => 8.0000
      [1] => 8.0000
      [2] => 8.0000
      [3] => 8.0000
      [4] => 8.0000
      )
      )

      )
      SimpleXMLElement Object
      (
      [XConsultant] => SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [id] => 32971
      )

      [ClientXrefNbr1] => SimpleXMLElement Object
      (
      )

      [PersonID] => 30305
      [PersonCode] => mailk123
      [Email] => test2@yahoo.com
      [FirstName] => mailk
      [MiddleInitial] => SimpleXMLElement Object
      (
      )

      [LastName] => tom
      [VendorXRefNbr1] => SimpleXMLElement Object
      (
      )

      [VendorXRefNbr2] => SimpleXMLElement Object
      (
      )

      )

      [TimeSheet] => Array
      (
      [0] => SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [WeekEnd] => 10/28/2018
      [WeekBegin] => 10/22/2018
      )

      [ApprovalHistory] => SimpleXMLElement Object
      (
      [Activity] => Array
      (
      [0] => SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [status] => SUBMITTED
      [datetime] => 10/27/2018 10:45AM
      [person] => mailk tom
      [role] => TimeSheetUser
      [comment] =>
      )
      )

      [1] => SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [status] => COMPLETED
      [datetime] => 10/30/2018 12:20PM
      [person] => mailk tom
      [role] => TimeSheetUser
      [comment] =>
      )
      )

      [2] => SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [status] => LOCKED
      [datetime] => 11/01/2018 5:05AM
      [person] => mailk tom
      [role] => TimeSheetUser
      [comment] => Locked By System [4667]
      )
      )
      )
      )

      [TimeRecord] => Array
      (
      [0] => 8.0000
      [1] => 8.0000
      [2] => 8.0000
      [3] => 8.0000
      )
      )

      [1] => SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [WeekEnd] => 11/04/2018
      [WeekBegin] => 10/29/2018
      )

      [ApprovalHistory] => SimpleXMLElement Object
      (
      [Activity] => Array
      (
      [0] => SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [status] => SUBMITTED
      [datetime] => 11/02/2018 7:46PM
      [person] => mailk tom
      [role] => TimeSheetUser
      [comment] =>
      )
      )

      [1] => SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [status] => COMPLETED
      [datetime] => 11/05/2018 11:01AM
      [person] => mailk tom
      [role] => TimeSheetUser
      [comment] =>
      )
      )
      )
      )
      [TimeRecord] => Array
      (
      [0] => 8.0000
      [1] => 8.0000
      [2] => 8.0000
      [3] => 7.7500
      [4] => 8.0000
      )
      )
      )
      )


      I used foreach and associative array key condition also, but I am unable to fetch the records. Where is <ConsultantTime>? I have many consult time data where I need to have foreach loop </ConsultantTime>. Any help would be appreciated.



      Thanks in advance.






      <TimeSheets><TimePeriod><Start weekdayStart="Monday" xmlns="">10/29/2018</Start><End weekdayEnd="Sunday" xmlns="">11/04/2018</End><StatementDate weekdayStatement="Wednesday" xmlns="">11/07/2018</StatementDate><LastRunDate weekdayLastRun="Saturday" xmlns="">12/28/2018</LastRunDate><SystemDate xmlns="">11/07/2018 00:51:43</SystemDate></TimePeriod><Client organization="abc">abc</Client><Supplier organization="fsdf, Inc." name="fsdf, Inc.">fsdf, Inc.

      <ConsultantTime>
      <XConsultant id="27189"><ClientXrefNbr1></ClientXrefNbr1><PersonID>24799</PersonID><PersonCode>DHinkle12345</PersonCode><Email>test1@gmail.com</Email><FirstName>David</FirstName><MiddleInitial></MiddleInitial><LastName>hennry</LastName><VendorXRefNbr1></VendorXRefNbr1><VendorXRefNbr2></VendorXRefNbr2></XConsultant>
      <TimeSheet WeekEnd="10/28/2018" WeekBegin="10/22/2018">
      <ApprovalHistory><Activity status="SUBMITTED" datetime="10/26/2018 7:30PM" person="David hennry" role="TimeSheetUser" comment="" /><Activity status="COMPLETED" datetime="10/29/2018 11:56AM" person="David hennry" role="TimeSheetUser" comment="" /><Activity status="LOCKED" datetime="11/01/2018 5:05AM" person="David hennry" role="TimeSheetUser" comment="Locked By System [4667]" /></ApprovalHistory>
      <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/22/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
      <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/23/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
      <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/24/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
      <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/25/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
      <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/26/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
      </TimeSheet>
      </ConsultantTime>

      </Supplier></TimeSheets>












      share|improve this question
















      This question already has an answer here:




      • How do you parse and process HTML/XML in PHP?

        29 answers




      I want to get the values of the XML below, which has time sheet details like XConsultant, personid, TimeSheet.WeekEnd , TimeRecord.WeekEnd and so on. I had tried with:



      $fileData = simplexml_load_file($fileName);//where file name is the destination of my file url ..


      When I am trying to load and print the array, it's only printing the timesheet details. I want to access the personid and [TimeSheet].[WeekEnd]



      SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [weekdayStart] => Monday
      )

      [0] => 10/29/2018
      )
      SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [weekdayEnd] => Sunday
      )

      [0] => 11/04/2018
      )
      SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [weekdayStatement] => Wednesday
      )

      [0] => 11/07/2018
      )
      SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [weekdayLastRun] => Saturday
      )

      [0] => 10/29/2018
      )
      SimpleXMLElement Object
      (
      [0] => 11/07/2018 00:51:43
      )
      SimpleXMLElement Object
      (
      [XConsultant] => SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [id] => 27189
      )

      [ClientXrefNbr1] => SimpleXMLElement Object
      (
      )

      [PersonID] => 24799
      [PersonCode] => DHinkle12345
      [Email] => test1@gmail.com
      [FirstName] => David
      [MiddleInitial] => SimpleXMLElement Object
      (
      )

      [LastName] => hennry
      [VendorXRefNbr1] => SimpleXMLElement Object
      (
      )

      [VendorXRefNbr2] => SimpleXMLElement Object
      (
      )
      )

      [TimeSheet] => SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [WeekEnd] => 10/28/2018
      [WeekBegin] => 10/22/2018
      )

      [ApprovalHistory] => SimpleXMLElement Object
      (
      [Activity] => Array
      (
      [0] => SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [status] => SUBMITTED
      [datetime] => 10/26/2018 7:30PM
      [person] => David hennry
      [role] => TimeSheetUser
      [comment] =>
      )
      )

      [1] => SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [status] => COMPLETED
      [datetime] => 10/29/2018 11:56AM
      [person] => David hennry
      [role] => TimeSheetUser
      [comment] =>
      )
      )

      [2] => SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [status] => LOCKED
      [datetime] => 11/01/2018 5:05AM
      [person] => David hennry
      [role] => TimeSheetUser
      [comment] => Locked By System [4667]
      )
      )
      )
      )

      [TimeRecord] => Array
      (
      [0] => 8.0000
      [1] => 8.0000
      [2] => 8.0000
      [3] => 8.0000
      [4] => 8.0000
      )
      )

      )
      SimpleXMLElement Object
      (
      [XConsultant] => SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [id] => 32971
      )

      [ClientXrefNbr1] => SimpleXMLElement Object
      (
      )

      [PersonID] => 30305
      [PersonCode] => mailk123
      [Email] => test2@yahoo.com
      [FirstName] => mailk
      [MiddleInitial] => SimpleXMLElement Object
      (
      )

      [LastName] => tom
      [VendorXRefNbr1] => SimpleXMLElement Object
      (
      )

      [VendorXRefNbr2] => SimpleXMLElement Object
      (
      )

      )

      [TimeSheet] => Array
      (
      [0] => SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [WeekEnd] => 10/28/2018
      [WeekBegin] => 10/22/2018
      )

      [ApprovalHistory] => SimpleXMLElement Object
      (
      [Activity] => Array
      (
      [0] => SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [status] => SUBMITTED
      [datetime] => 10/27/2018 10:45AM
      [person] => mailk tom
      [role] => TimeSheetUser
      [comment] =>
      )
      )

      [1] => SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [status] => COMPLETED
      [datetime] => 10/30/2018 12:20PM
      [person] => mailk tom
      [role] => TimeSheetUser
      [comment] =>
      )
      )

      [2] => SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [status] => LOCKED
      [datetime] => 11/01/2018 5:05AM
      [person] => mailk tom
      [role] => TimeSheetUser
      [comment] => Locked By System [4667]
      )
      )
      )
      )

      [TimeRecord] => Array
      (
      [0] => 8.0000
      [1] => 8.0000
      [2] => 8.0000
      [3] => 8.0000
      )
      )

      [1] => SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [WeekEnd] => 11/04/2018
      [WeekBegin] => 10/29/2018
      )

      [ApprovalHistory] => SimpleXMLElement Object
      (
      [Activity] => Array
      (
      [0] => SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [status] => SUBMITTED
      [datetime] => 11/02/2018 7:46PM
      [person] => mailk tom
      [role] => TimeSheetUser
      [comment] =>
      )
      )

      [1] => SimpleXMLElement Object
      (
      [@attributes] => Array
      (
      [status] => COMPLETED
      [datetime] => 11/05/2018 11:01AM
      [person] => mailk tom
      [role] => TimeSheetUser
      [comment] =>
      )
      )
      )
      )
      [TimeRecord] => Array
      (
      [0] => 8.0000
      [1] => 8.0000
      [2] => 8.0000
      [3] => 7.7500
      [4] => 8.0000
      )
      )
      )
      )


      I used foreach and associative array key condition also, but I am unable to fetch the records. Where is <ConsultantTime>? I have many consult time data where I need to have foreach loop </ConsultantTime>. Any help would be appreciated.



      Thanks in advance.






      <TimeSheets><TimePeriod><Start weekdayStart="Monday" xmlns="">10/29/2018</Start><End weekdayEnd="Sunday" xmlns="">11/04/2018</End><StatementDate weekdayStatement="Wednesday" xmlns="">11/07/2018</StatementDate><LastRunDate weekdayLastRun="Saturday" xmlns="">12/28/2018</LastRunDate><SystemDate xmlns="">11/07/2018 00:51:43</SystemDate></TimePeriod><Client organization="abc">abc</Client><Supplier organization="fsdf, Inc." name="fsdf, Inc.">fsdf, Inc.

      <ConsultantTime>
      <XConsultant id="27189"><ClientXrefNbr1></ClientXrefNbr1><PersonID>24799</PersonID><PersonCode>DHinkle12345</PersonCode><Email>test1@gmail.com</Email><FirstName>David</FirstName><MiddleInitial></MiddleInitial><LastName>hennry</LastName><VendorXRefNbr1></VendorXRefNbr1><VendorXRefNbr2></VendorXRefNbr2></XConsultant>
      <TimeSheet WeekEnd="10/28/2018" WeekBegin="10/22/2018">
      <ApprovalHistory><Activity status="SUBMITTED" datetime="10/26/2018 7:30PM" person="David hennry" role="TimeSheetUser" comment="" /><Activity status="COMPLETED" datetime="10/29/2018 11:56AM" person="David hennry" role="TimeSheetUser" comment="" /><Activity status="LOCKED" datetime="11/01/2018 5:05AM" person="David hennry" role="TimeSheetUser" comment="Locked By System [4667]" /></ApprovalHistory>
      <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/22/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
      <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/23/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
      <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/24/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
      <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/25/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
      <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/26/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
      </TimeSheet>
      </ConsultantTime>

      </Supplier></TimeSheets>







      This question already has an answer here:




      • How do you parse and process HTML/XML in PHP?

        29 answers







      <TimeSheets><TimePeriod><Start weekdayStart="Monday" xmlns="">10/29/2018</Start><End weekdayEnd="Sunday" xmlns="">11/04/2018</End><StatementDate weekdayStatement="Wednesday" xmlns="">11/07/2018</StatementDate><LastRunDate weekdayLastRun="Saturday" xmlns="">12/28/2018</LastRunDate><SystemDate xmlns="">11/07/2018 00:51:43</SystemDate></TimePeriod><Client organization="abc">abc</Client><Supplier organization="fsdf, Inc." name="fsdf, Inc.">fsdf, Inc.

      <ConsultantTime>
      <XConsultant id="27189"><ClientXrefNbr1></ClientXrefNbr1><PersonID>24799</PersonID><PersonCode>DHinkle12345</PersonCode><Email>test1@gmail.com</Email><FirstName>David</FirstName><MiddleInitial></MiddleInitial><LastName>hennry</LastName><VendorXRefNbr1></VendorXRefNbr1><VendorXRefNbr2></VendorXRefNbr2></XConsultant>
      <TimeSheet WeekEnd="10/28/2018" WeekBegin="10/22/2018">
      <ApprovalHistory><Activity status="SUBMITTED" datetime="10/26/2018 7:30PM" person="David hennry" role="TimeSheetUser" comment="" /><Activity status="COMPLETED" datetime="10/29/2018 11:56AM" person="David hennry" role="TimeSheetUser" comment="" /><Activity status="LOCKED" datetime="11/01/2018 5:05AM" person="David hennry" role="TimeSheetUser" comment="Locked By System [4667]" /></ApprovalHistory>
      <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/22/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
      <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/23/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
      <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/24/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
      <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/25/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
      <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/26/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
      </TimeSheet>
      </ConsultantTime>

      </Supplier></TimeSheets>





      <TimeSheets><TimePeriod><Start weekdayStart="Monday" xmlns="">10/29/2018</Start><End weekdayEnd="Sunday" xmlns="">11/04/2018</End><StatementDate weekdayStatement="Wednesday" xmlns="">11/07/2018</StatementDate><LastRunDate weekdayLastRun="Saturday" xmlns="">12/28/2018</LastRunDate><SystemDate xmlns="">11/07/2018 00:51:43</SystemDate></TimePeriod><Client organization="abc">abc</Client><Supplier organization="fsdf, Inc." name="fsdf, Inc.">fsdf, Inc.

      <ConsultantTime>
      <XConsultant id="27189"><ClientXrefNbr1></ClientXrefNbr1><PersonID>24799</PersonID><PersonCode>DHinkle12345</PersonCode><Email>test1@gmail.com</Email><FirstName>David</FirstName><MiddleInitial></MiddleInitial><LastName>hennry</LastName><VendorXRefNbr1></VendorXRefNbr1><VendorXRefNbr2></VendorXRefNbr2></XConsultant>
      <TimeSheet WeekEnd="10/28/2018" WeekBegin="10/22/2018">
      <ApprovalHistory><Activity status="SUBMITTED" datetime="10/26/2018 7:30PM" person="David hennry" role="TimeSheetUser" comment="" /><Activity status="COMPLETED" datetime="10/29/2018 11:56AM" person="David hennry" role="TimeSheetUser" comment="" /><Activity status="LOCKED" datetime="11/01/2018 5:05AM" person="David hennry" role="TimeSheetUser" comment="Locked By System [4667]" /></ApprovalHistory>
      <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/22/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
      <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/23/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
      <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/24/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
      <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/25/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
      <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/26/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
      </TimeSheet>
      </ConsultantTime>

      </Supplier></TimeSheets>






      php xml laravel-5






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 9 at 21:39









      Worthwelle

      453111




      453111










      asked Nov 9 at 8:02









      shirisha madhireddy

      61




      61




      marked as duplicate by gsamaras, IMSoP php
      Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 9 at 10:13


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by gsamaras, IMSoP php
      Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 9 at 10:13


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          -2
          down vote













          This code here will parse the XML in $input. Substitute $input for whatever variable currently holds your XML



          <?php
          $input = "<TimeSheets><TimePeriod><Start weekdayStart="Monday" xmlns="">10/29/2018</Start><End weekdayEnd="Sunday" xmlns="">11/04/2018</End><StatementDate weekdayStatement="Wednesday" xmlns="">11/07/2018</StatementDate><LastRunDate weekdayLastRun="Saturday" xmlns="">12/28/2018</LastRunDate><SystemDate xmlns="">11/07/2018 00:51:43</SystemDate></TimePeriod><Client organization="abc">abc</Client><Supplier organization="fsdf, Inc." name="fsdf, Inc.">fsdf, Inc.
          <ConsultantTime>
          <XConsultant id="27189"><ClientXrefNbr1></ClientXrefNbr1><PersonID>24799</PersonID>
          <PersonCode>DHinkle12345</PersonCode><Email>test1@gmail.com</Email>
          <FirstName>David</FirstName><MiddleInitial></MiddleInitial>
          <LastName>hennry</LastName><VendorXRefNbr1></VendorXRefNbr1><VendorXRefNbr2>
          </VendorXRefNbr2></XConsultant>
          <TimeSheet WeekEnd="10/28/2018" WeekBegin="10/22/2018">
          <ApprovalHistory><Activity status="SUBMITTED" datetime="10/26/2018 7:30PM"
          person="David hennry" role="TimeSheetUser" comment="" /><Activity
          status="COMPLETED" datetime="10/29/2018 11:56AM" person="David hennry"
          role="TimeSheetUser" comment="" /><Activity status="LOCKED"
          datetime="11/01/2018 5:05AM" person="David hennry" role="TimeSheetUser"
          comment="Locked By System [4667]" /></ApprovalHistory>
          <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/22/2018"
          payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A"
          PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511"
          TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating
          Expense" MSProjID="Default" FinTaskNumber="Default"
          ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2=""
          ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0"
          MasterProjectName="" SOP98="N" TaskWBSCode="60041"
          TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In:
          8:00 AM Time Out: 12:00 PM Comments: Time In:
          12:30 PM Time Out: 4:30 PM Comments: " ApproverName=""
          BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2=""
          VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6=""
          VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9=""
          VendorXRefNbr10="">8.0000</TimeRecord>
          <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/23/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
          <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/24/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
          <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/25/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
          <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/26/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
          </TimeSheet>
          </ConsultantTime>";

          //Create an XML parser object
          $p = xml_parser_create();

          //An array to put the data into
          $data = array();

          //Parse the XML into the data array
          xml_parse_into_struct($p, $input, $data);

          //Show the data array
          echo "<pre>" . print_r( $data, 1 ) . "</pre>";


          Running that code will give you the XML in a structured array, you will be able to process it in a for loop.






          share|improve this answer





















          • xml_parse_into_struct is not so much an XML parser, as a low-level bit of code that might be useful for building an XML parser; the array it produces is unlikely to be useful for, well, anything really. PHP has several much more user-friendly ways of working with XML, such as SimpleXML, which the OP already found.
            – IMSoP
            Nov 9 at 10:13




















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          -2
          down vote













          This code here will parse the XML in $input. Substitute $input for whatever variable currently holds your XML



          <?php
          $input = "<TimeSheets><TimePeriod><Start weekdayStart="Monday" xmlns="">10/29/2018</Start><End weekdayEnd="Sunday" xmlns="">11/04/2018</End><StatementDate weekdayStatement="Wednesday" xmlns="">11/07/2018</StatementDate><LastRunDate weekdayLastRun="Saturday" xmlns="">12/28/2018</LastRunDate><SystemDate xmlns="">11/07/2018 00:51:43</SystemDate></TimePeriod><Client organization="abc">abc</Client><Supplier organization="fsdf, Inc." name="fsdf, Inc.">fsdf, Inc.
          <ConsultantTime>
          <XConsultant id="27189"><ClientXrefNbr1></ClientXrefNbr1><PersonID>24799</PersonID>
          <PersonCode>DHinkle12345</PersonCode><Email>test1@gmail.com</Email>
          <FirstName>David</FirstName><MiddleInitial></MiddleInitial>
          <LastName>hennry</LastName><VendorXRefNbr1></VendorXRefNbr1><VendorXRefNbr2>
          </VendorXRefNbr2></XConsultant>
          <TimeSheet WeekEnd="10/28/2018" WeekBegin="10/22/2018">
          <ApprovalHistory><Activity status="SUBMITTED" datetime="10/26/2018 7:30PM"
          person="David hennry" role="TimeSheetUser" comment="" /><Activity
          status="COMPLETED" datetime="10/29/2018 11:56AM" person="David hennry"
          role="TimeSheetUser" comment="" /><Activity status="LOCKED"
          datetime="11/01/2018 5:05AM" person="David hennry" role="TimeSheetUser"
          comment="Locked By System [4667]" /></ApprovalHistory>
          <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/22/2018"
          payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A"
          PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511"
          TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating
          Expense" MSProjID="Default" FinTaskNumber="Default"
          ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2=""
          ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0"
          MasterProjectName="" SOP98="N" TaskWBSCode="60041"
          TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In:
          8:00 AM Time Out: 12:00 PM Comments: Time In:
          12:30 PM Time Out: 4:30 PM Comments: " ApproverName=""
          BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2=""
          VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6=""
          VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9=""
          VendorXRefNbr10="">8.0000</TimeRecord>
          <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/23/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
          <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/24/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
          <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/25/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
          <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/26/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
          </TimeSheet>
          </ConsultantTime>";

          //Create an XML parser object
          $p = xml_parser_create();

          //An array to put the data into
          $data = array();

          //Parse the XML into the data array
          xml_parse_into_struct($p, $input, $data);

          //Show the data array
          echo "<pre>" . print_r( $data, 1 ) . "</pre>";


          Running that code will give you the XML in a structured array, you will be able to process it in a for loop.






          share|improve this answer





















          • xml_parse_into_struct is not so much an XML parser, as a low-level bit of code that might be useful for building an XML parser; the array it produces is unlikely to be useful for, well, anything really. PHP has several much more user-friendly ways of working with XML, such as SimpleXML, which the OP already found.
            – IMSoP
            Nov 9 at 10:13

















          up vote
          -2
          down vote













          This code here will parse the XML in $input. Substitute $input for whatever variable currently holds your XML



          <?php
          $input = "<TimeSheets><TimePeriod><Start weekdayStart="Monday" xmlns="">10/29/2018</Start><End weekdayEnd="Sunday" xmlns="">11/04/2018</End><StatementDate weekdayStatement="Wednesday" xmlns="">11/07/2018</StatementDate><LastRunDate weekdayLastRun="Saturday" xmlns="">12/28/2018</LastRunDate><SystemDate xmlns="">11/07/2018 00:51:43</SystemDate></TimePeriod><Client organization="abc">abc</Client><Supplier organization="fsdf, Inc." name="fsdf, Inc.">fsdf, Inc.
          <ConsultantTime>
          <XConsultant id="27189"><ClientXrefNbr1></ClientXrefNbr1><PersonID>24799</PersonID>
          <PersonCode>DHinkle12345</PersonCode><Email>test1@gmail.com</Email>
          <FirstName>David</FirstName><MiddleInitial></MiddleInitial>
          <LastName>hennry</LastName><VendorXRefNbr1></VendorXRefNbr1><VendorXRefNbr2>
          </VendorXRefNbr2></XConsultant>
          <TimeSheet WeekEnd="10/28/2018" WeekBegin="10/22/2018">
          <ApprovalHistory><Activity status="SUBMITTED" datetime="10/26/2018 7:30PM"
          person="David hennry" role="TimeSheetUser" comment="" /><Activity
          status="COMPLETED" datetime="10/29/2018 11:56AM" person="David hennry"
          role="TimeSheetUser" comment="" /><Activity status="LOCKED"
          datetime="11/01/2018 5:05AM" person="David hennry" role="TimeSheetUser"
          comment="Locked By System [4667]" /></ApprovalHistory>
          <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/22/2018"
          payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A"
          PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511"
          TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating
          Expense" MSProjID="Default" FinTaskNumber="Default"
          ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2=""
          ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0"
          MasterProjectName="" SOP98="N" TaskWBSCode="60041"
          TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In:
          8:00 AM Time Out: 12:00 PM Comments: Time In:
          12:30 PM Time Out: 4:30 PM Comments: " ApproverName=""
          BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2=""
          VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6=""
          VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9=""
          VendorXRefNbr10="">8.0000</TimeRecord>
          <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/23/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
          <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/24/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
          <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/25/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
          <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/26/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
          </TimeSheet>
          </ConsultantTime>";

          //Create an XML parser object
          $p = xml_parser_create();

          //An array to put the data into
          $data = array();

          //Parse the XML into the data array
          xml_parse_into_struct($p, $input, $data);

          //Show the data array
          echo "<pre>" . print_r( $data, 1 ) . "</pre>";


          Running that code will give you the XML in a structured array, you will be able to process it in a for loop.






          share|improve this answer





















          • xml_parse_into_struct is not so much an XML parser, as a low-level bit of code that might be useful for building an XML parser; the array it produces is unlikely to be useful for, well, anything really. PHP has several much more user-friendly ways of working with XML, such as SimpleXML, which the OP already found.
            – IMSoP
            Nov 9 at 10:13















          up vote
          -2
          down vote










          up vote
          -2
          down vote









          This code here will parse the XML in $input. Substitute $input for whatever variable currently holds your XML



          <?php
          $input = "<TimeSheets><TimePeriod><Start weekdayStart="Monday" xmlns="">10/29/2018</Start><End weekdayEnd="Sunday" xmlns="">11/04/2018</End><StatementDate weekdayStatement="Wednesday" xmlns="">11/07/2018</StatementDate><LastRunDate weekdayLastRun="Saturday" xmlns="">12/28/2018</LastRunDate><SystemDate xmlns="">11/07/2018 00:51:43</SystemDate></TimePeriod><Client organization="abc">abc</Client><Supplier organization="fsdf, Inc." name="fsdf, Inc.">fsdf, Inc.
          <ConsultantTime>
          <XConsultant id="27189"><ClientXrefNbr1></ClientXrefNbr1><PersonID>24799</PersonID>
          <PersonCode>DHinkle12345</PersonCode><Email>test1@gmail.com</Email>
          <FirstName>David</FirstName><MiddleInitial></MiddleInitial>
          <LastName>hennry</LastName><VendorXRefNbr1></VendorXRefNbr1><VendorXRefNbr2>
          </VendorXRefNbr2></XConsultant>
          <TimeSheet WeekEnd="10/28/2018" WeekBegin="10/22/2018">
          <ApprovalHistory><Activity status="SUBMITTED" datetime="10/26/2018 7:30PM"
          person="David hennry" role="TimeSheetUser" comment="" /><Activity
          status="COMPLETED" datetime="10/29/2018 11:56AM" person="David hennry"
          role="TimeSheetUser" comment="" /><Activity status="LOCKED"
          datetime="11/01/2018 5:05AM" person="David hennry" role="TimeSheetUser"
          comment="Locked By System [4667]" /></ApprovalHistory>
          <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/22/2018"
          payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A"
          PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511"
          TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating
          Expense" MSProjID="Default" FinTaskNumber="Default"
          ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2=""
          ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0"
          MasterProjectName="" SOP98="N" TaskWBSCode="60041"
          TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In:
          8:00 AM Time Out: 12:00 PM Comments: Time In:
          12:30 PM Time Out: 4:30 PM Comments: " ApproverName=""
          BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2=""
          VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6=""
          VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9=""
          VendorXRefNbr10="">8.0000</TimeRecord>
          <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/23/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
          <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/24/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
          <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/25/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
          <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/26/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
          </TimeSheet>
          </ConsultantTime>";

          //Create an XML parser object
          $p = xml_parser_create();

          //An array to put the data into
          $data = array();

          //Parse the XML into the data array
          xml_parse_into_struct($p, $input, $data);

          //Show the data array
          echo "<pre>" . print_r( $data, 1 ) . "</pre>";


          Running that code will give you the XML in a structured array, you will be able to process it in a for loop.






          share|improve this answer












          This code here will parse the XML in $input. Substitute $input for whatever variable currently holds your XML



          <?php
          $input = "<TimeSheets><TimePeriod><Start weekdayStart="Monday" xmlns="">10/29/2018</Start><End weekdayEnd="Sunday" xmlns="">11/04/2018</End><StatementDate weekdayStatement="Wednesday" xmlns="">11/07/2018</StatementDate><LastRunDate weekdayLastRun="Saturday" xmlns="">12/28/2018</LastRunDate><SystemDate xmlns="">11/07/2018 00:51:43</SystemDate></TimePeriod><Client organization="abc">abc</Client><Supplier organization="fsdf, Inc." name="fsdf, Inc.">fsdf, Inc.
          <ConsultantTime>
          <XConsultant id="27189"><ClientXrefNbr1></ClientXrefNbr1><PersonID>24799</PersonID>
          <PersonCode>DHinkle12345</PersonCode><Email>test1@gmail.com</Email>
          <FirstName>David</FirstName><MiddleInitial></MiddleInitial>
          <LastName>hennry</LastName><VendorXRefNbr1></VendorXRefNbr1><VendorXRefNbr2>
          </VendorXRefNbr2></XConsultant>
          <TimeSheet WeekEnd="10/28/2018" WeekBegin="10/22/2018">
          <ApprovalHistory><Activity status="SUBMITTED" datetime="10/26/2018 7:30PM"
          person="David hennry" role="TimeSheetUser" comment="" /><Activity
          status="COMPLETED" datetime="10/29/2018 11:56AM" person="David hennry"
          role="TimeSheetUser" comment="" /><Activity status="LOCKED"
          datetime="11/01/2018 5:05AM" person="David hennry" role="TimeSheetUser"
          comment="Locked By System [4667]" /></ApprovalHistory>
          <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/22/2018"
          payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A"
          PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511"
          TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating
          Expense" MSProjID="Default" FinTaskNumber="Default"
          ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2=""
          ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0"
          MasterProjectName="" SOP98="N" TaskWBSCode="60041"
          TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In:
          8:00 AM Time Out: 12:00 PM Comments: Time In:
          12:30 PM Time Out: 4:30 PM Comments: " ApproverName=""
          BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2=""
          VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6=""
          VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9=""
          VendorXRefNbr10="">8.0000</TimeRecord>
          <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/23/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
          <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/24/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
          <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/25/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
          <TimeRecord WeekEnd="10/28/2018" WeekBegin="10/22/2018" workdate="10/26/2018" payCode="RT" projectID="Default" projectType="T&amp;M" ProjectCode="N/A" PrjMgrLastName="" PrjMgrFirstName="" PrjMgrEmail="" TimeHeaderKey="361511" TaskID="10323" TaskName="Operating Expense" MSTaskID="Default-Operating Expense" MSProjID="Default" FinTaskNumber="Default" ProjectFinTaskNumber1="Default" ProjectFinTaskNumber2="" ResourceFinTaskNumber1="" ResourceFinTaskNumber2="" MasterProjectID="0" MasterProjectName="" SOP98="N" TaskWBSCode="60041" TimeSystemCostCenter="4200G" ExpOrgType="" AccruedTime="0" Comments="Time In: 8:00 AM Time Out: 12:00 PM Comments: Time In: 12:30 PM Time Out: 4:30 PM Comments: " ApproverName="" BillToOrganization="BSC" VendorXRefNbr1="" VendorXRefNbr2="" VendorXRefNbr3="" VendorXRefNbr4="" VendorXRefNbr5="" VendorXRefNbr6="" VendorXRefNbr7="" VendorXRefNbr8="" VendorXRefNbr9="" VendorXRefNbr10="">8.0000</TimeRecord>
          </TimeSheet>
          </ConsultantTime>";

          //Create an XML parser object
          $p = xml_parser_create();

          //An array to put the data into
          $data = array();

          //Parse the XML into the data array
          xml_parse_into_struct($p, $input, $data);

          //Show the data array
          echo "<pre>" . print_r( $data, 1 ) . "</pre>";


          Running that code will give you the XML in a structured array, you will be able to process it in a for loop.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 9 at 9:29









          Harvey Fletcher

          9841516




          9841516












          • xml_parse_into_struct is not so much an XML parser, as a low-level bit of code that might be useful for building an XML parser; the array it produces is unlikely to be useful for, well, anything really. PHP has several much more user-friendly ways of working with XML, such as SimpleXML, which the OP already found.
            – IMSoP
            Nov 9 at 10:13




















          • xml_parse_into_struct is not so much an XML parser, as a low-level bit of code that might be useful for building an XML parser; the array it produces is unlikely to be useful for, well, anything really. PHP has several much more user-friendly ways of working with XML, such as SimpleXML, which the OP already found.
            – IMSoP
            Nov 9 at 10:13


















          xml_parse_into_struct is not so much an XML parser, as a low-level bit of code that might be useful for building an XML parser; the array it produces is unlikely to be useful for, well, anything really. PHP has several much more user-friendly ways of working with XML, such as SimpleXML, which the OP already found.
          – IMSoP
          Nov 9 at 10:13






          xml_parse_into_struct is not so much an XML parser, as a low-level bit of code that might be useful for building an XML parser; the array it produces is unlikely to be useful for, well, anything really. PHP has several much more user-friendly ways of working with XML, such as SimpleXML, which the OP already found.
          – IMSoP
          Nov 9 at 10:13





          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          JBPM : POST request for execute process go wrong