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

Ignoring undefined namespaces? #156

Open
anandijain opened this issue Mar 11, 2021 · 3 comments
Open

Ignoring undefined namespaces? #156

anandijain opened this issue Mar 11, 2021 · 3 comments

Comments

@anandijain
Copy link

julia> str = """<cn type="e-notation" cellml:units="molar_per_minute">5   <sep/>-2</cn>"""
"<cn type=\"e-notation\" cellml:units=\"molar_per_minute\">5   <sep/>-2</cn>"

julia> parsexml(str)
EzXML.Document(EzXML.Node(<DOCUMENT_NODE@0x0000000002880610>))

julia> parsexml(str).root
ERROR: AssertionError: isempty(XML_GLOBAL_ERROR_STACK)

I have snippets of an XML Document resulting from a findall("//x:math", node, ["x"=>"http://www.w3.org/1998/Math/MathML"]), but these nodes have references to namespaces defined elsewhere.

I'm wondering if I can ignore the undefined namespace, basically remove all cellml: attributes from a Document.

I suppose I could do findall("//*[@cellml:*]", node) and then just delete! the attributes.
This is sort of an annoying hack, as other documents might have other namespaces.

@anandijain
Copy link
Author

Another frustrating issue with XML_GLOBAL_ERROR_STACK is that it requires a restart of Julia to clear. I don't really see why though. If I call the above MWE, then try to parsexml a valid XML string with no namespace, I cannot parse it.

@jvkerckh
Copy link

jvkerckh commented Sep 7, 2022

Another frustrating issue with XML_GLOBAL_ERROR_STACK is that it requires a restart of Julia to clear. I don't really see why though. If I call the above MWE, then try to parsexml a valid XML string with no namespace, I cannot parse it.

I've run into the same issue when parsing something as simple as <p :foo="bar">content</p>, and I've found that you can circumvent the Julia restart requirement by using empty!(EzXML.XML_GLOBAL_ERROR_STACK) though this is hardly an ideal solution.

@JZL
Copy link

JZL commented Feb 9, 2023

Ooh thanks @jvkerckh I didn't put together than the global stack never is never cleared. This is pretty tricky because I was reading through XML files in a loop (parallelized to make it more complicated) with a try catch block to let errors be logged but not stop execitatopm. But as soon as one document errored, the rest in that session would as well because of the shared global

I feel like it would be very helpful if that was documented, or in the @assert when the error is declared, have an extra message reminding people to clear the variable before parsing a new document.

Otherwise a very useful package :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants