0
<XMLReport><Report>
<Preflight errors="0" criticalfailures="0" noncriticalfailures="0" signoffs="0" fixes="0" warnings="10">
  <PreflightResult type="Check" level="warning">
    <PreflightResultEntry xml:lang="en-US">
      <Message>PDF/X-1a:20000 : PDF/X-1a:20000 output intent is missing </Message>
      <StringContext>
        <BaseString>PDF/X-1a:20000 : %PDFXVersion% output intent is missing</BaseString>
      </StringContext>
    </PreflightResultEntry>
  </PreflightResult>
</Preflight></Report>

我想<Message> </Message>在 Python 中使用 lxml 获取元素中的所有值/文本。

谢谢

4

1 回答 1

2

lxml tuto很容易:

>>> from lxml import etree
>>> s = """<Report>
<Preflight errors="0" criticalfailures="0" noncriticalfailures="0" signoffs="0" fixes="0" warnings="10">
  <PreflightResult type="Check" level="warning">
    <PreflightResultEntry xml:lang="en-US">
      <Message>PDF/X-1a:20000 : PDF/X-1a:20000 output intent is missing </Message>
      <StringContext>
        <BaseString>PDF/X-1a:20000 : %PDFXVersion% output intent is missing</BaseString>
      </StringContext>
    </PreflightResultEntry>
  </PreflightResult>
</Preflight></Report>
"""
>>> root = etree.XML(s)
>>> for message in root.findall('Preflight/PreflightResult/PreflightResultEntry/Message'):
    print message.text


PDF/X-1a:20000 : PDF/X-1a:20000 output intent is missing 
>>> 
于 2012-06-27T07:38:57.417 回答