I have an array which contains 7000+ value
$arrayIds = [
'A001',
...,
'A7500'
];
This foreach loop gets node value inside a node in a given XML file
$dom = new DOMDocument;
$dom->load('myxml.xml');
$xp = new DOMXPath($dom);
$data = [];
foreach ($arrayIds as $arrayId) {
$expression = "//unit[@person-name=\"$arrayId\"]/@id";
$col = $xp->query($expression);
if ($col && $col->length) {
foreach ($col as $node) {
$data[] = $node->nodeValue;
}
}
}
It takes approximately 70 seconds. I can't wait any longer than 5 seconds
What is the fastest way to achieve this?
Segment of the XML file:
<unit person-name="A695" id="PTU-300" xml:space="preserve">
<source xml:lang="en">Related tutorials</source>
<seg-source><mrk mid="0" mtype="seg">Related tutorials</mrk></seg-source>
<target xml:lang="id"><mrk mid="0" mtype="seg">Related tutorials</mrk></target>
</unit>
<unit person-name="A001" id="PTU-4" xml:space="preserve">
<source xml:lang="en">Related tutorials</source>
<seg-source><mrk mid="0" mtype="seg">Related tutorials</mrk></seg-source>
<target xml:lang="id"><mrk mid="0" mtype="seg">Related tutorials</mrk></target>
</unit>
...
<unit>
...
</unit>
Anyway, I'm doing this on an M1 Mac