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

Failed to parse XML #34

Closed
tgoettel9401 opened this issue Sep 3, 2016 · 9 comments
Closed

Failed to parse XML #34

tgoettel9401 opened this issue Sep 3, 2016 · 9 comments

Comments

@tgoettel9401
Copy link

Hey guys,

I am using the package in a small Laravel Website I am creating for a chess club. Today I ran composer update which was updated the following packages:

  • Symfony/yaml from 3.1.3 to 3.1.4
  • Nathanmac/parser from 4.0 to 4.1
  • Symfony/class-loader from 3.1.3 to 3.1.4
  • Symfony/event-dispatcher from 3.1.3 to 3.1.4

While I was still using parser version 4.0 I was able to import and parse the XML File from [https://ssl-account.com/sbrp-ergebnisdienst.de/index.php?p1=0:ee:BK6-16&style=2]. Therefore I am simply using the following code:

$xml = file_get_contents($url); $xmlArray = Parser::xml($xml);

Unfortunately since I updated the package to 4.1 I get a ParserException in XML.php line 33: Failed To Parse XML. However it was working before and I do not understand the changes.

I would really appreciate your help guys.

Thanks!
Tobias

@danhunsaker
Copy link
Contributor

Interesting result. It shouldn't have had any issues, so I'll have to do some deep inspection of the code with your sample XML. I may have inadvertently introduced a bug somewhere we don't yet properly test for.

@mubinov
Copy link
Contributor

mubinov commented Sep 3, 2016

Hi!

More info about this issue:
in my case error occurs here: https://github.com/nathanmac/Parser/blob/master/src/Formats/XML.php#L68
Error message: Illegal string offset "..."

Thanks

@danhunsaker
Copy link
Contributor

@mubinov - do you have sample XML that causes this error?

@mubinov
Copy link
Contributor

mubinov commented Sep 3, 2016

$xml = '<Info> <Reader> <num>1111</num> </Reader> </Info>';
\Parser::xml($xml);

Error: Illegal string offset 'num'

@mubinov
Copy link
Contributor

mubinov commented Sep 3, 2016

This code works well:

$xml = '<Info><Reader><num>1111</num></Reader></Info>';
\Parser::xml($xml);

i.e. without any spaces and new lines

@danhunsaker
Copy link
Contributor

Ah. Right. Got it. Stupid mistake; easy fix. I'll try to get that taken care of as soon as I have my laptop out.

@tgoettel9401
Copy link
Author

Great guys, thank you for fixing this issue! :)

@danhunsaker
Copy link
Contributor

It hasn't been merged yet, but it looks good, now. Should be in 4.2, though this change totally fits the definition of a 4.1.1 under SemVer.

nathanmac added a commit that referenced this issue Sep 7, 2016
Checking XML for spaces and new lines. Fixed #34
@JoshuaVR
Copy link

JoshuaVR commented Mar 9, 2018

I think this update has created an unintended bug as I have discovered the root tag is taken as the last tag at the first tab indent not the opening tag.

here is an example:

<?xml version="1.0" encoding="utf-8"?>
<Orders>
<Order>
    <Meta>
        ....
    </Meta>
    <Header>
        ....
    </Header>
    ....
</Order>
</Orders>

results with array of:

'Meta' => 
  array (
   ....
  ),
 'Header' => 
  array (
   ....
  )

As you can see it completely ignores the '' tag.

However if you indent the Order tag it includes it.

A fix for this would be appreciated

Thanks

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

4 participants