Parsing dtd file with lxml library (python)

帅比萌擦擦* 提交于 2019-12-11 12:17:12

问题


I need your help. I use lxml library to parsing dtd file.

How can i get c subexpression in this example?

dtd = etree.DTD(StringIO('<!ELEMENT a (b,c,d)>'))

I try this

content = dtd.elements()[0].content

left, right = content.left, content.right

but it left of right subexpression.

http://lxml.de/validation.html#id1


回答1:


I'm completely guessing (I've never touched this before) but:

from io import StringIO
from lxml import etree

dtd.elements()[0].content.right.left
#>>> <lxml.etree._DTDElementContentDecl object name='c' type='element' occur='once' at 0x7f6999a28250>

?



来源:https://stackoverflow.com/questions/18930244/parsing-dtd-file-with-lxml-library-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!