[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: Problem in displaying & in XML node


Subject: Re: Problem in displaying & in XML node
From: Hari Yerram <yerram@xxxxxxxxxx>
Date: Thu, 10 Jun 1999 10:10:51 -0400

Thank you for spending time on this.

    There is another way of doing this by using the 'Replace' function of
VBScript. The replace function will replace the findstring with the
replacestring, if the findstring not found then it returns the same string.
you need not process every character and look for it. But internally it may
does the same thing(you need not bother about it :-))

Kay Michael wrote:

> > -----Original Message-----
> > From: Hari Yerram [mailto:yerram@xxxxxxxxxx]
> > Sent: 09 June 1999 19:48
> > To: xsl-list@xxxxxxxxxxxxxxxx
> > Subject: Problem in displaying & in XML node
> >
> >
> > please look the following code.
> >
> >             email = "" + Request("email");
> >
> >             sError = "<ERROR TYPE='Email_Info'>";
> >             sError += "<Subject>";
> >             sError += subject;
> (etc)
> >
> > The Problem is If i have '&' (ampersand) character in my XML
> > node ...
>
> > Is there a way to resolve it?
> >
> You need to write
>                  sError += xmlEscape(subject);
>
> where xmlEscape() is a function that substitutes special characters with
> their escaped forms, e.g. "&" changes to "&amp;".
>
> Here is a very simple unoptimised VBScript version (it doesn't attempt to
> handle
> non-ASCII characters):
>
> Public Function xmlEscape(s As String)
>     Dim i As Integer
>     Dim t As String
>     Dim c As String
>
>     i = 1
>     t = ""
>     Do While i <= Len(s)
>         c = Mid$(s, i, 1)
>         If c = "<" Then
>             t = t & "&lt;"
>         ElseIf c = ">" Then
>             t = t & "&gt;"
>         ElseIf c = "'" Then
>             t = t & "&#39;"
>         ElseIf c = """" Then
>             t = t & "&#34;"
>         ElseIf c = "&" Then
>             t = t & "&amp;"
>         Else
>             t = t & c
>         End If
>         i = i + 1
>     Loop
>
>     xmlEscape = t
>
> End Function
>
> Mike Kay
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords
xml