English 中文(简体)
利用Xpath选择基于其兄弟的文字和属性的内容
原标题:Selecting an element based on text and attribute of its sibling, using Xpath

Looking at the document, the goal is to select the second cell from the second row, in the first table.

我发表了以下言论:

//row/td[2]/text()[td[@class="identifier"]/span[text()="identifier"]]

但它并未退回任何款项。 不幸的是,我看不到什么错误。

对我来说,它看着alright。 表达方式应当:

select the text
    in the second cell 
        in any row
where
    the text of a span equals to "identifier"
        and the span is located in cell with a "identifier" class

如果你能够指出我做错的话,我将不胜感激。

Sample XML文件:

<?xml version="1.0"?>
<html>
    <table class="first">
        <tr>
            <td>row 1, cell 1</td>
            <td>row 1, cell 2</td>
        </tr>
        <tr>
            <td class="identifier">
                <span>identifier</span>
            </td>
            <td>
                foo
                <span>ignore</span>
                bar
            </td>
        </tr>
        <tr>
            <td>row 3, cell 1</td>
            <td>row 3, cell 2</td>
        </tr>
    </table>

    <table class="second">
        <tr>
            <td>row 1, cell 1</td>
            <td>row 1, cell 2</td>
        </tr>
        <tr>
            <td class="identifier">
                <span>not an identifier</span>
            </td>
            <td>
                not a target
            </td>
        </tr>
        <tr>
            <td>row 3, cell 1</td>
            <td>row 3, cell 2</td>
        </tr>
    </table>
</html>
最佳回答

就在一看,我认为你指的是写:

//tr/td[2][@class="identifier"][span="identifier"]

奇怪的是,我没有看到你抽样数据中符合所有三个条件的任何节点。

www.un.org/Depts/DGACM/index_spanish.htm 根据反馈,这里还有另一个要尝试的问题。

//tr[td/@class="identifier"][td/span="identifier"]/td[2]/text()
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签