Python and xml : Reading data from xml file
I have a simple python, in which i have defined styledoc as follows
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:开发者_JAVA技巧foo($bar)'/></article>
</xsl:template>
</xsl:stylesheet>
""")
I want to have something like all the data included in a file read.xml and something like this
styledoc = libxml2.parseDoc("read.xml");
but it gives me an error 'read' is not defined. What mistake am I doing?
parseDoc
takes a string containing XML, as shown in your first example. To parse a file use parseFile
instead:
styledoc = libxml2.parseFile("read.xml")
精彩评论