一点背景:在Sphinx需求管理插件的范围内,我正在研究导出ReqIF XML内容的方法。我找到了pyreqif,但发现它目前还不足以满足我们的需要
我决定研究一下pyXB生成的Reqif绑定,因为pyXB可以完成所有与XML之间的转换工作,我只需要担心添加一些方便的函数/类
可以在此处找到该项目:https://github.com/bavovanachte/reqif_pyxb_tryout
到目前为止,一切进展顺利:我已经成功地创建了所有对象的实例,它们很好地结合在一起,形成了一个xml文档。我唯一遇到的问题是XHTML内容的创建。理想情况下,我希望获取现有的html内容并将其插入到树中。 naieve的这种做法导致xml不安全字符被转义,因此无法工作
以下是我的一些尝试:
xml_string = '''
<div>
XY Block Adapter shall translate the Communication to TMN-Block in a bidirectional manner and support all functionalities of a TMN-Block.<br/>
</div>'''
att_value_xhtml = ATTRIBUTE_VALUE_XHTML(definition=text_attribute, THE_VALUE=XHTML_CONTENT(div=xml_string))
<div>
XY Block Adapter shall translate the Communication to TMN-Block in a bidirectional manner and support all functionalities of a TMN-Block.<br/>
</div></ns2:div>
xml_string = '''
<div>
XY Block Adapter shall translate the Communication to TMN-Block in a bidirectional manner and support all functionalities of a TMN-Block.<br/>
</div>'''
att_value_xhtml = ATTRIBUTE_VALUE_XHTML(definition=text_attribute, THE_VALUE=XHTML_CONTENT(xml_string, _from_xml=True))
Traceback (most recent call last):
File "examples/export_test.py", line 105, in <module>
att_value_xhtml = ATTRIBUTE_VALUE_XHTML(definition=text_attribute, THE_VALUE=XHTML_CONTENT(xml_string, _from_xml=True))
File "/home/bvn/.pyenv/versions/3.6.10/lib/python3.6/site-packages/pyxb/binding/basis.py", line 2127, in __init__
self.extend(args, _from_xml=from_xml, _location=location)
File "/home/bvn/.pyenv/versions/3.6.10/lib/python3.6/site-packages/pyxb/binding/basis.py", line 2612, in extend
[ self.append(_v, **kw) for _v in value_list ]
File "/home/bvn/.pyenv/versions/3.6.10/lib/python3.6/site-packages/pyxb/binding/basis.py", line 2612, in <listcomp>
[ self.append(_v, **kw) for _v in value_list ]
File "/home/bvn/.pyenv/versions/3.6.10/lib/python3.6/site-packages/pyxb/binding/basis.py", line 2588, in append
raise pyxb.MixedContentError(self, value, location)
pyxb.exceptions_.MixedContentError: Invalid non-element content
xml_string = '''
<div>
XY Block Adapter shall translate the Communication to TMN-Block in a bidirectional manner and support all functionalities of a TMN-Block.<br/>
</div>'''
att_value_xhtml = ATTRIBUTE_VALUE_XHTML(definition=text_attribute, THE_VALUE=XHTML_CONTENT(div=xhtml_div_type(xml_string, _from_xml=True)))
<div>
XY Block Adapter shall translate the Communication to TMN-Block in a bidirectional manner and support all functionalities of a TMN-Block.<br/>
</div></ns2:div>
xml_string = '''
<div>
XY Block Adapter shall translate the Communication to TMN-Block in a bidirectional manner and support all functionalities of a TMN-Block.<br/>
</div>'''
dom_content = xml.dom.minidom.parseString('<myxml>Some data<empty/> some more data</myxml>')
att_value_xhtml = ATTRIBUTE_VALUE_XHTML(definition=text_attribute, THE_VALUE=XHTML_CONTENT(div=xhtml_div_type(_dom_node=dom_content)))
Unable to convert DOM node empty at [UNAVAILABLE] to binding
Traceback (most recent call last):
File "examples/export_test.py", line 130, in <module>
att_value_xhtml = ATTRIBUTE_VALUE_XHTML(definition=text_attribute, THE_VALUE=XHTML_CONTENT(div=xhtml_div_type(_dom_node=dom_content)))
File "/home/bvn/.pyenv/versions/3.6.10/lib/python3.6/site-packages/pyxb/binding/basis.py", line 2133, in __init__
self.extend(dom_node.childNodes[:], fallback_namespace)
File "/home/bvn/.pyenv/versions/3.6.10/lib/python3.6/site-packages/pyxb/binding/basis.py", line 2612, in extend
[ self.append(_v, **kw) for _v in value_list ]
File "/home/bvn/.pyenv/versions/3.6.10/lib/python3.6/site-packages/pyxb/binding/basis.py", line 2612, in <listcomp>
[ self.append(_v, **kw) for _v in value_list ]
File "/home/bvn/.pyenv/versions/3.6.10/lib/python3.6/site-packages/pyxb/binding/basis.py", line 2567, in append
raise pyxb.UnrecognizedContentError(self, self.__automatonConfiguration, value, location)
pyxb.exceptions_.UnrecognizedContentError: Invalid content empty (expect {http://www.w3.org/1999/xhtml}h1 or {http://www.w3.org/1999/xhtml}h2 or ...
处理xhtml内容的正确方法是什么
目前没有回答
相关问题 更多 >
编程相关推荐