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

Parker convention is not implemented correctly #40

Open
AndreiPashkin opened this issue Feb 26, 2019 · 9 comments
Open

Parker convention is not implemented correctly #40

AndreiPashkin opened this issue Feb 26, 2019 · 9 comments

Comments

@AndreiPashkin
Copy link

It seems like the way of how the library converts XML using Parker convention differs from how it's defined originally in this repository:
https://github.com/doekman/xml2json-xslt

Here is the comparison:

Input data

<root>
    <person>
        <age>12</age>
        <height>1.73</height>
    </person>
    <person>
        <age>12</age>
        <height>1.73</height>
    </person>
</root>

Using xmltodict

Output:

{
    "person": [
        {
            "age": 12,
            "height": 1.73
        },
        {
            "age": 12,
            "height": 1.73
        }
    ]
}

Using XSLT document from the original Google repository

Output:

{
    "root":[
        {
            "age":12,
            "height":1.73
        },
        {
            "age":12,
            "height":1.73
        }
    ]
}
@dagwieers
Copy link
Contributor

dagwieers commented Feb 26, 2019

So xmljson (this project) returns this:

{
    "person": [
        {
            "age": 12,
            "height": 1.73
        }, {
            "age": 12,
            "height": 1.73
        }
    ]
}

Or this when using preserve_root=True:

{
    "root": {
        "person": [
            {
                "age": 12,
                "height": 1.73
            }, {
                "age": 12,
                "height": 1.73
            }
        ]
    }
}

To me the XSLT translation seems wrong, it removes information (i.e. the person sub-element).
Was there a question ?

@dagwieers
Copy link
Contributor

BTW Looking at the examples at https://github.com/doekman/xml2json-xslt/tree/master/unittests your depiction of what xml2json-xslt returns is incorrect, it does not turn the root-element into an element named root.

@AndreiPashkin
Copy link
Author

AndreiPashkin commented Feb 26, 2019

That repository is a reference implementation of Parker convention.

To me the XSLT translation seems wrong, it removes information (i.e. the person element).

I think it makes perfect sense, because in XML you usually have something like:

<people>
  <person>
    <name>John</name>
    <age>10</age>
  </person>
</people>

And in JSON you usually don't want to see {"people": {"person": [...]}} structure but {"people": [...]}.

your depiction of what xml2json-xslt returns is incorrect

I generated output examples using the XSLT file and xsltproc utility.

@AndreiPashkin
Copy link
Author

AndreiPashkin commented Feb 26, 2019

@dagwieers
Copy link
Contributor

dagwieers commented Feb 26, 2019

Root element seems to be preserved actually

@AndreiPashkin Exactly, so your example above is incorrect. And the output is the same as xmljson.

@dagwieers
Copy link
Contributor

And in JSON you usually don't want to see {"people": {"person": [...]}} structure but {"people": [...]}.

That seems very wrong. Why would someone want to see a sub-element (i.e. person) to disappear when doing a conversion? Why the first sub-element ?

@AndreiPashkin
Copy link
Author

AndreiPashkin commented Feb 26, 2019

That seems very wrong. Why would someone want to see a sub-element (i.e. person) to disappear when doing a conversion? Why the first sub-element ?

  1. Because why would you want to have people -> person structure? It is redundant.
  2. Because that's what developers expect from Parker convention implementation.

@AndreiPashkin Exactly, so your example above is incorrect. And the output is the same as xmljson.

Hm, that is correct. I don't why why xsltproc worked that way. But that's not important for me anyway, I filed the issue because of the above problem.

@dagwieers
Copy link
Contributor

dagwieers commented Feb 26, 2019

  1. Because why would you want to have people -> person structure? It is redundant.

The redundancy is in the original data, why would a conversion remove a sub-element layer. That doesn't make sense. A conversion has no semantics.

Maybe you were confused or your examples were wrong and you wanted to preserve/remove the root-element. That is possible with xmljson using preserve_root=True/False as my first example showed.

I filed the issue because of the above problem.

But there does not seem to be a problem, so can I close this issue ?

@AndreiPashkin
Copy link
Author

The redundancy is in the original data, why would a conversion remove a sub-element layer. That doesn't make sense. A conversion has no semantics.

In the original data there is no redundancy. How else would you express array of person-elements in XML? Only with person-tags. But in JSON equivalent of person-tags are dictionaries themselves.

Also - that's how Parker convention defines it. I think it makes sense to implement a standard according to the standard.

Repository owner deleted a comment from javadev May 15, 2023
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