这是有效的xpath查询吗? [英] is this a valid xpath query?

查看:89
本文介绍了这是有效的xpath查询吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//[dataOptions[id]]似乎有效

但是//[dataOptions[id=value]]不起作用

我正在尝试获取dataOptions等于val的所有dataOptions父母.第二个有效吗?我怀疑我用来解决查询的JPath出现错误.但是我不确定我的查询是否有效.

I am trying to get all the parents of dataOptions where dataOptions.id equals val. Is the second one valid ? I have a doubt my JPath that I am using to resolve query has a bug. But I am not sure if my query is valid.

[
{
    "dataOptions": {
        "id": "id1",
        "count": "10"
    },
    "name": "Leon",
    "children": [
        {
            "dataOptions": {
                "id": "id2",
                "count": "10"
            },
            "name": "Leon",
            "children": [],
            "isExpanded": false
        },
        {
            "dataOptions": {
                "id": "id2",
                "count": "10"
            },
            "name": "Leon",
            "children": [],
            "isExpanded": false
        }
    ],
    "isExpanded": false
},
{
    "dataOptions": {
        "id": "id3",
        "count": "10"
    },
    "name": "Leon",
    "children": [],
    "isExpanded": false
},
{
    "dataOptions": {
        "id": "id4",
        "count": "10"
    },
    "name": "Leon",
    "children": [],
    "isExpanded": false
}

]

推荐答案

ShaggyInjun, 我认为您正在寻找符合以下条件的东西:

ShaggyInjun, I think you're looking something in lines with:

//dataOptions[id]
//dataOptions[id="id2"]

我最近编写了一个名为"defiant.js"的js库-使用该库,可以使用XPath对JSON结构进行查询.在这种情况下-我已在此页面上粘贴了您的JSON数据:

I have recently written a js-lib called "defiant.js" - with which one can make queries on JSON structure with XPath. To put in in this context - I've pasted your JSON data at this page:

http://www.defiantjs.com/#xpath_evaluator

...并在视觉上测试了不同的XPath查询,再次验证了该结构.评估程序突出显示JSON及其XML对应项中的匹配项.

...and visually tested different XPath queries agains the structure. The evaluator highlights the matches both in JSON and its XML counterpart.

我希望您发现"defiant.js"及其网站有用.

I hope you find the "defiant.js" and its site usefull.

这篇关于这是有效的xpath查询吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆