tags:

views:

116

answers:

2

I am facing a problem after transformation of an XML file and saving it, i.e. I'm not getting the XML file top tag <?xml version="1.0" encoding="utf-8"?>.

Below is my XSLT file:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
  <xsl:output method="xml" indent="yes" encoding="utf-8"
  omit-xml-declaration="no" />

  <xsl:template match="*">
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>

  <!-- ... -->
</xsl:stylesheet >

I think the absence of this tag causing errors like "An invalid character was found in text content."

Can any one help me to get a solution. Thanks in advance.

+1  A: 

Most likely, the code that produces the transformation is where you need to look. Most XSLT libs have a switch somewhere that tells it whether or not to output an xml declaration, since XSLT can be used to output anything.

An invalid character error is most likely exactly what it sounds like. A character that is not valid for UTF8 was found in the text content.

Jeff Ober
A: 

I encountered the error "An invalid character was found in text content" only this morning. In this case it occurred when passing XML to a SQL stored procedure as a parameter. If you are using SQL Server 2000 (which I was) you need to make sure the parameter in the stored procedure is defined using the NTEXT type, and not the TEXT type.

CREATE PROCEDURE Xml_Test
   @MyXML NTEXT
AS
   ....
Tim C
File not generated from Sql Server.
pravakar