Converting MultiLine User Input into XML
-
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---
-
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---
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! -
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!The best way to correctly escape things is to just use a XmlTextWriter to build your XML rather than StringBuilder directly. -Blake
-
The best way to correctly escape things is to just use a XmlTextWriter to build your XML rather than StringBuilder directly. -Blake
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--- -
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---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
-
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
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---