Exception when pasting XHTML in Content Editor in Source View Mode

Topics: General
Apr 29, 2011 at 12:14 PM

 

Pasting  following XHTML code:

<?xml version="1.0" encoding="iso-8859-1"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
	<title>C1 Composite Sample error</title>
</head>

<body>
</body>
</html>
	

Causes exception in:

	\Website_v2.1\Composite\services\WysiwygEditor\XhtmlTransformations.asmx
	line 234

		[WebMethod]
		public XhtmlTransformationResult StructuredContentToTinyContent(string htmlFragment)
		{
			try
			{
				string warnings = "";
				string XhtmlPassSsltPath = Server.MapPath("..\\..\\transformations\\WysiwygEditor_StructuredContentToTinyContent.xsl");

				string html = WrapInnerBody(htmlFragment);

				XDocument xml = MarkupTransformationServices.TidyXml(html);

				IEnumerable<XElement> functionRoots = xml.Descendants(Namespaces.Function10 + "function").Where(f => f.Ancestors(Namespaces.Function10 + "function").Count() == 0);
				foreach (var functionElement in functionRoots.ToList())
				{
					functionElement.ReplaceWith(GetImageTagForFunctionCall(functionElement));
				}

				IEnumerable<XElement> dataFieldReferences = xml.Descendants(Namespaces.DynamicData10 + "fieldreference");
				foreach (var referenceElement in dataFieldReferences.ToList())
				{
					referenceElement.ReplaceWith(GetImageTagForDynamicDataFieldReference(referenceElement));
				}

				Dictionary<string, string> xsltParameters = new Dictionary<string, string>();
				xsltParameters.Add("requestapppath", UrlUtils.PublicRootPath);

				XDocument structuredResult = MarkupTransformationServices.RepairXhtmlAndTransform(xml.ToString(), XhtmlPassSsltPath, xsltParameters, out warnings);

				string bodyInnerXhtml = MarkupTransformationServices.OutputBodyDescendants(structuredResult);

				XhtmlTransformationResult result = new XhtmlTransformationResult();
				result.Warnings = warnings;
				result.XhtmlFragment = bodyInnerXhtml.Replace("\xA0", _nbspNumeric).Replace(_nbsp, _nbspNumeric);

				return result;
			}
			catch (Exception ex)
			{
				LoggingService.LogError("XhtmlTransformation", ex.ToString());
				// exception thrown here
				throw;
			}
		}



System.Xml.XmlException was unhandled by user code
  Message=Unexpected XML declaration. The XML declaration must be the first node in the document, 
  and no white space characters are allowed to appear before it. 
  Line 8, position 3.
  Source=System.Xml
  LineNumber=8
  LinePosition=3
  SourceUri=""
  StackTrace:
	   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
	   at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
	   at System.Xml.XmlTextReaderImpl.ParsePI(StringBuilder piInDtdStringBuilder)
	   at System.Xml.XmlTextReaderImpl.ParsePI()
	   at System.Xml.XmlTextReaderImpl.ParseElementContent()
	   at System.Xml.XmlTextReaderImpl.Read()
	   at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)
	   at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o)
	   at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
	   at System.Xml.Linq.XDocument.Parse(String text, LoadOptions options)
	   at System.Xml.Linq.XDocument.Parse(String text)
	   at Composite.Core.WebClient.Services.WysiwygEditor.MarkupTransformationServices.TidyXml(String xmlMarkup)
	   at Composite.Services.XhtmlTransformations.StructuredContentToTinyContent(String htmlFragment) in d:\SRC\HolisticWare\HolisticWare_Web_CMS_C1\Website_v2.1\Composite\services\WysiwygEditor\XhtmlTransformations.asmx:line 234
  InnerException: 	

Stepping further with debugger got C1 console altert error: "Error in source code: Unknown error"

Note: switching from Source View to Visual purges html (removes) <?xml version="1.0" encoding="iso-8859-1"?>

Pasting following code in Source view of the Content page and saving does not throw exception

<!--
C1 generated!!
<title>Title max 65 char all keywords</title>
<meta name="Description" content="Description all keywords" />
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
</head>
<body>
</body>
</html>	

Or adding whitespace in the firs line of code (space or tab before <?xml version="1.0" encoding="iso-8859-1"?>

 <?xml version="1.0" encoding="iso-8859-1"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
	<title>C1 Composite Sample error</title>
</head>

<body>
</body>
</html>	

Does not throw an Exception but alert comes up in C1 console

Unexpected xml declaration. Xml declaration must be first node in the document and no whitespace characters are allowed to appear before it. Line 1 position 4.

regards

mel

Coordinator
Apr 29, 2011 at 12:46 PM

Are you running the site with Visual Studio in debug mode, with "Break when an exception is... Thrown" for CLR exceptions (check in Debug | Exceptions ...)?