[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

ASP.NET and XML Encoding

Posted on 2004-08-13
3
Medium Priority
?
217 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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 Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

649 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