开发者

Getting the complete XML source out of an XML DOM object

The "Highcharts" library for rendering nice interactive Charts inside the browser has an export function, which sends it's internally used SVG to some server side application that raste开发者_运维技巧rizes it and sends the resulting PNG, JPEG or PDF back for downloading.

My problem is that background images and symbols that can be displayed inside the browser are being thrown away before exporting by Highcharts, but I want them.

So I commented out everything that deletes all their SVG <image> tags and so on (they are using regular expressions for sanitizing their internally used SVG, by the way...).

But they are using some non-standard attributes for these <image> tags and their coordinates are mapped differently to the images, so I have to recalculate things and throw away attributes.

So I parsed their SVG using DOMParser and did the stuff I should be doing, bot now I'm searching for an elegant (or simple) way to get the raw xml - I've seen that in Internet Explorer it's possible to get the raw xml using the xml attribute of the DOM Document Object - Is there something equivalent for all the other browsers? I'm searching a whole while now and could not find anything really helpful. Thanks :)


You can use XMLSerializer in non-IE browsers. The following function will serialize an XML node in all major browsers:

function serializeXmlNode(xmlNode) {
    if (typeof window.XMLSerializer != "undefined") {
        return (new window.XMLSerializer()).serializeToString(xmlNode);
    } else if (typeof xmlNode.xml != "undefined") {
        return xmlNode.xml;
    }
    return "";
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜