K
K
kriostar2016-02-10 16:01:39
MySQL
kriostar, 2016-02-10 16:01:39

Parsing .xml file into mysql database?

Good afternoon, I ask for advice in solving the issue of parsing data into the mysql database. A file like this:

<response>
<systime0>2324</systime0>
<iovalue0>1000000000000000000001</iovalue0>
<pwm0>0</pwm0>
<adc0>635</adc0>
<adc1>561</adc1>
<adc2>527</adc2>
<adc3>652</adc3>
<count0>0</count0>
<count1>0</count1>
<count2>0</count2>
<count3>0</count3>
<slow_info0/>
<cat_inf0/>
<cat_cnt0/>
</response>

Interested in the contents of the iovalue0 field. Where each digit is a separate value that should occupy a separate cell in the table. The value can be "1" or "0". Number of values ​​22.
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
bears, 2016-02-10
@kriostar

Do you need it?

$xml = '<response>
<systime0>2324</systime0>
<iovalue0>1000000000000000000001</iovalue0>
<pwm0>0</pwm0>
<adc0>635</adc0>
<adc1>561</adc1>
<adc2>527</adc2>
<adc3>652</adc3>
<count0>0</count0>
<count1>0</count1>
<count2>0</count2>
<count3>0</count3>
<slow_info0/>
<cat_inf0/>
<cat_cnt0/>
</response>';

$data = new SimpleXMLElement($xml);
$data = str_split($data->iovalue0);
$data = implode('|', $data);

var_dump($data);

// Результат
string '1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1' (length=43)

K
kriostar, 2016-02-10
@kriostar

It is necessary from 1000000000000000000001 to
get the table |1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1 |
Something like this.
Bears, your answer is very similar to the "str_split" solution, but you can suggest how to use it. Sorry, I'm a layman in this matter.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question