XML Formatting
Skip Navigation Links.

XML Formatting

Skip Navigation LinksHome :: ASP.NET :: XML :: Format XML


XML is very fussy about being well formed and some characters are just not allowed. Here's a helper function you can use to make strings XML 'legal'

        Public Shared Function ApplyXMLFormatting(ByVal strInput As String) As String

            ' replace characters that are illegal in XML documents

            strInput = Replace(strInput, "&", "&")

            strInput = Replace(strInput, "'", "'")

            strInput = Replace(strInput, """", """)

            strInput = Replace(strInput, ">", ">")

            strInput = Replace(strInput, "<", "&lt;")

            ApplyXMLFormatting = strInput

        End Function

Here's the code...

				Public Shared Function ApplyXMLFormatting(ByVal strInput As String) As String
								'	replace characters that are illegal in XML documents
								strInput = Replace(strInput, "&","&amp;" )
								strInput = Replace(strInput, "'", "&apos;")
								strInput = Replace(strInput, """", "&quot;")
								strInput = Replace(strInput, ">", "&gt;")
								strInput = Replace(strInput, "<", "&lt;")
								ApplyXMLFormatting = strInput
				End Function
Next >> XmlNodes
top of page
all content ©1996/2012 BennySutton.com
all images © their respective owners This site uses Thumbshots previews