从组标签中获取字符串文本
Get string text from a group tag
我想获取组标签的内容字符串xml
例如 xml:
<retEvento versao="1.00" xmlns="http://www.portalfiscal.inf.br/nfe">
<infEvento>
<tpAmb>2</tpAmb>
<verAplic>SVRSnfce201808211044</verAplic>
<cOrgao>22</cOrgao>
<cStat>135</cStat>
<xMotivo>Evento registrado e vinculado a NF-e</xMotivo>
<chNFe>XXXXXXXXXXXXXXXXXXXXXXXXXXX</chNFe>
<tpEvento>110111</tpEvento>
<nSeqEvento>1</nSeqEvento>
<dhRegEvento>2019-04-17T15:59:45-03:00</dhRegEvento>
<nProt>YYYYYYYYYYYYYYY</nProt>
</infEvento>
</retEvento>
我想获取 infEvento 组的字符串内容。像这样:
<infEvento>
<tpAmb>2</tpAmb>
<verAplic>SVRSnfce201808211044</verAplic>
<cOrgao>22</cOrgao>
<cStat>135</cStat>
<xMotivo>Evento registrado e vinculado a NF-e</xMotivo>
<chNFe>XXXXXXXXXXXXXXXXXXXXXXXXXXX</chNFe>
<tpEvento>110111</tpEvento>
<nSeqEvento>1</nSeqEvento>
<dhRegEvento>2019-04-17T15:59:45-03:00</dhRegEvento>
<nProt>YYYYYYYYYYYYYYY</nProt>
</infEvento>
我试试这个:
ns = {'ns':'http://www.portalfiscal.inf.br/nfe'}
el.xpath('//ns:retEvento',namespaces=ns)[0].text
但我一无所获:(
尝试使用 tostring
方法。
etree.tostring(el.xpath('//ns:retEvento',namespaces=ns)[0])
我想获取组标签的内容字符串xml
例如 xml:
<retEvento versao="1.00" xmlns="http://www.portalfiscal.inf.br/nfe">
<infEvento>
<tpAmb>2</tpAmb>
<verAplic>SVRSnfce201808211044</verAplic>
<cOrgao>22</cOrgao>
<cStat>135</cStat>
<xMotivo>Evento registrado e vinculado a NF-e</xMotivo>
<chNFe>XXXXXXXXXXXXXXXXXXXXXXXXXXX</chNFe>
<tpEvento>110111</tpEvento>
<nSeqEvento>1</nSeqEvento>
<dhRegEvento>2019-04-17T15:59:45-03:00</dhRegEvento>
<nProt>YYYYYYYYYYYYYYY</nProt>
</infEvento>
</retEvento>
我想获取 infEvento 组的字符串内容。像这样:
<infEvento>
<tpAmb>2</tpAmb>
<verAplic>SVRSnfce201808211044</verAplic>
<cOrgao>22</cOrgao>
<cStat>135</cStat>
<xMotivo>Evento registrado e vinculado a NF-e</xMotivo>
<chNFe>XXXXXXXXXXXXXXXXXXXXXXXXXXX</chNFe>
<tpEvento>110111</tpEvento>
<nSeqEvento>1</nSeqEvento>
<dhRegEvento>2019-04-17T15:59:45-03:00</dhRegEvento>
<nProt>YYYYYYYYYYYYYYY</nProt>
</infEvento>
我试试这个:
ns = {'ns':'http://www.portalfiscal.inf.br/nfe'}
el.xpath('//ns:retEvento',namespaces=ns)[0].text
但我一无所获:(
尝试使用 tostring
方法。
etree.tostring(el.xpath('//ns:retEvento',namespaces=ns)[0])