non existent empty attribute

Bug #1783012 reported by Dmitry Melnikov on 2018-07-22
This bug affects 1 person
Affects Status Importance Assigned to Milestone

Bug Description

I have a env.xml like:

<?xml version="1.0"?>
   <var name="A" value="1" />
   <var name="B" value="2" />

and env.xsd

<?xml version=1.0?>
<xs:schema xmlns:xs=>

   <xs:simpleType name=non_empty_string_type>
      <xs:restriction base=xs:string>
         <xs:minLength value=1 />

   <xs:element name=environment>
            <xs:element name=var minOccurs=0 maxOccurs=unbounded>
                  <xs:attribute name=name type=non_empty_string_type use=required />
                  <xs:attribute name=value type=xs:string use=required />
      <xs:unique name=uniqueName>
         <xs:selector xpath=var/>
         <xs:field xpath=@name/>


It works well with
xmllint --schema env.xsd env.xml

<?xml version="1.0"?>
   <var name="A" value="1"/>
   <var name="B" value="2"/>
env.xml validates

but failed with lxml

from lxml import etree


schema = etree.XMLSchema(file=env_xsd, attribute_defaults=True)
xmlparser = etree.XMLParser(schema=schema)
with open(env_xml) as f:
        etree.fromstring(, xmlparser)

Traceback (most recent call last):
  File "", line 9, in <module>
    etree.fromstring(, xmlparser)
  File "src/lxml/lxml.etree.pyx", line 3213, in lxml.etree.fromstring (src/lxml/lxml.etree.c:82934)
  File "src/lxml/parser.pxi", line 1819, in lxml.etree._parseMemoryDocument (src/lxml/lxml.etree.c:124533)
  File "src/lxml/parser.pxi", line 1700, in lxml.etree._parseDoc (src/lxml/lxml.etree.c:122964)
  File "src/lxml/parser.pxi", line 1040, in lxml.etree._BaseParser._parseUnicodeDoc (src/lxml/lxml.etree.c:116705)
  File "src/lxml/parser.pxi", line 573, in lxml.etree._ParserContext._handleParseResultDoc (src/lxml/lxml.etree.c:110510)
  File "src/lxml/parser.pxi", line 683, in lxml.etree._handleParseResult (src/lxml/lxml.etree.c:112276)
  File "src/lxml/parser.pxi", line 613, in lxml.etree._raiseParseError (src/lxml/lxml.etree.c:111124)
lxml.etree.XMLSyntaxError: Element 'var': Duplicate key-sequence [''] in unique identity-constraint 'uniqueName'.

Python : sys.version_info(major=3, minor=5, micro=2, releaselevel='final', serial=0)
lxml.etree : (3, 5, 0, 0)
libxml used : (2, 9, 4)
libxml compiled : (2, 9, 2)
libxslt used : (1, 1, 28)
libxslt compiled : (1, 1, 28)

scoder (scoder) wrote :

More likely related to the libxml2 version than lxml.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers