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 Parsing and attributes #27

Closed
soderluk opened this issue Apr 14, 2016 · 2 comments
Closed

XML Parsing and attributes #27

soderluk opened this issue Apr 14, 2016 · 2 comments

Comments

@soderluk
Copy link

When using the XML parser, it does not take into account any attributes that might have been defined for an element.

Example:

<?xml version="1.0" encoding="UTF-8"?>
<books>
  <book>
    <title>Example</title>
    <author>Author</author>
    <price currency="EUR">25.50</price>
  </book>
</books>

The price attribute currency is nowhere to be found in the resulting PHP array.

Has there been any discussion on how to tackle this issue? That is a pretty important part of XML parsing, to be able to get the attributes of elements.

Thanks!

@danhunsaker
Copy link
Contributor

Converting SimpleXML to an array (whether via JSON encode/decode or not) loses a lot of information, mostly because of how SimpleXML implements array conversion internally. Because it treats child elements as object properties, but attributes as array keys, converting to a simple array creates somewhat of a conflict in how to maintain this distinction, so the SimpleXML developers opted to simply discard attributes as being generally less important than contents.

Because this project is meant to abstract away, somewhat, the format used to input the data, so you can work with that data consistently regardless of how it was presented, it can only support the features of the simplest input type (which is probably Query String, meaning everything will be an array).

If you definitely need something more advanced, and the abstraction layer isn't all that important to you, consider using SimpleXML directly.

@soderluk
Copy link
Author

soderluk commented Jul 5, 2016

Thanks for the reply!
I went on and used SimpleXML directly for my parsing purposes.

@soderluk soderluk closed this as completed Jul 5, 2016
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

2 participants