summaryrefslogtreecommitdiffstats
path: root/index.php
diff options
context:
space:
mode:
authorMaksymilian Jopek <maks@jopek.eu>2022-03-24 14:31:15 +0100
committerMaksymilian Jopek <maks@jopek.eu>2022-03-24 14:31:15 +0100
commit3f375f41a0d8176396da0a5988a9db06383e1636 (patch)
tree89b8fa7232e73a9787b03f8d33847e63fcfdb393 /index.php
parentd1dcd0b49010bba31e44859e0d1d76abb7fb20fc (diff)
downloadalahelo-madio-3f375f41a0d8176396da0a5988a9db06383e1636.tar.gz
alahelo-madio-3f375f41a0d8176396da0a5988a9db06383e1636.tar.zst
alahelo-madio-3f375f41a0d8176396da0a5988a9db06383e1636.zip
Option to use or two xpaths ( speed )
Diffstat (limited to 'index.php')
-rw-r--r--index.php19
1 files changed, 9 insertions, 10 deletions
diff --git a/index.php b/index.php
index a67bd26..ee7431c 100644
--- a/index.php
+++ b/index.php
@@ -3,19 +3,18 @@ header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Content-Type");
$method = $_SERVER['REQUEST_METHOD'];
$xml = simplexml_load_file("./terc.xml");
-// var_dump($xml);
if ($method === "GET") {
- // $result = $xml->xpath('//row/NAZWA_DOD[text()="województwo"]/ancestor::*/NAZWA/text()');
- $result = $xml->xpath('//NAZWA_DOD[text()="województwo"]/ancestor::*/NAZWA/text() | //NAZWA_DOD[text()="województwo"]/ancestor::*/WOJ/text()');
+ $result = $xml->xpath('//NAZWA_DOD[text()="województwo"]/ancestor::*/NAZWA/text()');
} else if ($method === "POST") {
$body = file_get_contents('php://input');
- // echo $body;
- // echo '//row/NAZWA[text()="' . $body . '"]/ancestor::*/NAZWA_DOD[contains(text(),"miejs")]/ancestor::*/NAZWA/text()';
- $result = $xml->xpath('//row/WOJ[text()="' . $body . '"]/ancestor::*/NAZWA_DOD[contains(text(),"miejs")]/ancestor::*/NAZWA/text()');
-} else {
- $result = $xml->xpath('//row/NAZWA[text()="ŁÓDZKIE"]/ancestor::*/NAZWA_DOD[contains(text(),"miejs")]/ancestor::*/NAZWA/text()');
- $result = $xml->xpath('//WOJ[text()="10"]/ancestor::*/NAZWA_DOD[contains(text(),"miejs")]/ancestor::*/NAZWA/text()');
- $result = $xml->xpath('//NAZWA_DOD[text()="województwo"]/ancestor::*/NAZWA/text() | //NAZWA_DOD[text()="województwo"]/ancestor::*/WOJ/text()');
+ $one_xpath = true;
+ if (!$one_xpath) {
+ $id = $xml->xpath('//row/NAZWA[text()="' . $body . '"]/ancestor::*/WOJ');
+ $id = "{$id[0]}";
+ $result = $xml->xpath('//WOJ[text()=' . $id . ']/ancestor::*/NAZWA_DOD[contains(text(),"miejs")]/ancestor::*/NAZWA/text()');
+ } else {
+ $result = $xml->xpath('//WOJ[text()=//row/NAZWA[text()="' . $body . '"]/ancestor::*/WOJ]/ancestor::*/NAZWA_DOD[contains(text(),"miejs")]/ancestor::*/NAZWA/text()');
+ }
}
$result = array_map(function ($x) {
return "$x";