开发者

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")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜