0

I need a regex that will give me the "Resource" attribute value from the parent node, where "Name" node = "BES Support"

<BESAPI xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="BESAPI.xsd">
<ExternalSite Resource="https://server.domain.com:52311/api/site/external/BES%20Support">
<Name>BES Support</Name>
<GatherURL>http://sync.bigfix.com/cgi-bin/bfgather/bessupport</GatherURL>
</ExternalSite>
<CustomSite Resource="https://server.domain.com:52311/api/site/custom/DSE_Relays">
<Name>DSE_Relays</Name>
<GatherURL>http://server.domain.com:52311/cgi-bin/bfgather.exe/CustomSite_DSE_Relays</GatherURL>
</CustomSite>
<OperatorSite Resource="https://server.domain.com:52311/api/site/operator/idhere">
<Name>idhere</Name>
<GatherURL>http://server.domain.com:52311/cgi-bin/bfgather.exe/actionsite</GatherURL>
</OperatorSite>
</BESAPI>
masonje
  • 49
  • 1
  • 5
  • first you say xpath, then you say regex, then you tag xpath... you mean xpath, right? xpath is specifically designed for this stuff, but regex: https://stackoverflow.com/a/1732454/1067003 – hanshenrik Sep 28 '17 at 01:17
  • my bad hanshenrik – masonje Sep 29 '17 at 04:06

1 Answers1

0

//name[text()="BES Support"]/parent::*/@resource

hanshenrik
  • 19,904
  • 4
  • 43
  • 89
  • //Name[text()='BES Support']/parent::*/@Resource But that was it! Thanks! – masonje Sep 28 '17 at 01:20
  • @masonje sorry, i have been using too much of PHP's retarded and bugged DOMXPath implmentation, that lowercase both tag names and attribute names, but not actual attribute nor text values... -.- - and if anyone reports that on the bugtracker, there's a 99.999% chance that they say "sorry, can't fix it, would break backwards-compat" or some similar reason not to fix it (actually i bet someone already has) – hanshenrik Sep 28 '17 at 01:23
  • Funny you say that, I'm using it in PHP. But tested it on a web page tester. – masonje Sep 29 '17 at 04:03