This project has moved and is read-only. For the latest updates, please go here.

CreateNode does not support all tags?

Topics: Developer Forum
Mar 14, 2013 at 4:45 PM
I'm building up a complete HTML using C#, using ReplaceChild together with CreateNode. Most works pretty smooth, except for the following:
        switch (node.Attributes["attribute"].Value.ToLower())
            case "table":
                strTest = "<table><tr><td>hello</td><td>world</td></tr></table>";
            case "bold":
                strTest = "Normal, <b>this is bold</b> and back to normal";
            case "italic":
                strTest = "Normal, <i>this is italic</i> and back to normal";
        node.ParentNode.ReplaceChild(HtmlNode.CreateNode(strTest), node);
The table output is rendered correctly. If I add classes, styling can be done neatly in CSS.
However, when outputting the strings as can be seen in the bold and italic cases, output stops when the <b> or <i> tags are encountered. They simply do not exist in the resulting output.

What can be the problem? All tags are properly closed, and the output is part of a larger document and all other tags are handled correctly.
Mar 14, 2013 at 10:06 PM
Sorry, I don't have an answer to why you're having problems, but I have a suggestion. You could try replacing <b> with <strong> and <i> with <em>. I know they are not identical in their purpose but I believe all browsers render them the same way.

Good luck!
Mar 18, 2013 at 10:28 AM
Tried that already, doesn't make any difference.

The bizarre part is this: if I start with a bold section, followed by a 'regular' section, only the bold section is displayed. If I use italic IN that bold section, the italics render fine...
Apr 21, 2013 at 9:59 PM
Edited Apr 21, 2013 at 9:59 PM
I'm having this issue too. And I was just about to create an issue in the tracker.
Then I realized, a node can only be one thing - ie. it isn't a list of nodes.

For example, this:
"Normal, <i>this is italic</i> and back to normal"

Is three nodes. A #text, a <i> and a #text again. CreateNode can only return one node, hence the first #text.
Doing this:
"<text>Normal, <i>this is italic</i> and back to normal</text>"

Will give you one node, <text>, with three child nodes: #text, <i> and #text.

Just my 0.02$