Soapbox / laravel-formatter

A Formatter Class for Laravel 4 based on FuelPHP's Formatter Class
249 stars 95 forks source link

Same key problem when generating XML string #29

Open chris-peng-1244 opened 9 years ago

chris-peng-1244 commented 9 years ago

Say I want a XML like this

<Books>
 <Book>
  <Title>Book1</Title>
  <Price>10.00</Price>
 </Book>
 <Book>
  <Title>Book2</Title>
  <Price>15.00</Price>
 </Book>
</Books>

Here is the problem, how to feed a xml formatter a correct input array like

[
  'books' => [
    'book' => [
       'title' => 'book1',
       'price' => 10.00,
    ],
    'book' => [
      'title' => 'book2',
      'price' => 15.00,
    ]
]

You can't have same keys in an array! I really don't know what to do, please help.

yasinkocak commented 9 years ago

This is the correct format array like

[
  'books' => [
    'book' => [
       [
         'title' => 'book1',
         'price' => 10.00,
       ],
       [
         'title' => 'book2',
         'price' => 10.00,
       ]
    ]
]
zishiguo commented 5 years ago

@yasinkocak if xml likes

<Books cate_id="123">
 <Book>
  <Title>Book1</Title>
  <Price>10.00</Price>
 </Book>
 <Book>
  <Title>Book2</Title>
  <Price>15.00</Price>
 </Book>
</Books>

how to do ?

zishiguo commented 5 years ago

@yasinkocak It's wrong. Output is

<books>
<book>
<title>book1</title><price>10</price>
<title>book2</title><price>10</price>
</book>
</books>