defiant.js节点中带有空格的XPath表达式 [英] XPath expression with white space in node for defiant.js

查看:109
本文介绍了defiant.js节点中带有空格的XPath表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 defiant.js 搜索json.根据他们的文档,我需要提供xpath以便从json搜索特定元素.当节点中没有空白时,我就成功了.但是我的json现在包含空白.这是我的csv.我想要一个带有特定证书编号的商品.

I am using defiant.js for searching a json. According to their documentation, I need to provide xpath for searching a specific element from json. I am successful with it when there is no white space in the node. But my json now contain white space. Here is my csv. I want to get an item with specific certificate number.

    [
  {
    "Certificate Number":1019174,
    "Last Name":"MA",
    "First Name":"SHI",
    "Title":"MR",
    "DOB":"1/28/1990",
    "Address":"75 LEYLAND HOUSE",
    "City":"London",
    "Postal Code":"E14 0BU",
    "Country":"UK",
    "Passpot Number":"E0438750",
    "Course Level":7,
    "Course Details":"POST GRADUATE DIPLOMA IN INTERNATIONAL COMMERCIAL LAW",
    "Course Start Date":"2/2/2014",
    "Course End Date":"2/23/2015",
    "Note":"RPL Route Entry",
    "Remarks":""
  },
  {
    "Certificate Number":101235,
    "Last Name":"UD",
    "First Name":"HAN",
    "Title":"MR",
    "DOB":"1/28/1990",
    "Address":"75 LEYLAND HOUSE",
    "City":"London",
    "Postal Code":"E14 0BU",
    "Country":"UK",
    "Passpot Number":"E0438750",
    "Course Level":7,
    "Course Details":"POST GRADUATE DIPLOMA IN INTERNATIONAL COMMERCIAL LAW",
    "Course Start Date":"2/2/2014",
    "Course End Date":"2/23/2015",
    "Note":"RPL Route Entry",
    "Remarks":""
  }
]

我的xpath是

//[Certificate Number="101234"]

当属性名称类似于CertificateNumber时,我没有问题可以找到该项目.但是在证书和编号之间留有空格,我无法获得该物品.因此,如何从此json获取具有特定证书编号的项目. defiant.js以外的任何其他解决方案都可以.

When the property name is like CertificateNumber I have no problem to find the item. But with space between certificate and number I can't get the item. So how can I get an item with specific certificate number from this json. any alternative solution other than defiant.js can do.

推荐答案

似乎JSON属性作为XML节点名称是无效的(因为它们包含空格),因此它们通过反抗被转换为命名空间中的XML属性. js.

It seems that the JSON properties which are invalid as XML node name (because they contain space), they are getting converted to an XML attribute in namespace by defiant.js.

例如,这是JSON的这一部分.:

For example, this part of your JSON.. :

{
    "Certificate Number":101235,
    "Last Name":"UD",
    "First Name":"HAN",
    "Title":"MR",
    "DOB":"1/28/1990",
    "Address":"75 LEYLAND HOUSE",
    "City":"London",
    "Postal Code":"E14 0BU",
    "Country":"UK",
    "Passpot Number":"E0438750",
    "Course Level":7,
    "Course Details":"POST GRADUATE DIPLOMA IN INTERNATIONAL COMMERCIAL LAW",
    "Course Start Date":"2/2/2014",
    "Course End Date":"2/23/2015",
    "Note":"RPL Route Entry",
    "Remarks":""
  }

.. getting转换为以下XML结构(此处仅列出了XML的相关部分):

..getting converted to the following XML structure (only relevant part of the XML posted here) :

<d:item xmlns:d="defiant-namespace" d:mi="34">
   <d:name d:name="Certificate Number" d:constr="Number" d:mi="18">101235</d:name>
   <d:name d:name="Last Name" d:constr="String" d:mi="19">UD</d:name>
   <d:name d:name="First Name" d:constr="String" d:mi="20">HAN</d:name>
   <Title d:constr="String" d:mi="21">MR</Title>
   <DOB d:constr="String" d:mi="22">1/28/1990</DOB>
   <Address d:constr="String" d:mi="23">75 LEYLAND HOUSE</Address>
   <City d:constr="String" d:mi="24">London</City>
   <d:name d:name="Postal Code" d:constr="String" d:mi="25">E14 0BU</d:name>
   <Country d:constr="String" d:mi="26">UK</Country>
   <d:name d:name="Passpot Number" d:constr="String" d:mi="27">E0438750</d:name>
   <d:name d:name="Course Level" d:constr="Number" d:mi="28">7</d:name>
   <d:name d:name="Course Details" d:constr="String" d:mi="29">POST GRADUATE DIPLOMA IN INTERNATIONAL COMMERCIAL LAW</d:name>
   <d:name d:name="Course Start Date" d:constr="String" d:mi="30">2/2/2014</d:name>
   <d:name d:name="Course End Date" d:constr="String" d:mi="31">2/23/2015</d:name>
   <Note d:constr="String" d:mi="32">RPL Route Entry</Note>
   <Remarks d:constr="String" d:mi="33"/>
</d:item>

因此,根据XML结构,这是一种通过证书编号"值获取元素上方的XPath的可能性:

So according to the XML structure, this is one possible XPath to get above element by "Certificate Number" value :

//*[*[@*="Certificate Number" and .=101235]]

这篇关于defiant.js节点中带有空格的XPath表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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