PyXB:生成 class Unicode 名称

PyXB: generating class names in Unicode

当元素名称不是 ASCII 时,我无法生成绑定 类 和 PyXB,有人能给我指出正确的方向吗?

最小可重现示例:

<?xml version="1.0" encoding="utf8"?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Address">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Country" type="xs:string" />
        <xs:element name="Street" type="xs:string" />
        <xs:element name="Town" type="xs:string" />       
        <xs:element name="Дом" type="xs:string" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

(寻找我使用西里尔字母的 <xs:element name="Дом" type="xs:string" />。 文件的编码是utf8。 但是,当我尝试时:

pyxbgen -u example.xsd -m example

我收到错误:

Traceback (most recent call last):
  File "/home/sergey/anaconda3/lib/python3.5/xml/sax/expatreader.py", line 210, in feed
    self._parser.Parse(data, isFinal)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 9, column 26

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/sergey/anaconda3/bin/pyxbgen", line 52, in <module>
    generator.resolveExternalSchema()
.......

指向元素的西里尔字母名称。我错过了什么?

UTF8 在 XML 和 Python 中拼写为 "utf-8"

lilith[33]$ head -1 /tmp/cyr.xsd 
<?xml version="1.0" encoding="utf-8"?>
lilith[34]$ pyxbgen -u /tmp/cyr.xsd -m cyr
WARNING:pyxb.binding.generate:Element use None.Дом renamed to emptyString
Python for AbsentNamespace0 requires 1 modules

PyXB 生成一个名为 emptystring 的元素而不是一个名为 Дом 的元素是个问题。 PyXB 的设计早在 Python 3 和 unicode 支持之前就已设计完成,它会努力将文本转换为有效的 Python 2 标识符。

由于您使用的是 Python 3,因此应该可以绕过该转换,但这并非微不足道。跟踪日语的 issue 67, or if there's a Cyrillic transliteration you prefer the technique demonstrated here 可能有效。