How to change the attribute value of svg file

Posted by rafiq7s on Stack Overflow See other posts from Stack Overflow or by rafiq7s
Published on 2010-05-18T12:17:46Z Indexed on 2010/05/18 12:20 UTC
Read the original article Hit count: 247

Filed under:
|
|

Hello,

In samplexml.svg there is a node

<image width="744" height="1052" xlink:href="image1.png"/>

I need to replace "image1.png" with another value like "image2.png". Please guide me with sample code how to to that.

I could get the attribute value "image1.png". Here is the code:

> <?php $xdoc = new DomDocument;
> $xdoc->Load('samplexml.svg'); $tagName
> = $xdoc->getElementsByTagName('image')->item(0);
> $attribNode =
> $tagName->getAttributeNode('xlink:href');
> 
> echo "Attribute Name :
> ".$attribNode->name; echo "<br
> />Attribute Value :
> ".$attribNode->value; ?>

Here is samplexml.svg:

> <svg>  <g>   <title>Test title</title>
> <image x="0" y="0" width="744"
> height="1052"
> xlink:href="image1.png"/>  </g> </svg>

Please help me, how to change this attribute value.

Regards, rafiq7s

© Stack Overflow or respective owner

Related posts about php

Related posts about change