Parsing dtd file with lxml library (python)

2019-08-01 20:49发布

问题:

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>

?