?
Solved

ASP.NET and XML Encoding

Posted on 2004-08-13
3
Medium Priority
?
213 Views
Last Modified: 2010-04-07
I have a procedure that takes in a path to the file and a string containing xml data, and then writes it to the file to which the path is provided:

Sub WriteXMLToFile(ByVal filePath As String, ByVal xmltext As String)
        Dim xsr As XmlTextReader
        Dim xsw As XmlTextWriter
        Dim file As String

        Try
            xsr = New XmlTextReader(filePath)
            file = xsr.ReadInnerXml
            xsr.Close()
            file = xmltext
            xsw = New XmlTextWriter(filePath, Encoding.UTF8)
            xsw.WriteString(file)

        Catch ex As Exception
            Response.Write("The following error has occurred when writing to a file: " & ex.Message)
        Finally
            xsw.Close()
        End Try
    End Sub

The problem with the procedure is that it replaces < and > signs with &lt; and &gt;

How can I avoid that?
0
Comment
Question by:YZlat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 15

Accepted Solution

by:
Thogek earned 320 total points
ID: 11797051
Maybe because it thinks you're writing a XML node's value, when you're trying to write the XML node itself....

If your xmltest variable already contains known-to-be-valid XML text, then perhaps something simpler such as:

    Sub WriteXMLToFile(ByVal filePath As String, ByVal xmltext As String)
        Dim sw As StreamWriter

        Try
            StreamWriter = New StreamWriter(filePath, False, Encoding.UTF8)
            sw.Write(xmltext)
            sw.Close()
        Catch ex As Exception
            Response.Write("The following error has occurred when writing to a file: " & ex.Message)
        Finally
            xsw.Close()
        End Try
    End Sub
0
 
LVL 15

Expert Comment

by:Thogek
ID: 11797069
Here's the XmlTextWriter.WriteString method (that you're currently using), for comparison: http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemxmlxmltextwriterclasswritestringtopic.asp
0
 
LVL 15

Expert Comment

by:Thogek
ID: 11797081
Or, if you'd rather stick with the XmlTextWriter, try switching from the WriteString method to using the WriteRaw Method.  http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemxmlxmltextwriterclasswriterawtopic1.asp
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question