Skip to content Skip to sidebar Skip to footer

Xpath Expression With White Space In Node For Defiant.js

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

Solution 1:

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.

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 converted to the following XML structure (only relevant part of the XML posted here) :

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

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

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

Solution 2:

With JSONPath you should be able to use

//Certificate Number="101235"

No need for []

Post a Comment for "Xpath Expression With White Space In Node For Defiant.js"