【发布时间】:2015-04-22 13:20:11
【问题描述】:
我正在尝试编写一个 python 脚本来从 XML 文档构建一个对象,但是我在理解路径的工作原理时遇到了一些麻烦。这是 XML 文档的示例:
<args format="1.0">
<shaderType>
<tag value="pattern"/>
</shaderType>
<help>
Computes the facing ratio of the geometry : a simple dot product between
the camera vector and the surface normal.
</help>
<page name="Parameters" open="True">
<param name="faceForward"
label="Face Forward"
type="int"
default="1"
widget="checkbox">
<tags>
<tag value="__noconnection"/>
</tags>
<help>The facing ratio can be negative if the normal is pointing
away from the camera. This will flip the normal to always give a
positive result.</help>
</param>
<param name="invert"
label="Invert"
type="int"
default="0"
widget="checkbox">
<tags>
<tag value="__noconnection"/>
</tags>
<help>Inverts the facing ratio : black becomes white and
vice-versa.</help>
</param>
<param name="gamma"
label="Gamma"
type="float"
default="1.0"
widget="default">
<tags>
<tag value="float"/>
</tags>
<help>A simple gamma function to shape the facing ratio. A value of 1.0 is
neutral</help>
</param>
<param name="bumpNormal"
label="Bump Normal"
type="normal"
widget="default">
<tags>
<tag value="normal"/>
</tags>
<help>If the surface is bump-mapped, input the bump normal here. If
not connected, the node will use ths shading normal.</help>
</param>
</page>
<output name="resultF">
<tags>
<tag value ="float"/>
</tags>
</output>
<rfmdata nodeid="1053349"
classification="rendernode/RenderMan/pattern"/>
假设我想获取对象本身的帮助语句。我正在使用这个:
nodeText = tree.findtext('.//args/help')
print nodeText
然而,这将返回 None。是不是我用的路径不对?
【问题讨论】:
标签: python xml elementtree