is there something like a HtmlNode.Parse(string) method?

Topics: Developer Forum, User Forum
Mar 25, 2011 at 12:23 AM

Hi,

I'm attempting to do something like:

table.AppendChild(HtmlNode.Parse("<tr id=\"purchase{0}\">  <td>{1}</td>  <td>{2:C}</td>  <td>{3}</td>  <td>{4}</td>  <td>{5:C}</td></tr>"));

How would I convert the string above into a node that I can append to a table?

Mar 25, 2011 at 1:03 AM

Googling around I ended up coming up with this:

table.AppendChild(row = doc.CreateElement("tr"));
row.InnerHtml = string.Format(purchaseRowHtml,
                            purchase.Product.Name, 
                            purchase.CostEach, 
                            purchase.Quantity, 
                            purchase.Discount, 
                            purchase.LineCost()); 

Still it might be handy for a Parse() method.

Mar 31, 2011 at 9:43 PM

I think the following is what you are looking for.

HtmlNode node = HtmlNode.CreateNode("<div>some new node</div>");