AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Analytics
4.8K members online now
4.8K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

XML Formatting Error

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Error Parsing XML Google Content Experiment generated code when manually inserted in template.

“Could not load template preview: Error parsing XML, line 10, column 57: The content of elements must consist of well-formed character data or markup.”

 

How do I get a coding error fixed in Google's code.

 

Code follows:

 

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

<!DOCTYPE html>

<html b:version='2' class='v2' expr:dir='data:blog.languageDirection' xmlns='http://www.w3.org/1999/xhtml' xmlns:b='http://www.google.com/2005/gml/b' xmlns:data='http://www.google.com/2005/gml/data' xmlns:expr='http://www.google.com/2005/gml/expr'>

  <head>

<!-- Google Analytics Content Experiment code -->

<script>function utmx_section(){}function utmx(){}(function(){var

k='123291265-4',d=document,l=d.location,c=d.cookie;

if(l.search.indexOf('utm_expid='+k)>0)return;

function f(n){if(c){var i=c.indexOf(n+'=');if(i>-1){var j=c.

indexOf(';',i);return escape(c.substring(i+n.length+1,j<0?c.  [Line 10] *****

length:j))}}}var x=f('__utmx'),xx=f('__utmxx'),h=l.hash;d.write(

'<sc'+'ript src="'+'http'+(l.protocol=='https:'?'s://ssl':

'://www')+'.google-analytics.com/ga_exp.js?'+'utmxkey='+k+

'&utmx='+(x?x:'')+'&utmxx='+(xx?xx:'')+'&utmxtime='+new Date().

valueOf()+(h?'&utmxhash='+escape(h.substr(1)):'')+

'" type="text/javascript" charset="utf-8"><\/sc'+'ript>')})();

</script><script>utmx('url','A/B');</script>

<!-- End of Google Analytics Content Experiment code -->

 

<script>

  (function(i,s,o,g,r,a,m){i[&#39;GoogleAnalyticsObject&#39;]=r;i[r]=i[r]||function(){

  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)

  })(window,document,&#39;script&#39;,&#39;https://www.google-analytics.com/analytics.js&#39;,&#39;ga&#39Smiley Wink;

 

  ga(&#39;create&#39;, &#39;UA-171733-7&#39;, &#39;auto&#39Smiley Wink;

  ga(&#39;send&#39;, &#39;pageview&#39Smiley Wink;

 

</script>

 

 

 

1 Expert replyverified_user

Re: XML Formatting Error

[ Edited ]
Top Contributor
# 2
Top Contributor

If you need to embed scripts in a web page that you are generating from XML, you need to make sure that the two markup characters < and & are either escaped as &lt; and &amp; respectively, or that each script's content is enclosed in a CDATA Section so that it doesn't get seen as markup.

Essentially, when you have a SCRIPT tag, you should contain its content within a CDATA tag, like so:

<script>
<![CDATA[ // Add experiment code function utmx_section(){}function utmx(){}(function(){var k='123291265-4',d=document,l=d.location,c=d.cookie; if(l.search.indexOf('utm_expid='+k)>0)return; function f(n){if(c){var i=c.indexOf(n+'=');if(i>-1){var j=c.indexOf(';',i);return escape(c.substring(i+n.length+1,j<0?c.length:j))}}}var x=f('__utmx'),xx=f('__utmxx'),h=l.hash;d.write( '<sc'+'ript src="'+'http'+(l.protocol=='https:'?'s://ssl': '://www')+'.google-analytics.com/ga_exp.js?'+'utmxkey='+k+ '&utmx='+(x?x:'')+'&utmxx='+(xx?xx:'')+'&utmxtime='+new Date(). valueOf()+(h?'&utmxhash='+escape(h.substr(1)):'')+ '" type="text/javascript" charset="utf-8"><\/sc'+'ript>')})(); </script><script>utmx('url','A/B'); // Throw in GA code while we're at it (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-171733-7', 'auto'); ga('send', 'pageview'); ]]> </script>
VP & Chief Evangelist at Hub'Scan | Contact me
Level 80 Digital Analytics Warrior, KPI Therapist and Keeper of the One True Tagging Plan