Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 为嵌套中继器指定XPath节点索引_Asp.net_Xpath_Indexing_Selectnodes_Nested Repeater - Fatal编程技术网

Asp.net 为嵌套中继器指定XPath节点索引

Asp.net 为嵌套中继器指定XPath节点索引,asp.net,xpath,indexing,selectnodes,nested-repeater,Asp.net,Xpath,Indexing,Selectnodes,Nested Repeater,假设我有一个类似于以下内容的XML层次结构: <Animal> <Kingdom> <Phylum> <Class></Class> <Class></Class> </Phylum> <Phylum> <Class></Class>

假设我有一个类似于以下内容的XML层次结构:

<Animal>
    <Kingdom>
        <Phylum>
            <Class></Class>
            <Class></Class>
        </Phylum>
        <Phylum>
            <Class></Class>
            <Class></Class>
        </Phylum>
    </Kingdom>
    <Kingdom>
        <Phylum>
            <Class></Class>
            <Class></Class>
        </Phylum>
    </Kingdom>
</Animal>

(etc.)

(等等)
同样,我有使用嵌套转发器的ASP.NET代码,类似于:

<asp:Repeater ID="ShowKingdom" runat="server" DataSource="(SomeDataSource)">
    <ItemTemplate>
        <asp:TextBox ID="txtKingdom" runat="server" XPath="/*[local-name()='Animal']/*[local-name()='Kingdom'][{0}]">
        <asp:Repeater ID="ShowPhylum" runat="server" OnItemDataBound="(SomeDataBinder)">
            <ItemTemplate>
                <asp:TextBox ID="txtKingdom" runat="server" XPath="/*[local-name()='Animal']/*[local-name()='Kingdom'][{0}]/*[local-name()='Phylum'][???]">
            </ItemTemplate>
        </asp:Repeater>
    </ItemTemplate>
</asp:Repeater>

我的问题是:如何为嵌套中继器中的XPath指定节点索引选择器“[??]”“

注意:我的语言是ASP.NET中的VB

Edit:我尝试使用不同的索引“[{1}]”(给我一个索引越界错误)、相对Xpath“[local-name()='Phylum']”(前面的否“/*”——不识别节点/路径),以及修补嵌套的repeater数据源(它要么不识别Xpath,要么崩溃)

很明显,我一直没能让这些东西发挥作用。我需要考虑另一种方法吗?

编辑#2:我尝试过的另一件不想起作用的事情:对于嵌套中继器:

DataSource="<%# XPathSelect('Phylum')%>"
DataSource=“”

我终于明白了这一点。我找到钥匙了

在做了大量挖掘之后,我意识到XPath中的{0}谓词索引在代码中被替换为使用String.format调用

我通过引用e.Item.parent.parent(其中“e”是RepeaterItemEventArgs对象)获得了父中继器索引

一旦我有了当前中继器及其父级的索引,我就可以使用{0}和{1}作为索引,剩下的就用String.format了

瞧。问题解决了