我有一个简单的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/