hi
I would like to know how to convert XML to Array with codeIgniter
This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
September 24, 2011 5:22pm
Subscribe [7]#1 / Sep 24, 2011 5:22pm
hi
I would like to know how to convert XML to Array with codeIgniter
#2 / Sep 25, 2011 12:42am
http://codeigniter.com/wiki/Xml_Library/
maybe this can help you!!
#3 / Sep 25, 2011 3:13pm
Thanks
#4 / Sep 29, 2011 5:38am
Pffft laaaaame! Use my Format library for X to Y conversion between a whole bunch of formats:
https://github.com/philsturgeon/codeigniter-restserver/blob/master/application/libraries/Format.php
Hit raw and copy and paste. This is part of restserver but I will chuck it into CI 2.1.
#5 / Sep 29, 2011 6:20pm
Nice, but was the “Pffft lame” really necessary? 😊 LOL
#6 / Sep 29, 2011 6:24pm
Of course! :-D
#7 / Nov 15, 2011 11:40pm
Pffft laaaaame! Use my Format library for X to Y conversion between a whole bunch of formats:
https://github.com/philsturgeon/codeigniter-restserver/blob/master/application/libraries/Format.php
Hit raw and copy and paste. This is part of restserver but I will chuck it into CI 2.1.
Did this manage to get into the recent v2.1.0 release? If not, any plans for next release?
#8 / Nov 16, 2011 5:58am
This one will be going into develop as I didn’t see the point in writing extra documentation in HTML that I’d need to translate LaTex for 3.0.
#9 / Jan 26, 2012 3:15am
Hi Phil,
Thanks for a great Library. One question though, and it’s more of a php one!
When converting from xml to array. It outputs a single array as
[Item] => Array
(
[Name] => Name
[Code] => 10
)And multiple array as
[Item] => Array
(
[0] => Array
(
[Name] => Name1
[Code] => 10
),
[1] => Array
(
[Name] => Name2
[Code] => 11
)
)I need to loop all occurrences of Item, but cannot us foreach as sometimes it returns a single array, something like this would be great:
[Item] => Array
(
[0] => Array
(
[Name] => Name1
[Code] => 10
)
)But do not know how to achieve it.
I think it’s the simplexml_load_string() function that outputs it this way, but I have no idea how to loop all the through all the data.
Any help / advice would be greatly appreciated.
Thanks
Nate
#10 / Jan 26, 2012 3:15am
Hi Phil,
Thanks for a great Library. One question though, and it’s more of a php one!
When converting from xml to array. It outputs a single array as
[Item] => Array
(
[Name] => Name
[Code] => 10
)And multiple array as
[Item] => Array
(
[0] => Array
(
[Name] => Name1
[Code] => 10
),
[1] => Array
(
[Name] => Name2
[Code] => 11
)
)I need to loop all occurrences of Item, but cannot us foreach as sometimes it returns a single array, something like this would be great:
[Item] => Array
(
[0] => Array
(
[Name] => Name1
[Code] => 10
)
)But do not know how to achieve it.
I think it’s the simplexml_load_string() function that outputs it this way, but I have no idea how to loop all the through all the data.
Any help / advice would be greatly appreciated.
Thanks
Nate
#11 / Jan 26, 2012 3:17am
isset($data[0]) or $data = array($data);#12 / Jan 26, 2012 3:38am
Thanks Phil,
Worked a treat.
Regards
Nate
#13 / Jun 22, 2012 7:13pm
Phil
I have a cURL $res = curl_exec($ch); that returns XML in this following format.
<?xml version="1.0"?>
<XMLDataStreamResponse>
<Ver>3.2</Ver>
<LegalNote>USE SUBJECT TO TERMS OF YOUR AGREEMENT. UNAUTHORIZED USE PROHIBITED. SUPPLIER INFORMATION IS CONFIDENTIAL. (C) 2012 QUICK TECHNOLOGIES INC.</LegalNote>
<SearchResults>
<Success>1</Success>
<ErrMsg></ErrMsg>
<TotalFound>567</TotalFound>
<Items>
<Item>
<Count>1</Count>
553425783</ProductID>
<SPC>AFLIE-HMXSX</SPC>
Food Processor</PrName>
19.35 - 24.70</Prc>
<ThumbPicLink>http://www.promoplace.com/ws/ws.dll/QPic?SN=63814&P=553425783&RS=150</ThumbPicLink>
</Item>
<Item>
<Count>2</Count>
992851163</ProductID>
<SPC>VJFKE-GGFSD</SPC>
Kitchen Worthy Stainless Steel Deep Fryer</PrName>
27.95</Prc>
<ThumbPicLink>http://www.promoplace.com/ws/ws.dll/QPic?SN=63814&P=992851163&RS=150</ThumbPicLink>
</Item>
<Item>
<Count>3</Count>
503169927</ProductID>
<SPC>FBNOI-GYJGH</SPC>
2 Slice Toaster & Bun Warmer</PrName>
15.95 - 20.30</Prc>
<ThumbPicLink>http://www.promoplace.com/ws/ws.dll/QPic?SN=63814&P=503169927&RS=150</ThumbPicLink>
</Item>How would I start to use your library to build arrays so I can use them in my view?