3
I’m having a hard time. I’m unable to scan the XML file and change the values of the tags I need, they are NOTA
and SERIE
. I have to replace these tags with new values, someone knows how to do it ? 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>
just a hint, try using ". / "in the path, so it becomes much more practical for you instead of using the absolute path.
– Gabriel C.
Yes, I won’t do it this way. The way will come dynamically from another class, I did so just to gain time and test rsrs. But anyway thank you.
– Marlon Castro
You want to change the tags or their contents?
– Guilherme Nascimento
The contents of tags.
– Marlon Castro
@Marloncastro if any of the answers solved your problem, please mark the solution.
– Marcelo de Andrade