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

Abdera child nodes incorrectly placed in same dictionaries #21

Closed
mattgd opened this issue Jun 17, 2017 · 1 comment
Closed

Abdera child nodes incorrectly placed in same dictionaries #21

mattgd opened this issue Jun 17, 2017 · 1 comment

Comments

@mattgd
Copy link

mattgd commented Jun 17, 2017

I seemed to have encountered a bug with the Abdera conversion logic, specifically how it converts children:

for child in children:
            child_data = self.data(child)
            if (count[child.tag] == 1
                    and len(children_list) > 1
                    and isinstance(children_list[-1], dict)):
                # Merge keys to existing dictionary
                children_list[-1].update(child_data)
            else:
                # Add additional text
                children_list.append(self.data(child))

When given the following XML data:

<?xml version="1.0" encoding="ISO-8859-1"?>
<Data
   version="9.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:noNamespaceSchemaLocation="comp.xsd">
    <Airport
      country="Samoa"
      city="Apia"
      name="Faleolo Intl"
      lat="-13.8296668231487"
      lon="-171.997166723013"
      alt="17.678M"
      ident="NSFA"
      >
      <Services>
    	 <Fuel
    		type="JETA"
    		availability="YES"/>
      </Services>
      <Tower
    	 lat="-13.8320958986878"
    	 lon="-171.998676359653"
    	 alt="0.0M">
      </Tower>
      <Runway
    	 lat="-13.8300792127848"
    	 lon="-172.008545994759"
    	 alt="17.678M"
    	 surface="ASPHALT"
    	 heading="89.3199996948242"
    	 length="2999.23M"
    	 width="45.11M"
    	 number="08"
    	 designator="NONE">
      </Runway>
    </Airport>
</Data>

I receive the following output from ab.data(xml_file):

{
    "Data": {
        "attributes": {
            "version": 9.0,
            "{http://www.w3.org/2001/XMLSchema-instance}noNamespaceSchemaLocation": "comp.xsd"
        },
        "children": [
            {
                "Airport": {
                    "attributes": {
                        "country": "Samoa",
                        "city": "Apia",
                        "name": "Faleolo Intl",
                        "lat": -13.8296668231487,
                        "lon": -171.997166723013,
                        "alt": "17.678M",
                        "ident": "NSFA"
                    },
                    "children": [
                        {
                            "Services": {
                                "Fuel": {
                                    "attributes": {
                                        "type": "JETA",
                                        "availability": "YES"
                                    }
                                }
                            }
                        },
                        {
                            "Tower": {
                                "attributes": {
                                    "lat": -13.8320958986878,
                                    "lon": -171.998676359653,
                                    "alt": "0.0M"
                                }
                            },
                            "Runway": {
                                "attributes": {
                                    "lat": -13.8300792127848,
                                    "lon": -172.008545994759,
                                    "alt": "17.678M",
                                    "surface": "ASPHALT",
                                    "heading": 89.3199996948242,
                                    "length": "2999.23M",
                                    "width": "45.11M",
                                    "number": 8,
                                    "designator": "NONE"
                                }
                            }
                        }
                    ]
                }
            }
        ]
    }
}

The first child node, Services, is placed into a separate dictionary, while the rest of the children are placed in the same dictionary. Because multiple tags with the same keys can be present in XML, all children should probably be placed in separate dictionaries.

I'm working on a PR for this, but if you happen to no what the problem is, let me know.

@mattgd mattgd changed the title Abdera first child node placed in separate dictionary Abdera child nodes incorrectly placed in same dictionaries Jun 18, 2017
@dagwieers
Copy link
Contributor

I guess this one should be closed now ?

@sanand0 sanand0 closed this as completed Aug 7, 2017
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