在samplexml.svg有一個節點如何改變SVG文件的屬性值
<image width="744" height="1052" xlink:href="image1.png"/>
我需要像「image2.png」另一個值來代替「image1.png」。請用示例代碼指導我如何做到這一點。
我可以得到屬性值「image1.png」。下面是代碼:
$xdoc = new DomDocument;
$xdoc->Load('samplexml.svg');
$tagName = $xdoc->getElementsByTagName('image')->item(0);
$attribNode = $tagName->getAttributeNode('xlink:href');
echo "Attribute Name : " . $attribNode->name . "<br/>";
echo "Attribute Value : " . $attribNode->value;
這裏是samplexml.svg:
<svg>
<g>
<title>Test title</title>
<image x="0" y="0" width="744" height="1052" xlink:href="image1.png"/>
</g>
</svg>
如何編程方式更改的XLink:href的值?
-1提示查找/替換。 – 2010-05-18 12:27:14
聖牛,所以你不能建議更好的選擇?放鬆傢伙。 – zaf 2010-05-18 12:29:51
我已經離開[我自己的答案](http://stackoverflow.com/questions/2857113/how-to-change-the-attribute-value-of-svg-file/2857206#2857206)。只是給你提供反饋意見。每當有人建議搜索/替換XML/HTML數據時,神會殺死一隻小貓。 – 2010-05-18 12:34:12