PreTeXtBook / pretext

PreTeXt: an authoring and publishing system for scholarly documents
https://pretextbook.org
Other
266 stars 208 forks source link

check for statement inside stage in extracted WW #1120

Closed Alex-Jordan closed 5 years ago

Alex-Jordan commented 5 years ago

In #1069 we started looking for a statement tag in extracted WW. Because my knowledge of tools for analyzing XML in Python is weak, I just found a way to check if there was a statement child of the root webwork and called it a day. But this neglected to account for when there is a stage, with the statement inside the stage, making the statement a grandchild of the root, not a child.

So we need a better way.

rbeezer commented 5 years ago

I like "lxml" but it does not seem to be part of standard Python. Sounds like ElementTree is not as powerful/complete.

While poking around, I found this, which sounded helpful for this particular problem, but I won't claim to have studied it very carefully for this particular case:

https://stackoverflow.com/questions/5373902/python-xml-query-get-parent

mitchkeller commented 5 years ago

The python documentation makes me think that

if problem_root.find('statement') is None:

can become

if problem_root.find('.//statement') is None:

since // from XPATH is supported and the example in the documentation says about //:

Selects all subelements, on all levels beneath the current element. For example, .//egg selects all egg elements in the entire tree.

rbeezer commented 5 years ago

That sounds right.

On 6/28/19 6:30 AM, Mitchel T. Keller wrote:

The python documentation makes me think that

|if problem_root.find('statement') is None:|

can become

|if problem_root.find('.//statement') is None:|

since |//| from XPATH is supported and the example in the documentation says about |//|:

Selects all subelements, on all levels beneath the current element. For
example, .//egg selects all egg elements in the entire tree.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/rbeezer/mathbook/issues/1120?email_source=notifications&email_token=AAOLM4VOAEPTUWX5HVO2EALP4YG6ZA5CNFSM4H4CBF72YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODY2CP3A#issuecomment-506734572, or mute the thread https://github.com/notifications/unsubscribe-auth/AAOLM4S7TFW2BANWWEFZVYLP4YG6ZANCNFSM4H4CBF7Q.

rbeezer commented 5 years ago

Fied at #1164