使用.NET XLinq解析svg - 'xlink'是未声明的前缀

时间:2012-02-29 15:35:55

标签: .net xml svg linq-to-xml

我正在尝试使用以下行将一串svg解析为XElement:

XElement productSvg = XElement.Parse(svgString);

但我收到以下异常: XmlException - 'xlink'是未声明的前缀 这是我的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>

有谁知道如何在.NET XLinq中成功解析包含命名空间的xml属性?

1 个答案:

答案 0 :(得分:2)

这是一个很好的解决方案,对我来说很完美:

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