0

I am using reg ex pattern which does not support below xpath.currently getting null value against this xpath.

I am using xpath which has default namespaces and value is achieved when i change the xpath format but in this case, I am unable to get the value, but if i change the xpath then i get value.

So I need regex for the actual xpath to convert it into expected.

xpath is :

/abc/tra/tra/part[tr/@tr="http://www.sd.org"]/trId

Expected is :

/abc/tra/tra/part[:tr/@tr="http://www.sd.org"]/trId

If any body can then have a look.

Filburt
  • 17,626
  • 12
  • 64
  • 115
pank24oct
  • 1
  • 1
  • 1
    what parts of this is dynamic? Are there any more examples to give? Otherwise a simple string replace would already do? https://regex101.com/r/DvdRs5/1 – Doqnach May 17 '17 at 12:48
  • we can't hard code "tr" in substitute because this will keep on changing. – pank24oct May 17 '17 at 13:12
  • also some time xpath wil get change like /abc/tra/tra/part/tse[@tr="http://www.sd.org"]/text() so need rege ex which can compile maximum xpath format. – pank24oct May 17 '17 at 13:13
  • Please provide a full real-world example then, with as many use-cases as possible. That way we can provide you with a valid regex. As it is now, we can only guess at what it is that you need. (I have no idea what you mean by "maximum xpath format"... do you mean prepending valid cases with an empty namespace? If so, that doesn't really seem like a job for regex but a tool that is xpath aware) – Doqnach May 17 '17 at 15:47
  • currently I have made regex which compile the below xpath using regex xpath = xpath.replaceAll("/(?=\\w.*?)(?![^\\[/]*:)(?![^\\[]*\")(?![^\\[]*\')", "/:"); – pank24oct May 18 '17 at 05:58
  • Above regex is valid for xpath like ://traessage/hId/text() //trage/heaer/meseId[@messaheme='urn:hc:met']/text() //trat/trae[@xsi:type='c:Trade']/f:traeHeder/f:partyTraifier/f:versId/f:tr[@tre='urn:cA']/text() //f:tradeId[@trme='urn:h']/text() //hc:eqeDetails/f:prype[@prpeeme='urn-plus'] //pa[@id='p1']/f:peon[@id='Clk']/f:pId[@pId='urn:id:FA-UR']/text() – pank24oct May 18 '17 at 06:02
  • while same regex is not matching the actual xpath which i mentioned in the above.There is some modification require in it. – pank24oct May 18 '17 at 06:03

0 Answers0