I'm having a hard time. I am not able to scan the XML file and change the values of the tags that I need, they are NOTA
and SERIE
. I have to replace these tags with new values, does anyone know how to do this? I researched, but the structure of my XML
is making me more difficult. Follow the codes.
public function corrigirXML() {
$dom = new DOMDocument();
$dom->load("C:\BSI\INFOCLOUD\ENTRADA\".$this->getCaminhoXmlCorrecao());
$root = $dom->documentElement;
$index = $root->getElementsByTagName('IndexValue');
print_r($index);
for ($i =0; $i<count($index); $i++) {
$type = $index->getElementsByTagName('Label')->item($i)->textContent;
$title = $index->getElementsByTagName('Value')->item($i)->textContent;
echo $type." - ".$title."<br>";
}
}
XML structure
<?xml version="1.0"?>
<Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Number>61</Number>
<PageCount>1</PageCount>
<IndexValues>
<IndexValue>
<Label>TIPO_DOCUMENTO</Label>
<Value>CANHOTOS</Value>
</IndexValue>
<IndexValue>
<Label>NOTA</Label>
<Value>001954884</Value>
</IndexValue>
<IndexValue>
<Label>SERIE</Label>
<Value>1</Value>
</IndexValue>
</IndexValues>
</Document>