How to set an XML comment either as segment separator or inline element

Hi there,

let's assume that I've got this XML text:

<test>
<text>This is<!-- comment in segment--> test text.</text>
</test>

How can set in the XML2 parser, if the XML comment works as a segment separator (like a structure element) or as an inline tag? Can this be set via an XPATH definition?

Thank in advance!

Best regards,

Bodo

emoji
Parents
  • "Probability score": 0.8

    "Question improvement suggestion": Please provide the version of Trados Studio you are using and any error messages you may have encountered. Also, it would be helpful to know if you have tried any troubleshooting steps already.

    In the meantime, based on the information you have provided, here is a suggested answer to your question:

    Hello Bodo,

    To set an XML comment as a segment separator or inline element in Trados Studio, you can follow these steps:

    Step 1: Open Trados Studio and go to the "File Types" settings.

    Step 2: Select the XML file type you are working with.

    Step 3: Go to the "Parser Rules" section.

    Step 4: Here, you can define how Trados Studio should handle XML comments. If you want the XML comment to act as a segment separator, you can add it as a "Structure" element. If you want it to be an inline tag, you can add it as an "Inline" element.

    Step 5: To add a new rule, click on the "New" button and enter the XPath expression for the XML comment. The XPath for an XML comment is typically "//comment()".

    Please note that the exact steps may vary depending on the version of Trados Studio you are using.

    I hope this answer addressed your question. If not, please reject the answer, add the question improvement suggestion information, and click the RWS Community AI checkbox on the right to try again.

    RWS Community AI

    emoji
  • I've tried to use //comment(), comment() and /test/text/comment() as XPATH, this doesn't work.

    emoji
  •  

    Do you want to do this to be able to translate it or just manage it in some way?  I ask because comments in XML are not normally intended for translation as they are intended to be processing instructions.  They're usually meant for developers, translators, or systems as notes, explanations, or debugging hints.  The XML specification also clarifies this point stating the following:

    "An XML processor MAY, but need not, make it possible for an application to retrieve the text of comments."

    Trados Studio has taken the approach not to extract the comments for translation.  So if you want to extract for translation you'd have to do some pre-processing and content the comment markup into proper tags so you can expose the content for translation, then post process to remove them and add the comment markup back again.

    If you just want to be able to see them you can hover over the comments as they are "tagged" as a placeholder automatically by the XML filetype:

    Or... you could even use a stylesheet to show them in the preview:

    Screenshot of Trados Studio interface displaying a translation grid on the left and an XML preview on the right. The XML comment is visible as 'Comment: comment in segment' in the preview.

    Here's a couple of files to test in case it's helpful: xml_xsl.zip

    Paul Filkin | RWS Group

    ________________________
    Design your own training!

    You've done the courses and still need to go a little further, or still not clear? 
    Tell us what you need in our Community Solutions Hub

    emoji


    Generated Image Alt-Text
    [edited by: RWS Community AI at 8:00 PM (GMT 1) on 2 May 2025]
  • Hi Paul,

    thank you for your answer. Maybe I should explain my problem detailledly: I've got a Docufy Cosima XML file (based on XML2 settings) where the CMS puts comments in the middle of segments. However Trados Studio 2024 breaks this segment up into two segments while it's only one if the comment gets removed first.

    So my question was how to understand better, how XML comments work in Trados. I don't need to translate the comment contents, no.

    I've created test xml filetype definitions and in my test the comment appears as an inline tag, like in your example. The question is, in this Cosima filetype, why does it separate the segment and how can I convert the comment into an inline tag?

    If needed, I can prepare sample data.

    Best regards,

    Bodo

    emoji
  •  

    Good idea... and a sample of the offending elements is essential as this is clearly going to be the cause of your problem.

    Paul Filkin | RWS Group

    ________________________
    Design your own training!

    You've done the courses and still need to go a little further, or still not clear? 
    Tell us what you need in our Community Solutions Hub

    emoji
  •  

    I've prepared a sample package. I initially thought it was a systematic problem but it looks more like an error of Studio's tag handling to me...

    In XML:

    Screenshot showing XML code with a comment 'HYPO-5536' that removes the leading tag 'y.textvar.name=Geraetebezeichnung'.

    Present XML comment removes leading tag:

    Screenshot showing text in a Trados Studio editor where the XML comment causes the leading tag to be missing.

    After removing the XML comment, the leading tag is present:

    Screenshot showing corrected text in Trados Studio editor with the leading tag 'y.textvar' now visible.

    I attach the XMLs and package...

    Out.zip

    Best regards,

    Bodo

    emoji


    Generated Image Alt-Text
    [edited by: RWS Community AI at 12:49 PM (GMT 1) on 7 May 2025]
Reply Children