Skip to content

Commit 8aa9b1c

Browse files
committed
Optimized xpath queries
1 parent f0bc083 commit 8aa9b1c

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

src/Sdmx/api/parser/v21/V21CodelistParser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ public function parseCodesFromNode(SimpleXMLElement $data)
1717
{
1818
$result = [];
1919

20-
$codes = $data->xpath('.//str:Code');
20+
$codes = $data->xpath('./str:Code');
2121

2222
foreach ($codes as $code){
23-
$name = $code->xpath('.//com:Name[@xml:lang="en"]');
23+
$name = $code->xpath('./com:Name[@xml:lang="en"]');
2424
if(count($name) > 0){
2525
$result[(string) $code['id']] = (string)$name[0];
2626
}
@@ -37,7 +37,7 @@ public function parseCodesFromNode(SimpleXMLElement $data)
3737
public function parseCodes($data)
3838
{
3939
$xml = new SimpleXMLElement($data);
40-
$codelist = $xml->xpath('//mes:Structure/mes:Structures/str:Codelists/str:Codelist')[0];
40+
$codelist = $xml->xpath('/mes:Structure/mes:Structures/str:Codelists/str:Codelist')[0];
4141

4242
return $this->parseCodesFromNode($codelist);
4343
}

src/Sdmx/api/parser/v21/V21DataParser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ public function parse($data, DataflowStructure $dsd, $dataflow, $containsData)
2626
$xml = new SimpleXMLElement($data);
2727
$result = [];
2828

29-
$dataSet = $xml->xpath('//message:StructureSpecificData/message:DataSet')[0];
29+
$dataSet = $xml->xpath('/message:StructureSpecificData/message:DataSet')[0];
3030
$action = (string)$dataSet[self::ACTION];
3131
$validFrom = (string)$dataSet[self::VALID_FROM];
3232
$validTo = (string)$dataSet[self::VALID_TO];
3333

34-
$series = $dataSet->xpath('.//ns1:Series');
34+
$series = $dataSet->xpath('./ns1:Series');
3535
foreach ($series as $seriesLine) {
3636
$result[] = $this->parseSeriesLine($seriesLine, $dsd, $dataflow, $containsData, $action, $validFrom, $validTo);
3737
}
@@ -58,7 +58,7 @@ private function parseSeriesLine(SimpleXMLElement $seriesLine, DataflowStructure
5858
$this->setMetadata($seriesLine, $dsd, $action, $validFrom, $validTo, $result);
5959

6060
if ($containsData) {
61-
$observations = $seriesLine->xpath('.//ns1:Obs');
61+
$observations = $seriesLine->xpath('./ns1:Obs');
6262
foreach ($observations as $observation) {
6363
$this->processObservation($dsd, $observation, $result);
6464
}

src/Sdmx/api/parser/v21/V21DataStructureParser.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function parse($data)
4848
*/
4949
private function parseCodelists(SimpleXMLElement $xml)
5050
{
51-
$codelists = $xml->xpath('//mes:Structure/mes:Structures/str:Codelists/str:Codelist');
51+
$codelists = $xml->xpath('/mes:Structure/mes:Structures/str:Codelists/str:Codelist');
5252
$result = [];
5353
foreach ($codelists as $codelist) {
5454
$codelistName = $this->getCodelistName($codelist);
@@ -64,13 +64,13 @@ private function parseCodelists(SimpleXMLElement $xml)
6464
*/
6565
private function parseConcepts(SimpleXMLElement $xml)
6666
{
67-
$conceptSchemes = $xml->xpath('//mes:Structure/mes:Structures/str:Concepts/str:ConceptScheme');
67+
$conceptSchemes = $xml->xpath('/mes:Structure/mes:Structures/str:Concepts/str:ConceptScheme');
6868
$result = [];
6969

7070
foreach ($conceptSchemes as $conceptScheme) {
7171
$version = (string)$conceptScheme['version'];
7272
$agency = (string)$conceptScheme['agencyID'];
73-
$concepts = $conceptScheme->xpath('.//str:Concept');
73+
$concepts = $conceptScheme->xpath('./str:Concept');
7474

7575
foreach ($concepts as $concept) {
7676
$id = (string)$concept['id'];
@@ -88,7 +88,7 @@ private function parseConcepts(SimpleXMLElement $xml)
8888
*/
8989
private function getConceptName(SimpleXMLElement $concept)
9090
{
91-
$name = $concept->xpath('.//com:Name[@xml:lang="en"]');
91+
$name = $concept->xpath('./com:Name[@xml:lang="en"]');
9292

9393
return count($name) > 0 ? (string)$name[0] : '';
9494
}
@@ -103,7 +103,7 @@ private function parseDataStructures(SimpleXMLElement $xml, array $codelists, ar
103103
{
104104
$result = [];
105105

106-
$structures = $xml->xpath('//mes:Structure/mes:Structures/str:DataStructures/str:DataStructure');
106+
$structures = $xml->xpath('/mes:Structure/mes:Structures/str:DataStructures/str:DataStructure');
107107
foreach ($structures as $structure) {
108108
$result[] = $this->parseDataStructure($structure, $codelists, $concepts);
109109
}
@@ -136,7 +136,7 @@ private function fillDsMainData(SimpleXMLElement $structure, DataflowStructure $
136136
$flowStructure->setAgency((string)$structure['agencyID']);
137137
$flowStructure->setId((string)$structure['id']);
138138
$flowStructure->setVersion((string)$structure['version']);
139-
$name = $structure->xpath('.//com:Name[@xml:lang="en"]');
139+
$name = $structure->xpath('./com:Name[@xml:lang="en"]');
140140
if (count($name) > 0) {
141141
$flowStructure->setName((string)$name[0]);
142142
}
@@ -150,7 +150,7 @@ private function fillDsMainData(SimpleXMLElement $structure, DataflowStructure $
150150
*/
151151
private function fillDsDimensionData(SimpleXMLElement $structure, DataflowStructure $flowStructure, array $codelists, array $concepts)
152152
{
153-
$dimensions = $structure->xpath('.//str:DataStructureComponents/str:DimensionList/str:Dimension');
153+
$dimensions = $structure->xpath('./str:DataStructureComponents/str:DimensionList/str:Dimension');
154154
$position = 0;
155155
foreach ($dimensions as $dimension) {
156156
$parsedDimension = $this->parseDimension($dimension, $concepts, ++$position);
@@ -190,7 +190,7 @@ private function parseDimension(SimpleXMLElement $dimension, array $concepts, $p
190190
*/
191191
private function parseDimensionCodeList(SimpleXMLElement $dimension)
192192
{
193-
$localRepresentation = $dimension->xpath('.//str:LocalRepresentation/str:Enumeration/Ref');
193+
$localRepresentation = $dimension->xpath('./str:LocalRepresentation/str:Enumeration/Ref');
194194

195195
if (count($localRepresentation) == 0) {
196196
return null;
@@ -212,7 +212,7 @@ private function parseDimensionCodeList(SimpleXMLElement $dimension)
212212
*/
213213
private function getDimensionName(SimpleXMLElement $dimension, array $concepts)
214214
{
215-
$concept = $dimension->xpath('.//str:ConceptIdentity/Ref');
215+
$concept = $dimension->xpath('./str:ConceptIdentity/Ref');
216216

217217
if (count($concept) == 0) {
218218
return '';
@@ -232,7 +232,7 @@ private function getDimensionName(SimpleXMLElement $dimension, array $concepts)
232232
*/
233233
private function parseTimeDimension(SimpleXMLElement $structure)
234234
{
235-
$timeDimension = $structure->xpath('.//str:DataStructureComponents/str:DimensionList/str:TimeDimension');
235+
$timeDimension = $structure->xpath('./str:DataStructureComponents/str:DimensionList/str:TimeDimension');
236236

237237
if (count($timeDimension) == 0) {
238238
return '';

src/Sdmx/api/parser/v21/V21DataflowParser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ public function parse($data)
2323
$result = array();
2424
$xml = new SimpleXMLElement($data);
2525

26-
$flows = $xml->xpath('//mes:Structure/mes:Structures/str:Dataflows/str:Dataflow');
26+
$flows = $xml->xpath('/mes:Structure/mes:Structures/str:Dataflows/str:Dataflow');
2727
foreach ($flows as $flow) {
2828
$dataflow = new Dataflow();
2929
$dataflow->setId((string) $flow[self::ID]);
3030
$dataflow->setAgency((string) $flow[self::AGENCY_ID]);
3131
$dataflow->setVersion((string)$flow[self::VERSION]);
3232

33-
$name = $flow->xpath('.//com:Name[@xml:lang="en"]');
33+
$name = $flow->xpath('./com:Name[@xml:lang="en"]');
3434
if(count($name) > 0){
3535
$dataflow->setName((string)$name[0]);
3636
}
3737

3838

39-
$ref = $flow->xpath('.//str:Structure/Ref');
39+
$ref = $flow->xpath('./str:Structure/Ref');
4040
if(count($ref) > 0){
4141
$ref = $ref[0];
4242
$dsd = new DsdIdentifier(

0 commit comments

Comments
 (0)