Maintaining standalone > and < symbols to load in XML when the contents also have HTML tags
We have an editor where users can have HTML formatting. We need to have those standalone < and >开发者_JAVA百科 symbols in the XML when we load the content. I can replace < and > with their character entity references as described here but that would also include those characters in the HTML tags. Could anyone provide any direction on the same? I am using C# as the language.
It would be convenient if your editor handled escaping entity references for you. In the ASP.NET world, I use the TinyMCE editor, which handles escaping entity references nicely, and you'll find plenty of other editors that will do the same whether you are dealing with web forms or some other .NET technology.
As for HTML storage in XML, I find it easier to stuff the HTML content in a CDATA section, just to avoid the hassles of encoding/decoding content.
You need to use a CDATA area.
<XMLtag><![CDATA[<html>in here <img src="unclosed tag"> </html>]]</XMLtag>
That's < ! [ CDATA [ stuff you don't want parsed ] ]
UPDATE:
If your HTML is proper XML (all tags closed, etc) then don't worry about it, just include it in the XML doc.
If it isn't proper XML, then you can't iterator through the nodes as you go through the XML -- you will need to extract the HTML as a long text block (see above), load it into a HTML aware parser, and then iterator through that. The HTMLAgility Pack can handle iterating through impure Html.
精彩评论