c# - How do I serialize/deserialize an HTML table in .NET -
c# - How do I serialize/deserialize an HTML table in .NET -
i trying write class serialize/deserialize simple as:
<table border="1"> <tr> <td>row 1, cell 1</td> <td>row 1, cell 2</td> </tr> <tr> <td>row 2, cell 1</td> <td>row 2, cell 2</td> </tr> </table>
i have gotten point of (see below) can't generate table xml correctly:
imports system.xml.serialization <xmlroot("table")> public class htmltable <xmlarray("")> <xmlarrayitem(gettype(htmltablerow), elementname:="tr")> public property rows new list(of htmltablerow) <xmltype("tr")> public class htmltablerow <xmlarray("td")> public property cells new list(of htmltablecell) end class <xmltype("td")> public class htmltablecell <xmltext()> public property value string end class end class
with test like:
<test()> public sub serializetest() dim tbl new htmltable dim row new htmltable.htmltablerow dim cell new htmltable.htmltablecell row.cells.add(cell) tbl.rows.add(row) debug.print(xmlprocessor.serialize(tbl)) end sub
i can't serialize thing. tried generate class using xsd produced lot of garbage code , maintain hand easier monstrosity xsd produced didn't work anyway. doing wrong above?
try changing:
<xmlarray("")> <xmlarrayitem(gettype(htmltablerow), elementname:="tr")> public property rows new list(of htmltablerow)
into:
<xmlelement("tr")> public property rows new list(of htmltablerow)
, , change:
<xmlarray("td")> public property cells new list(of htmltablecell)
into:
<xmlelement("td")> public property cells new list(of htmltablecell)
that how set attributes when using xmlserializer
same task.
i move htmltablerow
, htmltablecell
classes out of htmltable
class.
on note, test method isn't test method, since doesn't assert
, doesn't throw exception when result doesn't meet requirements!
c# .net vb.net
Comments
Post a Comment