Read StructuredDocumentTag and extract table present in it

Hi Team,

I’m working on StructuredDocumentTag where I have a tag containing Table. I need to read row by row and have to add to an object. Are there any ways that can be done?

Below is the code snippet and sample document I have used:

foreach (StructuredDocumentTag tagname in doc.GetChildNodes(NodeType.StructuredDocumentTag, true))
{
    if (tagname.Title == "CPT:ObjectiveEndpointCustom[1]")
    {
        //here I need to read the table
    }
}

sampleDOC.docx (23.5 KB)

@kkumaranil485 You can use CompositeNode.GetChild or CompositeNode.GetChildNodes method to get tables from SDT. For example see the following code:

Document doc = new Document(@"C:\Temp\in.docx");

foreach (StructuredDocumentTag tagname in doc.GetChildNodes(NodeType.StructuredDocumentTag, true))
{
    if (tagname.Title == "CPT:ObjectiveEndpointCustom[1]")
    {
        // Get the first table in the SDT and putput it's content.
        Table table = (Table)tagname.GetChild(NodeType.Table, 0, true);
        if (table != null)
        {
            Console.WriteLine("----------------------------------");
            foreach (Row r in table.Rows)
            {
                Console.Write("|");
                foreach (Cell c in r.Cells)
                {
                    Console.Write(" {0} |", c.ToString(SaveFormat.Text).Trim());
                }
                            
                Console.WriteLine("\r\n----------------------------------");
            }
        }
    }
}