My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

Post hidden from Hashnode

Posts can be hidden from Hashnode network for various reasons. Contact the moderators for more details.

Please help, How to read and display XML Elements to HTML table using PHP.?

Bright Ngidi's photo
Bright Ngidi
·Mar 24, 2017

i`m a newbie to php and javascript but i have a personal project that needs knowledge about these languages.

i have two xml files that i would like to read and display.

file 1 is a transaction file by a user and file 2 is a summary of transaction files and Total of all summary files (depending on how many transaction files user(s) created).

Here is my file 1

<?xml version="1.0" encoding="UTF-8" ?>
<CmpOUT>
<TRX>
   <Version>3.0.19.82</Version>
   <DeviceProductName>Product</DeviceProductName>
   <DeviceSerialNumber>4C02890FD627</DeviceSerialNumber>
   <LocationName>Demo place</LocationName>
   <InputNumber>guest</InputNumber>
   <InputSubNumber></InputSubNumber>
   <OutputNumber></OutputNumber>
   <OutputSubNumber></OutputSubNumber>
   <TrxCode>1</TrxCode>
   <BagNumber>999999</BagNumber>
   <NoteJam>0</NoteJam>
   <TranAmount>35850.00</TranAmount>
   <DateTime>2016-12-03T16:17:42</DateTime>
   <TranCycle>2072</TranCycle>
   <ContainerCycle>64</ContainerCycle>
   <ContainerNumber></ContainerNumber>
   <TotalNumberOfNotes>0</TotalNumberOfNotes>
   <NoteCount>
      <Currency>ZAR</Currency>
      <Denomination>10.00</Denomination>
      <NumberOfNotes>10</NumberOfNotes>
   </NoteCount>
   <NoteCount>
      <Currency>ZAR</Currency>
      <Denomination>20.00</Denomination>
      <NumberOfNotes>20</NumberOfNotes>
   </NoteCount>
   <NoteCount>
      <Currency>ZAR</Currency>
      <Denomination>50.00</Denomination>
      <NumberOfNotes>11</NumberOfNotes>
   </NoteCount>
   <NoteCount>
      <Currency>ZAR</Currency>
      <Denomination>100.00</Denomination>
      <NumberOfNotes>198</NumberOfNotes>
   </NoteCount>
   <NoteCount>
      <Currency>ZAR</Currency>
      <Denomination>200.00</Denomination>
      <NumberOfNotes>75</NumberOfNotes>
   </NoteCount>
   <Reference>DemoUser</Reference>
   <ShiftReference></ShiftReference>
</TRX>
</CmpOUT>

My file 1 is a transaction file which has a number Elements/Nodes and Child Elements (14 Main Elements, 3 Child elements).

I would like to use PHP to read all these elements and display their data in HTML table content.

Here is my file 2

<EODSummary>
   <Summary>
      <Transaction>
         <Date>2017-01-06</Date>
         <Time>17:54:57</Time>
         <InputNumber>guest</InputNumber>
         <RefNo>TILL25</RefNo>
         <Amount>19620.00</Amount>
      </Transaction>
      <Transaction>
         <Date>2017-01-06</Date>
         <Time>17:56:06</Time>
         <InputNumber>guest</InputNumber>
         <RefNo>TLL28</RefNo>
         <Amount>300.00</Amount>
      </Transaction>
      <Transaction>
         <Date>2017-01-06</Date>
         <Time>17:56:54</Time>
         <InputNumber>guest</InputNumber>
         <RefNo>TILL09</RefNo>
         <Amount>4770.00</Amount>
      </Transaction>
      <Transaction>
         <Date>2017-01-06</Date>
         <Time>17:57:36</Time>
         <InputNumber>guest</InputNumber>
         <RefNo>TILL04</RefNo>
         <Amount>320.00</Amount>
      </Transaction>
      <Information>
         <EODNo>87</EODNo>
         <BagNumber>999999</BagNumber>
         <DeviceSerialNumber>4C02890FD627</DeviceSerialNumber>
         <ContainerNumber>014</ContainerNumber>
         <ContainerCycle>84</ContainerCycle>
         <Currency>ZAR</Currency>
         <Name>Demo Place</Name>
         <Date>2017-01-07</Date>
         <Time>07:19:16</Time>
         <Transactions>4</Transactions>
         <TotalValue>25010.00</TotalValue>
         <Denomination1>54</Denomination1>
         <Denomination2>76</Denomination2>
         <Denomination3>67</Denomination3>
         <Denomination4>98</Denomination4>
         <Denomination5>49</Denomination5>
      </Information>
   </Summary>
</EODSummary>

So basically, file 1 which is a transaction file belongs to the Summary file and transaction files are listed in Summary file and added up to give Total of all transactions.

This looks a bit complex to me the newbie in PHP but i hope you guys can understand.

Lastly i would like to Thank everyone on the site for allowing me to post and ask for assistance.