none
XmlReader and normalized newline characters

    Question

  • Hello All

    I recently upgraded my asp.net web application to 2.0 framework.

    In one of my applications, i store newline character( CHAR(13)) as part of the string in a SQL table field for formatting purpose.

    Earlier i used to use XmlTextReader to read the input returned from the command object

    XmlTextReader myXmlReader = (XmlTextReader)myCmd.ExecuteXmlReader();

    I then used to search for the newline character in my XSLT for the above field and insert html break <br/> tags for proper formatting .

    Now after the upgrade, i don't use XmlTextReader class as recommended by MS and use xmlReader directly

    XmlReader myXmlReader = myCmd.ExecuteXmlReader();

    The problem is , this normalizes the new line character to space  in the xml data(attribute values) and hence my XSLT fails to find the newline character and hence doesn;t return formatted html

    Is there a way to search for a normalized space in my xslt so that i can explicitly insert break tags<br/> in my xslt

    Please help me

    Cheers

    Here's my xslt function

    <xsl:template name="tmplFormatTxt">
     <xsl:param name="inputTxt"></xsl:param>

     <xsl:variable name="lPart" select="substring-before($inputTxt,'&#13;')"/>
     <xsl:variable name="rPart" select="substring-after($inputTxt,'&#13;')"/>

     <xsl:choose>
      <xsl:when test="contains($inputTxt,'&#13;')">
       <xsl:value-of select="$lPart"/><br></br>
      </xsl:when>
      <xsl:otherwise>
       <xsl:value-of select="$inputTxt"/>
      </xsl:otherwise>
     </xsl:choose>
     
     <xsl:choose>
      <xsl:when test="contains($rPart,'&#13;')">
       <xsl:call-template name="tmplFormatTxt">
        <xsl:with-param name="inputTxt"><xsl:value-of select="$rPart"/></xsl:with-param>
       </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
       <xsl:value-of select="$rPart"/>
      </xsl:otherwise>
     </xsl:choose>

    </xsl:template>

     

     

     

    Wednesday, June 21, 2006 8:58 PM

Answers

  • XML parser should normalize whitespaces in the attributes.

    XmlTextReader has property Normalization that controls this behavior and it was off by default.

    In V.2 myCmd.ExecuteXmlReader(); doesn't return you XmlTextReader and you has no change to disable attribute normalization.

    As soon as new line is normalized to space nothing can help you find that it was there.

    The best options for you is store strings with new lines as text nodes not as attribute values.

    Friday, June 23, 2006 6:50 PM

All replies

  • XML parser should normalize whitespaces in the attributes.

    XmlTextReader has property Normalization that controls this behavior and it was off by default.

    In V.2 myCmd.ExecuteXmlReader(); doesn't return you XmlTextReader and you has no change to disable attribute normalization.

    As soon as new line is normalized to space nothing can help you find that it was there.

    The best options for you is store strings with new lines as text nodes not as attribute values.

    Friday, June 23, 2006 6:50 PM
  • Thank You

    It worked.

    best regards

    Friday, March 16, 2007 9:02 PM