I have such a working main.svg file:
<?xml version="1.0" encoding="UTF-8" ?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs id ="mydefs">
<marker id="markerEnd" markerWidth="15" markerHeight="15" refX="7" refY="7" orient="auto">
<path d="M0,0 l7,7 l-7,7" style="stroke: #000000;fill: none;"/>
</marker>
</defs>
<line x1="0" y1="0" x2="200" y2="200" stroke="black" marker-end="url(#markerEnd)"/>
</svg>
Now I wish to move defs into a separated file.
defs.svg:
<?xml version="1.0" encoding="UTF-8" ?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs id ="mydefs">
<marker id="markerEnd" markerWidth="15" markerHeight="15" refX="7" refY="7" orient="auto">
<path d="M0,0 l7,7 l-7,7" style="stroke: #000000;fill: none;"/>
</marker>
</defs>
</svg>
I could use: marker-end="url(defs.svg#markerEnd)"
, but I wish to inject id's from defs.svg to main.svg to still use marker-end="url(#markerEnd)"
.
How do I change my main.svg to use marker identificator from external defs.svg?
Such main.svg does not draw markerEnd:
<?xml version="1.0" encoding="UTF-8" ?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<use xlink:href="defs.svg#mydefs" />
</defs>
<use xlink:href="defs.svg#mydefs" />
<line x1="0" y1="0" x2="200" y2="200" stroke="black" marker-end="url(#markerEnd)"/>
</svg>
I know about Cross Origin Policy for local files in Google Chrome and this is not the issue, I tested on many other browsers.
if you need HTML to test SVG:
<!DOCTYPE html>
<html>
<head>
<style>
html, body, object {
width: 100%;
height: 100%;
}
</style>
<body>
<object type="image/svg+xml" data="main.svg"></object>
</body>
</html>
There is such question: I it possible to include external SVG defs But from those answers I can't understand how to solve the problem.