How to fill the document structure view within a filter

Can someone please point me to right chapter in the File Type Support documentaion, a SDK sample code or a SDL Community projects code, where I can see how to fill the structure information in this view:

Trados Studio Editor view showing a document structure with headings for 'Getting Started', 'Finding a location for your photo printer', 'Connecting and turning on the power', and a 'Table' with three 'Table Row' entries.



Generated Image Alt-Text
[edited by: Trados AI at 1:24 PM (GMT 0) on 5 Mar 2024]
  • Hi Martin,

    the AbstractNativeFileParser class implements a  ProcessLine(string sLine) method.

    In there, you can determine what defines a structure in the file you are parsing. Now beware that to create a "structure" in the tree view has nothing to do with the WriteStructureTag() method but rather with the WriteContext() method.

    So, in your ProcessLine, you simply create a tree node by using

    WriteContext("new section");

    before writing the segment to your resulting sdlxliff with WriteText(...).

    Of course you need to have a WriteContext method in your FileParser class like this, note the CreateStructureInfo section which creates the actual tree node:

    private void WriteContext(string contextContent)
                {
                    var contextProperties = PropertiesFactory.CreateContextProperties();
                    var contextInfo = PropertiesFactory.CreateContextInfo(contextContent);
                    contextInfo.DisplayCode = "EL"; // Element
                    contextInfo.DisplayName = contextContent;
                    contextInfo.ContextType = StandardContextTypes.Element;
                    contextInfo.Description = contextContent;
                    contextInfo.DisplayColor = Color.Beige;
                    contextInfo.Purpose = ContextPurpose.Information;
                    contextProperties.Contexts.Clear();
                    contextProperties.Contexts.Add(contextInfo);
                    var structInfo = PropertiesFactory.CreateStructureInfo(contextInfo, true, nodeStructureInfo);
                    contextProperties.StructureInfo = structInfo;
                    Output.ChangeContext(contextProperties);
                }

    Hope this helps.

    Best,
    Andreas

  • I just remembered you posting about a bilingual parser a couple of days back.
    If this is for a bilingual parser, things are a bit different. I haven't written any BIL parser myself yet, but it looks like you need to do this in the CreateParagraphUnit(XmlNode xmlUnit) method.

    There you need to set the context like this:
    paragraphUnit.Properties.Contexts = CreateContext("Paragraph", id);

    The helper function CreateContext needs to be implemented like this:

    private IContextProperties CreateContext(string spec, string unitID)
    {
        // context info for type information, e.g. heading, paragraph, etc.
        IContextProperties contextProperties = PropertiesFactory.CreateContextProperties();
        IContextInfo contextInfo = PropertiesFactory.CreateContextInfo(StandardContextTypes.Paragraph);
        contextInfo.Purpose = ContextPurpose.Information;

        // add unit id as metadata
        IContextInfo contextId = PropertiesFactory.CreateContextInfo("UnitId");
        contextId.SetMetaData("UnitID", unitID);

        switch (spec)
        {
            case "Heading":
                contextInfo = PropertiesFactory.CreateContextInfo(StandardContextTypes.Topic);
                contextInfo.DisplayColor = Color.Green;
                break;
            case "Box":
                contextInfo = PropertiesFactory.CreateContextInfo(StandardContextTypes.TextBox);
                contextInfo.DisplayColor = Color.Gold;
                break;
            case "Paragraph":
                contextInfo = PropertiesFactory.CreateContextInfo(StandardContextTypes.Paragraph);
                contextInfo.DisplayColor = Color.Silver;
                break;
            default:
                break;
        }

        contextProperties.Contexts.Add(contextInfo);
        contextProperties.Contexts.Add(contextId);

        return contextProperties;
    }

    Hope this helps.

  • The CreateStructureInfo() function was the missing piece and did the trick.

    Very helpful answer. Many Thanks.