gpt4 book ai didi

Python 和 xml : Reading data from xml file

转载 作者:行者123 更新时间:2023-12-01 06:13:13 25 4
gpt4 key购买 nike

我有一个简单的python,其中我定义了styledoc,如下

styledoc = libxml2.parseDoc("""
<xsl:stylesheet version='1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
xmlns:foo='http://example.com/foo'
xsl:exclude-result-prefixes='foo'>

<xsl:param name='bar'>failure</xsl:param>
<xsl:template match='/'>
<article><xsl:value-of select='foo:foo($bar)'/></article>
</xsl:template>
</xsl:stylesheet>
""")

我想要将所有数据包含在文件 read.xml 之类的内容

styledoc = libxml2.parseDoc("read.xml");

但它给了我一个错误“read”未定义。我犯了什么错误?

最佳答案

parseDoc 采用包含 XML 的字符串,如第一个示例所示。要解析文件,请使用 parseFile 代替:

styledoc = libxml2.parseFile("read.xml")

关于Python 和 xml : Reading data from xml file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4651569/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com