請指教。我有XML,我需要通過PHP來糾正。 XML的如何根據預設參數找到並替換XML中的值
例如
<?xml version="1.0"?>
<csv_data>
<row>
<articul>1107134</articul>
<type>car tires</type>
<brand>Aeolus</brand>
<name>Aeolus AL01 Trans Ace 195/75 R16C 107/105R</name>
<season>summer</season>
</row>
<row>
<articul>1107134</articul>
<type>car tires</type>
<brand>Aeolus</brand>
<name>Aeolus AL01 Trans Ace 195/75 R16 107/105R</name>
<season>summer</season>
</row>
</csv_data>
在結果我需要在<type>car tires</type>
替換到<type>new car tires</type>
,如果有像<name></name>
「R16C」(或R12C,R13C等)的值。符號「C」表示「新車輪胎」類型。否則,請不要更改字段名稱。
我有錯誤 「的foreach()在XML-parser.php提供的無效參數」
該怎麼做,請指教
$filename="./mos-test2.xml";
$dom = simplexml_load_file($filename);
foreach ($dom->documentElement->childNodes as $node) {
//print_r($node);
if($node->nodeType==1){
$OldJobId = $node->getElementsByTagName('name')->Item(0);
$newelement = $dom->createElement('name','new car type'.$OldJobId->nodeValue);
$OldJobId->parentNode->replaceChild($newelement, $OldJobId);
}
}
$str = $dom->saveXML($dom->documentElement);
我已經張貼一個答案,但它不包括''對你的問題的符號C'一部分,我會有點更新 –