mathml schema problem
I'm trying to create xml elements from strings marked up as mathml, and I'm using the mathml3 schema as follows. I'm working in the same directory as the xsd files; I generate the schema object and the parser, but the parser complains about the entities in the marked-up string. What am I doing wrong? thanks, --Tim % ls mathml3-common.xsd* mathml3-presentation.xsd* mathml3.xsd* mathml3-content.xsd* mathml3-strict-content.xsd* % python Python 2.7.1 (r271:86832, Apr 5 2011, 13:19:14) [GCC 4.2.1 20070719 [FreeBSD]] on freebsd8 Type "help", "copyright", "credits" or "license" for more information.
from lxml import etree xsd = 'mathml3.xsd' schema = etree.XMLSchema(etree.parse(xsd)) parser = etree.XMLParser(schema=schema) m = '''<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> <mstyle displaystyle="true"> <mo>=</mo> <mi>t</mi> <mo>−</mo> <mi>j</mi> </mstyle> </math>''' etree.fromstring(m,parser) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "lxml.etree.pyx", line 2756, in lxml.etree.fromstring (src/lxml/lxml.etree.c:54657) File "parser.pxi", line 1578, in lxml.etree._parseMemoryDocument (src/lxml/lxml.etree.c:82774) File "parser.pxi", line 1457, in lxml.etree._parseDoc (src/lxml/lxml.etree.c:81572) File "parser.pxi", line 965, in lxml.etree._BaseParser._parseDoc (src/lxml/lxml.etree.c:78242) File "parser.pxi", line 569, in lxml.etree._ParserContext._handleParseResultDoc (src/lxml/lxml.etree.c:74498) File "parser.pxi", line 650, in lxml.etree._handleParseResult (src/lxml/lxml.etree.c:75389) File "parser.pxi", line 590, in lxml.etree._raiseParseError (src/lxml/lxml.etree.c:74722) lxml.etree.XMLSyntaxError: Entity 'minus' not defined, line 1, column 67
Hi Tim, I don't think XSD supports entity references apart from the five ones generic to XML, so − can't be part of a valid XML doc under that schema. I think only DTD permits the declaration of entity references. Chuck On Thu, Jul 19, 2012 at 11:08 AM, Tim Arnold <Tim.Arnold@sas.com> wrote:
I'm trying to create xml elements from strings marked up as mathml, and I'm using the mathml3 schema as follows. I'm working in the same directory as the xsd files; I generate the schema object and the parser, but the parser complains about the entities in the marked-up string.
What am I doing wrong?
thanks,
--Tim
% ls
mathml3-common.xsd* mathml3-presentation.xsd* mathml3.xsd*
mathml3-content.xsd* mathml3-strict-content.xsd*
% python
Python 2.7.1 (r271:86832, Apr 5 2011, 13:19:14)
[GCC 4.2.1 20070719 [FreeBSD]] on freebsd8
Type "help", "copyright", "credits" or "license" for more information.
from lxml import etree
xsd = 'mathml3.xsd'
schema = etree.XMLSchema(etree.parse(xsd))
parser = etree.XMLParser(schema=schema)
m = '''<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mstyle displaystyle="true">
<mo>=</mo>
<mi>t</mi>
<mo>−</mo>
<mi>j</mi>
</mstyle>
</math>'''
etree.fromstring(m,parser)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "lxml.etree.pyx", line 2756, in lxml.etree.fromstring (src/lxml/lxml.etree.c:54657)
File "parser.pxi", line 1578, in lxml.etree._parseMemoryDocument (src/lxml/lxml.etree.c:82774)
File "parser.pxi", line 1457, in lxml.etree._parseDoc (src/lxml/lxml.etree.c:81572)
File "parser.pxi", line 965, in lxml.etree._BaseParser._parseDoc (src/lxml/lxml.etree.c:78242)
File "parser.pxi", line 569, in lxml.etree._ParserContext._handleParseResultDoc (src/lxml/lxml.etree.c:74498)
File "parser.pxi", line 650, in lxml.etree._handleParseResult (src/lxml/lxml.etree.c:75389)
File "parser.pxi", line 590, in lxml.etree._raiseParseError (src/lxml/lxml.etree.c:74722)
lxml.etree.XMLSyntaxError: Entity 'minus' not defined, line 1, column 67
_________________________________________________________________ Mailing list for the lxml Python XML toolkit - http://lxml.de/ lxml@lxml.de https://mailman-mail5.webfaction.com/listinfo/lxml
Thanks for your quick reply Chuck. I should have read the xsd more carefully. the minus *element* is declared but not the entity. thanks, --Tim -----Original Message----- From: Chuck Bearden [mailto:cfbearden@gmail.com] Sent: Thursday, July 19, 2012 12:13 PM To: Tim Arnold Cc: lxml@lxml.de Subject: Re: [lxml] mathml schema problem Hi Tim, I don't think XSD supports entity references apart from the five ones generic to XML, so − can't be part of a valid XML doc under that schema. I think only DTD permits the declaration of entity references. Chuck On Thu, Jul 19, 2012 at 11:08 AM, Tim Arnold <Tim.Arnold@sas.com> wrote:
I'm trying to create xml elements from strings marked up as mathml, and I'm using the mathml3 schema as follows. I'm working in the same directory as the xsd files; I generate the schema object and the parser, but the parser complains about the entities in the marked-up string.
What am I doing wrong?
thanks,
--Tim
% ls
mathml3-common.xsd* mathml3-presentation.xsd* mathml3.xsd*
mathml3-content.xsd* mathml3-strict-content.xsd*
% python
Python 2.7.1 (r271:86832, Apr 5 2011, 13:19:14)
[GCC 4.2.1 20070719 [FreeBSD]] on freebsd8
Type "help", "copyright", "credits" or "license" for more information.
from lxml import etree
xsd = 'mathml3.xsd'
schema = etree.XMLSchema(etree.parse(xsd))
parser = etree.XMLParser(schema=schema)
m = '''<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mstyle displaystyle="true">
<mo>=</mo>
<mi>t</mi>
<mo>−</mo>
<mi>j</mi>
</mstyle>
</math>'''
etree.fromstring(m,parser)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "lxml.etree.pyx", line 2756, in lxml.etree.fromstring (src/lxml/lxml.etree.c:54657)
File "parser.pxi", line 1578, in lxml.etree._parseMemoryDocument (src/lxml/lxml.etree.c:82774)
File "parser.pxi", line 1457, in lxml.etree._parseDoc (src/lxml/lxml.etree.c:81572)
File "parser.pxi", line 965, in lxml.etree._BaseParser._parseDoc (src/lxml/lxml.etree.c:78242)
File "parser.pxi", line 569, in lxml.etree._ParserContext._handleParseResultDoc (src/lxml/lxml.etree.c:74498)
File "parser.pxi", line 650, in lxml.etree._handleParseResult (src/lxml/lxml.etree.c:75389)
File "parser.pxi", line 590, in lxml.etree._raiseParseError (src/lxml/lxml.etree.c:74722)
lxml.etree.XMLSyntaxError: Entity 'minus' not defined, line 1, column 67
_________________________________________________________________ Mailing list for the lxml Python XML toolkit - http://lxml.de/ lxml@lxml.de https://mailman-mail5.webfaction.com/listinfo/lxml
participants (2)
-
Chuck Bearden
-
Tim Arnold