Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Same key problem when generating XML string #29

Open
chris-peng-1244 opened this issue Apr 28, 2015 · 3 comments
Open

Same key problem when generating XML string #29

chris-peng-1244 opened this issue Apr 28, 2015 · 3 comments

Comments

@chris-peng-1244
Copy link

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
Copy link

This is the correct format array like

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

@zishiguo
Copy link

zishiguo commented Sep 15, 2018

@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
Copy link

@yasinkocak It's wrong. Output is

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants