C# ,Convert string to xhtml

Pho3nix

The Legend
Joined
Jul 31, 2009
Messages
32,829
Reaction score
3,033
Location
On the toilet
As the title states, is it possible ? Any code for it. Been googling and can't find a thing, only .html to .xhtml or string to integer.

Any help would be appreciated
 
Your question is incomplete.

xhtml basically is just html with stricter tag checkings. HTML is just text with some tags. So to convert a string to xhtml is basically as simple as ...

"<xml><value>" + your_string_value + "</value></xml>"

and voila, your string is now xhtml ...

Strictly speaking you would be adding more tags, ensuring that it's actually valid html, etc, etc, but without understanding what you are trying to do, most I can help with.

Question is: What are you going to use the xhtml for? xhtml is very commonly found as server side script and is usually processed by some type of application server, be that JSF/JSP/PHP, ...
 
im not sure, but why would you want to do this?
 
Coding some InfoPath forms and it seems some fields are RichText Boxes of data type .xhtml and need to convert it to a string for use in a adjoining table that data will be exported to..Alota fields and wondered if there was an easier way to do this instead of removing all the fields and replacing them with text boxes.

EDIT : Oops :o meant how would you convert a .xhtml to a string.
 
Last edited:
So you want to convert a string to a string?
 
Coding some InfoPath forms and it seems some fields are RichText Boxes of data type .xhtml and need to convert it to a string for use in a adjoining table that data will be exported to..Alota fields and wondered if there was an easier way to do this instead of removing all the fields and replacing them with text boxes.

EDIT : Oops :o meant how would you convert a .xhtml to a string.

Shouldn't you be using XmlDocument ? Not sure what you are trying to achieve here...
 
I think he wants to strip out all HTML formatting from the text and have clean paragraph-like text to insert into the database.
 
I think he wants to strip out all HTML formatting from the text and have clean paragraph-like text to insert into the database.

Ahh

Code:
public class HtmlRemoval
    {
        public static string StripTagsRegex(string source)
        {
            return Regex.Replace(source, "<.*?>", string.Empty);
        }

        static Regex _htmlRegex = new Regex("<.*?>", RegexOptions.Compiled);

        public static string StripTagsRegexCompiled(string source)
        {
            return _htmlRegex.Replace(source, string.Empty);
        }

        public static string StripTagsCharArray(string source)
        {
            char[] array = new char[source.Length];
            int arrayIndex = 0;
            bool inside = false;

            for (int i = 0; i < source.Length; i++)
            {
                char let = source[i];
                if (let == '<')
                {
                    inside = true;
                    continue;
                }
                if (let == '>')
                {
                    inside = false;
                    continue;
                }
                if (!inside)
                {
                    array[arrayIndex] = let;
                    arrayIndex++;
                }
            }
            return new string(array, 0, arrayIndex);
        }
    
    }
 
Not 100% that's the question.

I suspect that he is trying to extract the value of the text box. The text box is a component in the .xhtml file. If this is true, then you will need to get hold of an instance of that text box object and dereference the value in it, i.e. something like mystring = textbox.getText();

or something in that line.

RichText Boxes of data type .xhtm

Is probably an incorrect statement. RichText Boxes is of datatype 'Component' or something. It is stored in source form in a file with extension .xhtml. You need to process that .xhtml file and programmatically access your instance.
 
Top
Sign up to the MyBroadband newsletter
X