Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Converting MultiLine User Input into XML

Converting MultiLine User Input into XML

Scheduled Pinned Locked Moved ASP.NET
questioncsharpasp-netdatabase
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mittalpa
    wrote on last edited by
    #1

    Hi, Environment - VB.NET, ASP.NET, SQL Server 2000. In one of Input forms, the user fill some text as a paragraph. As long as it is one line, I am able to capture that data and form and XML. But, once the user fills Mulit-Line data, then Data Capture into XML breaks. The XML doesn't get formed. I tried using CDATA but that didn't help either. Please advice how can I insert MultiLine data into XML? Please advice. Thanks Pankaj Follow your goals, Means will follow you ---Gandhi---

    M 1 Reply Last reply
    0
    • M mittalpa

      Hi, Environment - VB.NET, ASP.NET, SQL Server 2000. In one of Input forms, the user fill some text as a paragraph. As long as it is one line, I am able to capture that data and form and XML. But, once the user fills Mulit-Line data, then Data Capture into XML breaks. The XML doesn't get formed. I tried using CDATA but that didn't help either. Please advice how can I insert MultiLine data into XML? Please advice. Thanks Pankaj Follow your goals, Means will follow you ---Gandhi---

      M Offline
      M Offline
      Marc Clifton
      wrote on last edited by
      #2

      mittalpa wrote: The XML doesn't get formed. Without a better description of what your code is doing, it's hard to say, but I know that I've pulled my hair out in the past when dealing with strings with embedded CR-LF characters. For example, you're probably doing something like this: string xmlString=xmlStuff + inputFormData + morexmlStuff; and it seems to me that the embedded CR's are causing the XML stuff to break. You'll either have to replace the CR-LF with a custom character and reverse the process when you read them back out (this is NOT the preferable solution), or figure out how to escape the CR-LF chars, like the way the '\' character in C is the escape character. If I'm barking up the wrong tree, just throw a newspaper at me. :-D Marc Latest AAL Article My blog Join my forum!

      B 1 Reply Last reply
      0
      • M Marc Clifton

        mittalpa wrote: The XML doesn't get formed. Without a better description of what your code is doing, it's hard to say, but I know that I've pulled my hair out in the past when dealing with strings with embedded CR-LF characters. For example, you're probably doing something like this: string xmlString=xmlStuff + inputFormData + morexmlStuff; and it seems to me that the embedded CR's are causing the XML stuff to break. You'll either have to replace the CR-LF with a custom character and reverse the process when you read them back out (this is NOT the preferable solution), or figure out how to escape the CR-LF chars, like the way the '\' character in C is the escape character. If I'm barking up the wrong tree, just throw a newspaper at me. :-D Marc Latest AAL Article My blog Join my forum!

        B Offline
        B Offline
        Blake Coverett
        wrote on last edited by
        #3

        The best way to correctly escape things is to just use a XmlTextWriter to build your XML rather than StringBuilder directly. -Blake

        M 1 Reply Last reply
        0
        • B Blake Coverett

          The best way to correctly escape things is to just use a XmlTextWriter to build your XML rather than StringBuilder directly. -Blake

          M Offline
          M Offline
          mittalpa
          wrote on last edited by
          #4

          this is what I cam up with finally ... Public Function EncodeData(ByVal strParam as String) as String 'This function encode the input string and return it. Dim strHTMLEncode as String strHTMLEncode = strParam.Replace(VbCrLf, " ") strHTMLEncode = strHTMLEncode.Replace("'", "'") EncodeData = Server.HtmlEncode(strHTMLEncode) End Function Public Function DecodeData(ByVal strParam as String) as String 'This function decode the input string and return it. Dim strHTMLDecode as String strHTMLDecode = Server.HtmlDecode(strParam.Replace(" ", VbCrLf)) strHTMLDecode = strHTMLDecode.Replace("'", "'") DecodeData = strHTMLDecode End Function works like a charm..:-D:);) Follow your goals, Means will follow you ---Gandhi---

          B 1 Reply Last reply
          0
          • M mittalpa

            this is what I cam up with finally ... Public Function EncodeData(ByVal strParam as String) as String 'This function encode the input string and return it. Dim strHTMLEncode as String strHTMLEncode = strParam.Replace(VbCrLf, " ") strHTMLEncode = strHTMLEncode.Replace("'", "'") EncodeData = Server.HtmlEncode(strHTMLEncode) End Function Public Function DecodeData(ByVal strParam as String) as String 'This function decode the input string and return it. Dim strHTMLDecode as String strHTMLDecode = Server.HtmlDecode(strParam.Replace(" ", VbCrLf)) strHTMLDecode = strHTMLDecode.Replace("'", "'") DecodeData = strHTMLDecode End Function works like a charm..:-D:);) Follow your goals, Means will follow you ---Gandhi---

            B Offline
            B Offline
            Blake Coverett
            wrote on last edited by
            #5

            This only works like a charm because you haven't tried it with enough test cases. See what happens if the user types a '<', '>' or '&' in your test box. Depending on various other code and configuation things you may find accented characters a problem too. Use XmlTextWriter, it is your friend. -Blake

            M 1 Reply Last reply
            0
            • B Blake Coverett

              This only works like a charm because you haven't tried it with enough test cases. See what happens if the user types a '<', '>' or '&' in your test box. Depending on various other code and configuation things you may find accented characters a problem too. Use XmlTextWriter, it is your friend. -Blake

              M Offline
              M Offline
              mittalpa
              wrote on last edited by
              #6

              In my code, I am also using "Server.HtmlEncode", which to my surprise took care of all the characters visible on key-board including &, <, >. As you suggested, I will definitely look into XMLTextWriter. Follow your goals, Means will follow you ---Gandhi---

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups