Sunday, February 2, 2014

XMLSerializer: some problem about usage

Conditions:

Chrome Version: 32.0.1700.102

Operating System: Ubuntu Linux and Windows XP


Issue description: I'm creating a template based on XHTML 1.0 Transitional.

During my elaboration process (made by js) I need to get a DOM element and convert it as string. It seems that the class XMLSerializer doesn't work correctly or something else happen. Anyway, the string obtained isn't an XML correctly formatted.


In order to clarify better this problem I prepared a demo code on jsfiddle: http://jsfiddle.net/Xj6QL/3/

On the next lines I reported the code applied on the demo.In brief, what happen after the user perform a click on the button is an acquisition on a DOM element and its and relative serialization( see "first"). Subsequently the output obtained re-parsed (DOMParser) and re-serialized for a second time (see "next"). If everything goes right these two string should be identical.

If you check it by mean of FF the result is correct, instead, with Chrome, the output present some error.

can someone help me to understand what happen?
Thank you
Claudio

The code applied on jsfiddle is this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

   <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8"/>

   <meta http-equiv="X-UA-Compatible" content="IE=edge"/>

   <script src="../../js/jquery/jquery-1.10.2.js" type="text/javascript"></script>

   <script src="test.js" type="text/javascript"></script>

   <title>Test</title>

</head>

<body style="font-size: 16px;">

<div id="vbody">

   <img class="cycle" src="images/logo1.jpg" alt="Demo logo 1" title="Demo logo 1"/>

   <img class="cycle" src="images/logo2.jpg" alt="Demo logo 1" title="Demo logo 1"/>

   <img class="cycle" src="images/logo3.jpg" alt="Demo logo 1" title="Demo logo 1"/>

   <img class="cycle" src="images/logo4.jpg" alt="Demo logo 1" title="Demo logo 1"/>

</div>

<div class="clear"></div>

<button id="mybutton">click here</button>

</body>

</html>


Here the js:

$(function () {

   $("#mybutton").click(function() {

       var f = '<div id="vbody"> </div>';


       var first = Xml2String($("#vbody")[0]);

       console.log(first);

       var parser=new DOMParser();

       var xmlDoc=parser.parseFromString(first,"text/xml");

       var next = Xml2String(xmlDoc);

       console.log("------------");

       console.log(next);


   });


   function Xml2String(xmlData) {

       if (window.ActiveXObject) {

           return xmlData.xml;

       }

       var s = new XMLSerializer();

       return s.serializeToString(xmlData);

   }

});


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment