gatkin / declxml

Declarative XML processing for Python
https://declxml.readthedocs.io/en/latest/
MIT License
37 stars 7 forks source link

Access a node's parent attribute #8

Open marnunez opened 6 years ago

marnunez commented 6 years ago

Hi! Is this funcionality implemented?

xml.integer('..', attribute='nFrames', alias='_nFrames')]

I need for each child to have a copy of its parent "nFrames" attribute. Is this achievable with XPath?

gatkin commented 6 years ago

I think that should be possible, but it would be good to add some tests to verify it is possible. One thing we would need to consider is what to do when serializing the value since we will have multiple items referring to the same attribute. Do we let the first value we encounter win and make that the value of the attribute when serializing? What do we do if the items that should serialize to the same attribute have different values?

marnunez commented 6 years ago

I think it should be the last item serialized that defines its parent's attribute, just like with normal variables. I'm not sure how this is implemented in other parsers.