1

这就是我的 xPathNavigator 的样子:

<mux:Column Name="id" DisplayMemberBinding="{Binding Path=Id, Mode=OneWay}" Width="100" DisplayName="Header_Id" Property="Id" DataType="s:String" xmlns:mux="http://schemas.microsoft.com/SystemCenter/Common/UI/Views/GridView" />

我想读取 DisplayMemberBinding 属性中 Path 的值。

这是我尝试过的:

xPathNavigator.GetAttribute("DisplayMemberBinding", "") //Gives me {Binding Path=Id, Mode=OneWay}

xPathNavigator.GetAttribute("DisplayMemberBinding/Binding/@Path", "") //Gives me empty string

如何获取 DisplayMemberBinding 属性中 Path 的值?

4

1 回答 1

1

使用

xPathNavigator.Evaluate
  (@"substring-before(substring-after(@DisplayMemberBinding, 'Path='),
                     ',')"
  );

当然,您需要将结果转换为string.

基于 XSLT 的验证

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:mux="http://schemas.microsoft.com/SystemCenter/Common/UI/Views/GridView">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="/*">
  <xsl:value-of select=
  "substring-before(substring-after(@DisplayMemberBinding, 'Path='),
                    ',')"/>
 </xsl:template>
</xsl:stylesheet>

当此转换应用于提供的 XML 文档时:

<mux:Column Name="id"
DisplayMemberBinding="{Binding Path=Id, Mode=OneWay}"
Width="100" DisplayName="Header_Id"
Property="Id" DataType="s:String"
xmlns:mux="http://schemas.microsoft.com/SystemCenter/Common/UI/Views/GridView" />

对 XPath 表达式求值,并将该求值的结果复制到输出中:

Id
于 2013-05-02T01:31:10.437 回答