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

pxx-13 Duplicate errors due to long element names #19

Open
mluis7 opened this issue Apr 18, 2024 · 0 comments
Open

pxx-13 Duplicate errors due to long element names #19

mluis7 opened this issue Apr 18, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@mluis7
Copy link
Owner

mluis7 commented Apr 18, 2024

UPDATE:
Reported as libxml2 bug since xmllint shows same behavior.
https://gitlab.gnome.org/GNOME/libxml2/-/issues/715

Long element names may cause some duplicate and count errors while parsing

ERROR: duplicated path: /xbrli:xbrl/in-bse-cg:AggregateValueOfSecurityProvidedDuringSixMonthsOfSecurityInConnectionWithLoanOrAnyOtherD
...
ERROR: 0 elements found with /xbrli:xbrl/in-bse-cg:AggregateAmountAdvancedDuringSixMonthsOfAnyLoanOrAnyOtherFormOfDebtToPromoterOrAnyOtherE xpath expression.
Original xpath: /xbrli:xbrl/in-bse-cg:AggregateAmountAdvancedDuringSixMonthsOfAnyLoanOrAnyOtherFormOfDebtToPromoterOrAnyOtherE

Cause:
tree.getpath(ele) truncates the returned path to 110 characters.

Possible fix:
tree.getelementpath(ele)

Reproduce
Given an XML with namespaces

<root xmlns:ns="http://example.com/ns">
    <ns:a01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678z01234567890123456789012345678x>1</ns:a01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678z01234567890123456789012345678x>
</root>
>>> from lxml import etree

>>> xtree = etree.parse('tmp.xml')
>>> root = xtree.getroot()

truncated path


>>> xtree.getpath(root.getchildren()[0])
'/root/ns:a0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123'

complete path with tree.getelementpath()


>>> xtree.getelementpath(root.getchildren()[0])
'{http://example.com/ns}a01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678z01234567890123456789012345678x'

While trying to report an lxml bug I found that it's an libxml2 bug as xmllint shows the same behavior

xmllint --shell tmp.xml
/ > du
/
root
  ns:a01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678z01234567890123456789012345678x
/ > setrootns
/ > setns default=
/ > setns ns=http://example.com/ns
/ > whereis //ns:a01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678z01234567890123456789012345678x
/root/ns:a0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123
@mluis7 mluis7 added the bug Something isn't working label Apr 18, 2024
@mluis7 mluis7 self-assigned this Apr 18, 2024
@mluis7 mluis7 changed the title Duplicate errors due to long element names pxx-13 Duplicate errors due to long element names Apr 18, 2024
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

1 participant