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

Missing element values with unwrap() #6

Open
laurianvm opened this issue Apr 22, 2022 · 2 comments
Open

Missing element values with unwrap() #6

laurianvm opened this issue Apr 22, 2022 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@laurianvm
Copy link
Contributor

unwrap() (or copy()) of this example_xml:

<Element>
    <ChildA>value_a</ChildA>
     <ChildB namespace="I-am-an-attribute">value_b</ChildB>
</Element>

gives:

{
   "Element":{
      "ChildA":"value_a",
      "ChildB":{
         "@namespace":"I-am-an-attribute"
      }
   }
}

while you would expect something like this:

{
   "Element":{
      "ChildA":"value_a",
      "ChildB":{
         "@namespace":"I-am-an-attribute",
         "#value":"value_b"
      }
   }
}

or, when implementing 'flattening' as mentioned in vliz-be-opsci/pysubyt#4, something like this:

{
   "Element":{
      "ChildA":"value_a",
      "ChildB": "value_b",
      "ChildB.@namespace":"I-am-an-attribute"
      }
   }
@marc-portier
Copy link
Member

marc-portier commented May 4, 2022

retake on that last idea - I don´t think we will have the luxury to start this "flattening" half way down

meaning the final thing will be more like:

{ 
    "Element": " <ChildA>value_a</ChildA><ChildB namespace="I-am-an-attribute">value_b</ChildB>", 
    "Element.ChildA":"value_a",
    "Element.ChildB": "value_b",
    "Element.ChildB.@namespace":"I-am-an-attribute"
}

this could indeed be produced through some xdict.flatten()

additionally we would need to have some notation for nested lists: choosing now for **path.element[index] over **path.element.index.

having the xmlasdict- wrapper approac this means this .flatten() becomes available at any level you like. this means one could first navigate down xdb = xdict.ChildB and only then call flatten() which should just return

{ 
    "@namespace": "I-am-an-attribute"
} 

we could consider an extra 'flatten(self_prefix='_') to produce

{ 
    "_": value_b
    "_.@namespace": "I-am-an-attribute"
} 

which in tern might be the smart thing to do in order to resolve this in a recursive way!

@marc-portier
Copy link
Member

marc-portier commented May 9, 2022

Just came across https://github.com/bramstein/xsltjson which might give some general advise on how they solved things.
Specially their reference to the Badgerfish convention seems to be relevant here.

@cedricdcc cedricdcc added the bug Something isn't working label May 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants