1
我有這個數據,我希望能夠在每個節點只顯示名稱和IP:使用XPath排除可能的屬性?
{
"virtualservers": [
{
"name": "/partition/name",
"ip": "1.1.1.1",
"port": "80",
"defaultpool": "",
"sslprofile": "None",
"compressionprofile": "/Common/cmpprof",
"persistence": "None",
"irules": [
"/Common/http-to-https"
],
"pools": null,
"sourcexlatetype": "None",
"sourcexlatepool": "None",
"loadbalancer": "MYLB"
},
{
"name": "/partition/name2",
"ip": "2.2.2.2",
"port": "80",
"defaultpool": "",
"sslprofile": "None",
"compressionprofile": "/Common/cmpprof",
"persistence": "None",
"irules": [
"/Common/anotherrule"
],
"pools": null,
"sourcexlatetype": "None",
"sourcexlatepool": "None",
"loadbalancer": "MYLB2"
}
]
}
我周圍有點戳,這幾乎工程:
//virtualserver[(position() > 0 and position() < 10)]/*[name()="name" or name()="ip"]
[
"/partition/name",
"1.1.1.1",
"/partition/name2",
"2.2.2.2"
]
但我想爲了讓我的節點信息能夠在我的模板中正確地遍歷它。理想情況下,結果會是這樣的
[
{
"name": "/partition/name",
"ip": "1.1.1.1",
},
{
"name": "/partition/name2",
"ip": "2.2.2.2",
}
]
我使用這個defiantjs所以它可能不是使用XPath完全兼容。歡迎任何建議!
/Patrik
Thak你,非常感謝! – PatrikJ