Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing svg using .NET XLinq - 'xlink' is an undeclared prefix

I'm trying to parse a string of svg into an XElement using the following line:

XElement productSvg = XElement.Parse(svgString);

But I'm getting the following exception: XmlException - 'xlink' is an undeclared prefix Here's my svg:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<svg id="svg62433" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 595.19 596.32" version="1.1" xmlns:cc="http://creativecommons.org/ns#" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/">
        <g id="g7123">
            <path id="path5588" d="m404.54,164.29c0,121.64-98.612,220.26-220.26,220.26-121.64,0-220.26-98.612-220.26-220.26,0-121.64,98.612-220.26,220.26-220.26,121.64,0,220.26,98.612,220.26,220.26z" transform="matrix(0.01922722,0.99981514,-0.99981514,0.01922722,536.42634,464.95177)" fill="none"/>
            <text id="text5590" style="writing-mode:lr-tb;letter-spacing:0px;text-anchor:middle;word-spacing:0px;text-align:center;" font-weight="bold" font-size="64px" line-height="125%" font-stretch="normal" font-variant="normal" font-style="normal" font-family="'Swis721 Cn BT'">
                <textPath id="textPath5598" xlink:href="#path5588" startOffset="50%">
                    <tspan id="contentTopText" style="writing-mode:lr-tb;text-anchor:middle;text-align:center;" font-weight="bold" font-size="64px" line-height="125%" font-stretch="normal" font-variant="normal" font-style="normal" font-family="'Swis721 Cn BT'">Text Here</tspan>
                </textPath>
            </text>
        </g>
</svg>

Does anyone know how to successfully parse xml attributes in .NET XLinq that contain namespaces?

like image 290
KodeKreachor Avatar asked Nov 04 '22 04:11

KodeKreachor


1 Answers

Here's a great solution to this problem, worked perfect for me:

http://aspnetgotyou.blogspot.com/2010/06/xdocument-or-xelement-with-xmlnamespace.html

like image 143
KodeKreachor Avatar answered Nov 09 '22 13:11

KodeKreachor