1

This is sample xml file. I want to convert this xml file into byte array which is equivalent to C# byte array.

<?xml version="1.0" encoding="UTF-8"?>
<DailyMidDayMeal>
<MDMHeader StateID="19" MDMServedDate="30/11/2017" BatchCount="1" 
BatchIDCreateDateTime="30/11/2017 11:02:47" BatchType="F">
<DailyTransactions>
<sno>001</sno>
<SchoolCode>19220111501</SchoolCode>
<MDMServedCount>34</MDMServedCount>
<ReasonCode>0</ReasonCode>
<TxnDateTime>30/11/2017 10:02:01</TxnDateTime>
</DailyTransactions>
</MDMHeader>
</DailyMidDayMeal>

1 Answers1

1

A variation of this question has been answered before. See the approved answer here: String to byte array in php

For completeness, I'll put this in the context of your question:

$xmlStr = file_get_contents('sample.xml'); // read file to string
$byte_array = unpack('C*', $xmlStr); // convert string to byte array
var_dump($byte_array); // output your resulting byte array

See the PHP documentation for details on unpack: http://php.net/manual/en/function.unpack.php

Edit: I saw in a comment you mentioned this method didn't work. Attached are my results from a small test:

Results

Philip Attisano
  • 223
  • 1
  • 8