gatkin / declxml

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

Support for reading data from attributes on childless objects? #2

Closed BlacKCaT27 closed 7 years ago

BlacKCaT27 commented 7 years ago

After reading through the docs here:

http://declxml.readthedocs.io/en/latest/guide.html#attributes

I realized the error I was receiving earlier was due to me trying to read attributes as if they were elements.

However, the docs as linked above only show how to read an attribute from a child element to add an attribute to the parent. What if the element-in-question has no children?

Following the example code, say the XML looked like this:

How would one parse this xml with declxml such that the resulting output had "favoriteFood" with a value of pizza as an attribute of author?

BlacKCaT27 commented 7 years ago

For reference, I lucked into figuring this out. If you use "." for the element_name argument and speficy the attribute name as documented, you can retrieve the current element's attributes.

I would HIGHLY recommend this be added to the documentation.

gatkin commented 7 years ago

Yes, that is definitely a missing feature that needs to be added, and I also agree that the documentation needs to be updated as well to document how XPath syntax like "." can be used with declxml.