Search code examples
c#html-tablexmlwriter

designing a table inside xmlwriter


I am trying to get the output of this:

<thead>
    <tr><th>Condition</th><th>Effective Dates</th><th>Condition Status</th></tr>
</thead>

but I am getting this:

<thead>
   <tr>
      <th>DX Code</th>
      <th>Date</th>
      <th>Code Type</th>
    </tr>
</thead>

I cannot seem to get the elements to show on a single line. my code for this is:

  doc.WriteStartElement("thead");
  doc.WriteStartElement("tr");
  doc.WriteStartElement("th");
  doc.WriteString("DX Code");
  doc.WriteEndElement();
  doc.WriteStartElement("th");
  doc.WriteString("Date");
  doc.WriteEndElement();
  doc.WriteStartElement("th");
  doc.WriteString("Code Type");
  doc.WriteEndElement();
  doc.WriteEndElement();
  doc.WriteEndElement();

Is there a way of getting the formatting like the first example? I tried using WriteString, but it replaced all the "<" and ">" with the XML '&lt' and '&gt'


Solution

  • ok, got it to work by calling doc.WriteWhiteSpace(""); after the ("tr") Element. which pauses the indent/newline until the ("tr") element is ended.