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

XML empty field becomes [] #8

Closed
Glasya opened this issue Jul 3, 2015 · 2 comments
Closed

XML empty field becomes [] #8

Glasya opened this issue Jul 3, 2015 · 2 comments

Comments

@Glasya
Copy link

Glasya commented Jul 3, 2015

Hi,

I don't know wether i'm doing something wrong here or forgetting something but heres the weird thing.
When parsing an .xml file, if a field is empty it gets translated to an empty array, my guess is this is due to a multi-array functionality.

For instance this is my XML:

<?xml version="1.0" encoding="UTF-8"?>
<request>
 <company></company>
 <first_name>Joe</first_name>
 <insertion></insertion>
 <last_name>Dirt</last_name>
 <gender>0</gender>  <!-- 0=male/ 1=female-->
 <street>Somestreet</street>
 <street_number>13</street_number>
 <number_adjective></number_adjective>
 <zipcode>0000AA</zipcode>
 <city>Denver</city>
 <email1>j.dirt@somedomain.com</email1>
 <email2></email2>
 <contact_preference>3</contact_preference>  <!-- 1=morning / 2=midday / 3=evening -->
 <home_phone>0123456789</home_phone>
 <mobile>0612345678</mobile>
 <remarks>Some text here</remarks>
 <date>2015-07-03</date>  <!-- MySQL date format -->
 <source_id>1</source_id> <!-- Internal unique number from supplier -->
 <source_api>1234567890</source_api> <!-- API key -->
</request>

I am loading it with: $xml = Parser::xml(File::get($filename));
when doing a dd($xml); it gives me something like:

company = []
first_name = Joe
insertion = []
last_name = Dirt
gender = 0
street = Somestreet
street_number = 13
etc.

When inserting it in the database i get values named Array.

Is there any easy way for me to force empty fields to empty instead of array types?

@nathanmac
Copy link
Owner

@Glasya - If you use release 3.6 it is fixed and now returns a null value not an empty array.

Thanks for point out the issue.

@sivpro
Copy link

sivpro commented Aug 1, 2016

Use version 2* (with laravel 4). Array is present if empty field.

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