Search code examples
htmlmsbuildtransformxdt-transform

xdt transform fails on HTML file on P tag


I am trying to apply a transform to an HTML file. The transform works correctly with divs and spans but as soon as I insert a P tag it will fail.

The HTML file I am transforming is:

<!DOCTYPE html>
<html>
  <head>
    <title>STREAM Interactive - UAT</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  </head>
    <body>
          <p>my para</p>
    </body>
</html>

The transform file is very simple:

<html xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
   <head>
     <title xdt:Transform="Replace">TITLEHEADINGHERE</title>
   </head>  

</html>

The project file that is used to do the transform is:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="TransformXml" AssemblyFile="C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.Dll"/>

    <PropertyGroup>
        <SourceFile>web.config</SourceFile>
        <TransformFile>web.debug.config</TransformFile>
        <OutputFile>final.config</OutputFile>
    </PropertyGroup>

    <Target Name="GenerateConfigs">
        <Message Text="Beginning Transformation." />
        <Message Text="$(SourceFile)" />
        <TransformXml Source="$(SourceFile)" Transform="$(TransformFile)" Destination="$(OutputFile)" />
        <Message Text="Completed Transformation." />
    </Target>

</Project>

The command used is:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe D:\SAM\SAMSite\bin\msbuild-transform-Template.xml /p:SourceFile="C:\temp\buildTest\BlueZone\2.3.10.5\PublishedClickOnce\index.html" /p:TransformFile="D:\SAM\SAMSite\bin\TransformTemplates\clickonce.index.transform.temp" /p:OutputFile="C:\temp\buildTest\BlueZone\2.3.10.5\PublishedClickOnce\index.html.temp"

The output / error I get is:

Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.269]
Copyright (C) Microsoft Corporation 2007. All rights reserved.

Build started 02/07/2012 10:54:33.
Project "D:\SAM\SAMSite\bin\msbuild-    transform-Template.xml" on node 1 (default targets).
GenerateConfigs:
  Beginning Transformation.
  C:\temp\buildTest\BlueZone\2.3.10.5\PublishedClickOnce\index.html
  Transforming Source File:     C:\temp\buildTest\BlueZone\2.3.10.5\PublishedClickOnce\index.html
  Transformation succeeded
D:\SAM\SAMSite\bin\msbuild-transform-Template.xml(13,3): error MSB4018: The "TransformXml" task failed unexpectedly.
D:\SAM\SAMSite\bin\msbuild-transform-    Template.xml(13,3): error MSB4018: System.UriFormatException: Invalid URI: The URI is empty.
D:\SAM\SAMSite\bin\msbuild-transform-    Template.xml(13,3): error MSB4018:    at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
D:\SAM\SAMSite\bin\msbuild-transform-Template.xml(13,3): error MSB4018:    at Microsoft.Web.Publishing.Tasks.TransformXml.Execute()
D:\SAM\SAMSite\bin\msbuild-transform-Template.xml(13,3): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
D:\SAM\SAMSite\bin\msbuild-transform-Template.xml(13,3): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean& taskResult)
Done Building Project "D:\SAM\SAMSite\bin\msbuild-transform-Template.xml" (default targets) -- FAILED.

Build FAILED.

"D:\SAM\SAMSite\bin\msbuild-transform-Template.xml" (default target) (1) ->
(GenerateConfigs target) -> 
  D:\SAM\SAMSite\bin\msbuild-transform-Template.xml(13,3): error MSB4018: The "TransformXml" task failed unexpectedly.
D:\SAM\SAMSite\bin\msbuild-transform-Template.xml(13,3): error MSB4018: System.UriFormatException: Invalid URI: The URI is empty.
D:\SAM\SAMSite\bin\msbuild-transform-Template.xml(13,3): error MSB4018:    at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
D:\SAM\SAMSite\bin\msbuild-transform-Template.xml(13,3): error MSB4018:    at Microsoft.Web.Publishing.Tasks.TransformXml.Execute()
D:\SAM\SAMSite\bin\msbuild-transform-Template.xml(13,3): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
D:\SAM\SAMSite\bin\msbuild-transform-Template.xml(13,3): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean& taskResult)

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.09

The HTML has been stripped down to the barest possible, previously there have been div's and spans in there. Interestingly, if I gave the P tag a class it works.

I have no idea why this would be the case.

EDIT

As per @Kieren's suggestion I have tried to run using the TransformXml directly. I get a new error:

Data at the root level is invalid. Line 1, position 1.

   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.XmlTextReader.Read()
   at Microsoft.Web.Publishing.Tasks.XmlAttributePreservationDict.ReadPreservationInfo(String elementStartTag)
   at Microsoft.Web.Publishing.Tasks.XmlAttributePreservationProvider.GetDictAtPosition(Int32 lineNumber, Int32 linePosition)
   at Microsoft.Web.Publishing.Tasks.XmlFileInfoDocument.XmlFileInfoElement..ctor(String prefix, String localName, String namespaceUri, XmlFileInfoDocument document)
   at Microsoft.Web.Publishing.Tasks.XmlFileInfoDocument.CreateElement(String prefix, String localName, String namespaceURI)
   at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace)
   at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
   at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
   at System.Xml.XmlDocument.Load(XmlReader reader)
   at Microsoft.Web.Publishing.Tasks.XmlFileInfoDocument.LoadFromTextReader(TextReader textReader)
   at Microsoft.Web.Publishing.Tasks.XmlFileInfoDocument.LoadFromFileName(String     filename)
   at Microsoft.Web.Publishing.Tasks.XmlFileInfoDocument.Load(String filename)
   at QuickTests.TestTransformXml.OpenSourceFile(String sourceFile) in C:\Users\jon\Documents\Visual Studio 2010\Projects\QuickTests\QuickTests\TestTransformXmlTask.cs:line 140

Solution

  • According to the bug report I filed this has now been fixed. Assuming it will be included in the next release of MsBuild, (don't know when that will be):

    https://connect.microsoft.com/VisualStudio/feedback/details/752279/msbuild-tansform-failure-for-elements-with-only-one-character