in Opera when I serialize an xml doc, it returns the string with the XML Declaration added to it. In Firefox and Chrome this dose not occur, and i would like Opera to return same results as Firefox and Chrome.
http://jsfiddle.net/superbDeveloper/Qst5e/9/ (JavaScript Code below)
JavaScript Code
//test xml serializer
var s = new XMLSerializer();
var d = document;
var str = s.serializeToString(d);
console.log("1) serializeToString ");
console.log(str);
Results in Firefox
1) serializeToString
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"><head> <meta content="text/html; charset=UTF-8" http-equiv="content-type" /> <title> - jsFiddle demo by superbDeveloper</title> <script src="/js/lib/mootools-core-1.4.2-full-nocompat.js" type="text/javascript"></script> <link href="/css/normalize.css" type="text/css" rel="stylesheet" /> <link href="/css/result-light.css" type="text/css" rel="stylesheet" /> <style type="text/css"> </style>.....
Results in Opera
1) serializeToString
<?xml version="1.0"?><html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title> - jsFiddle demo</title>
<script type="text/javascript" src="/js/lib/mootools-core-1.4.2-full-nocompat.js"/>
<link rel="stylesheet" type="text/css" href="/css/normalize.css"/>
<link rel="stylesheet" type="text/css" href="/css/result-light.css"/>
<style type="text/css">
</style>...
Notice the XML Declaration <?xml version="1.0"?> has being added in Opera browser. Is there a way of stoping Opera from adding the XML Declaration? or how can one remove the XML Declaration? I thought of using substring but its not really an elegant solution.
Well, at this point what you have is a string, so using string methods is as elegant as it gets 🙂
I’m not aware of any other way to do it.