Open kerimoyle opened 4 years ago
Parsing a model you have all the contextual information to be able to set all the required namespaces (https://github.com/cellml/libcellml/blob/develop/src/parser.cpp#L523). When a user calls setMath()
directly, it is up to them to make sure the required namespaces are defined. Pretty sure that should be in the docs...or it needs to be added :)
Hmmm ... that would mean that calling getMath()
and then setMath()
would break it? Shouldn't calling getMath()
just return the unadulterated string, rather than the one with the namespace added by the parser?
getMath()
returns the current math string - so get-then-set after parsing would be fine. I don't see an issue with the parser setting the namespaces in the math string when it parses a model, that is also what any user code should be doing. Otherwise there is no way to know what prefix has been used in the namespaces - you definitely can't and shouldn't assume, for example, that a cellml
namespace prefix has been defined and is the CellML 2.0 namespace (as you are doing in your "fixed" MathML string).
There's a difference in behaviour between parsing a model's math and setting it through the API. This test prints two different MathML strings, and the "fixed" one doesn't have the cellml namespace added, so generates all kinds of libxml2 validation errors. I think it should be treated consistently between the two - either specifying the namespace on the model or on the MathML, but not depending on whether it's done through the parser or the component->setMath function.
The parser reads this file (note location of namespaces):
This prints:
Prints:
... with validation errors of:
Error 1: LibXml2 error: Namespace prefix cellml for units on cn is not defined. Error 2: CellML identifiers must contain one or more basic Latin alphabetic characters. Error 3: Math cn element with the value '3' does not have a valid cellml:units attribute. Error 4: W3C MathML DTD error: Namespace prefix cellml for units on cn is not defined. Error 5: W3C MathML DTD error: No declaration for attribute cellml:units of element cn.