Failed uploading old resource

I am getting the following error :

You have one or more unescaped characters from the following list: ', ", @, ?, \n, \t in the string: '\n        <html>\n            <body>\n                <h1>How to access shared Windows folder on Android (SMB)</h1>\\n\\n\n                <ul>\n                    <li>\n                        <b>Enable File Sharing on Windows</b>\\n\n                    </li>\n                    <p style=\'margin-left: 40px\'>\n                        Open the Control Panel, click Choose HomeGroup and Sharing options under Network\n                        and Internet, and click "Change Advanced Sharing Settings," enable the "File and\n                        Printer Sharing" feature.\\n\\n\n                    </p>\n\n                    <li>\n                        <b>Additional File Sharing settings</b>\\n\n                    </li>\n                    <p style=\'margin-left: 40px\'>\n                        You may also want to configure the other advanced sharing settings here. \\n\n                        For example, you could enable access to your files without a password if you trust all\n                        the devices on your local network. Once file and printer sharing is enabled, you can\n                        open File Explorer or Windows Explorer, right-click a folder you want to share, and\n                        select Properties. \\n\n                        Click the Share button and make the folder available on the network.\\n\\n\n                        </p>\n\n                    <li>\n                        <b>Make sure both devices are on same Wifi</b>\\n\n                    </li>\n                    <p style=\'margin-left: 40px\'>\n                        This feature makes files available on the local network, so your PC and mobile devices\n                        have to be on the same local network. You can\\’t access a shared Windows folder\n                        over the Internet or when your smartphone is connected to its mobile data — it\n                        has to be connected to Wi-Fi.\\n\\n\n                    </p>\n\n                    <li>\n                        <b>Find IP Address</b>\\n\n                    </li>\n                    <p style=\'margin-left: 40px\'>\n                        Open Command Prompt. Type \\\'ipconfig\\\' and press Enter. Look for Default Gateway\n                        under your network adapter for your router\\\'s IP address. Look for\n                        \\\\\\"IPv4 Address\\\\\\" under the same adapter section to find your computer\\\'s IP\n                        address.\\n\\n\n                    </p>\n\n                    <b>Enter details in SMB dialog box</b>\\n\n                </ul>\n            </body>\n        </html>\n    '

For an old (since 2017) string:


    <string name="smb_instructions">
        <html>
            <body>
                <h1>How to access shared Windows folder on Android (SMB)</h1>\n\n
                <ul>
                    <li>
                        <b>Enable File Sharing on Windows</b>\n
                    </li>
                    <p style='margin-left: 40px'>
                        Open the Control Panel, click Choose HomeGroup and Sharing options under Network
                        and Internet, and click "Change Advanced Sharing Settings," enable the "File and
                        Printer Sharing" feature.\n\n
                    </p>

                    <li>
                        <b>Additional File Sharing settings</b>\n
                    </li>
                    <p style='margin-left: 40px'>
                        You may also want to configure the other advanced sharing settings here. \n
                        For example, you could enable access to your files without a password if you trust all
                        the devices on your local network. Once file and printer sharing is enabled, you can
                        open File Explorer or Windows Explorer, right-click a folder you want to share, and
                        select Properties. \n
                        Click the Share button and make the folder available on the network.\n\n
                        </p>

                    <li>
                        <b>Make sure both devices are on same Wifi</b>\n
                    </li>
                    <p style='margin-left: 40px'>
                        This feature makes files available on the local network, so your PC and mobile devices
                        have to be on the same local network. You can\’t access a shared Windows folder
                        over the Internet or when your smartphone is connected to its mobile data — it
                        has to be connected to Wi-Fi.\n\n
                    </p>

                    <li>
                        <b>Find IP Address</b>\n
                    </li>
                    <p style='margin-left: 40px'>
                        Open Command Prompt. Type \'ipconfig\' and press Enter. Look for Default Gateway
                        under your network adapter for your router\'s IP address. Look for
                        \\\"IPv4 Address\\\" under the same adapter section to find your computer\'s IP
                        address.\n\n
                    </p>

                    <b>Enter details in SMB dialog box</b>\n
                </ul>
            </body>
        </html>
    </string>

It seems that there is either a bug, or the site changed the parser on the resource and it broke. How should I fix this?

Hello there,​

I am Antonis from the Transifex Customer Success team. I hope you’re well!​

This looks like an Android XML file but correct me if I’m wrong.

Our Android XML parser received an update on January 2024 (announcement) and has since become the default parser.

Old resources that were created before the introduction of the new parser will still use the old version (v2) but anything created after January 2024 when the v3 parser became the default will use the new version and the file contents must conform to the new standard.

You can find information about the expected escaping behavior in our Help Center article.

Please let me know if you have any questions or need further assistance, and I will be happy to help!

​Kind regards,

Antonis

The error message wasn’t very clear on the illegal characters, as it seems to add a lot of “\n” in its message. I don’t think we can escape the HTML as it is used as is in the application to generate an HTML view. We are currently trying to use a tag for this, which seemed to work for other strings.

From the docs you linked “These characters will only be accepted unescaped if they are part of an inline tag.”, my first idea was to do an inline tag (in-lining the whole section) but that hack would be unmaintainable, do you provide other solutions for this use case (HTML in the string)?

Hi @EmmanuelMess,

I understand that this process as you outlined could be unmaintainable.

While I’m not an Android development expert myself, I did some research into the official Android documentation and developer community best practices to better understand the issues you’re encountering.

Based on what I found, your current approach goes against several Android XML formatting rules. The official Android Developer documentation is quite specific about this.

Key issues with your current file

  1. Unescaped Characters: According to Android’s string resource documentation, you must properly escape certain characters in XML:

    • Single quotes in style='margin-left: 40px' need to be escaped as &apos; or use double quotes
    • The backslashes in \\\"IPv4 Address\\\" should be \"IPv4 Address\"
    • Special characters like & require XML entity escaping
  2. CSS Styles Won’t Work: The Android documentation states that TextView has very limited HTML support and doesn’t support CSS styles at all. Properties like margin-left: 40px will be ignored when displayed in a TextView.

Recommendations based on official Android documentation

The Android Developer guides suggest a few approaches for complex HTML content:

Option 1: Use CDATA

<string name="smb_instructions">
<![CDATA[
<h1>How to access shared Windows folder on Android (SMB)</h1>
<ul>
<li><b>Enable File Sharing on Windows</b><br/>
Open the Control Panel, click Choose HomeGroup and Sharing options...</li>
<li><b>Additional File Sharing settings</b><br/>
You may also want to configure the other advanced sharing settings...</li>
<li><b>Make sure both devices are on same Wifi</b><br/>
This feature makes files available on the local network...</li>
<li><b>Find IP Address</b><br/>
Open Command Prompt. Type 'ipconfig' and press Enter...</li>
<li><b>Enter details in SMB dialog box</b></li>
</ul>
]]>
</string>

Option 2: Use proper XML entity escaping

<string name="smb_instructions">
&lt;h1&gt;How to access shared Windows folder on Android (SMB)&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Enable File Sharing on Windows&lt;/b&gt;&lt;br/&gt;
Open the Control Panel...
&lt;/li&gt;
&lt;/ul&gt;
</string>

Option 3: Separate HTML and store it in your asset folder

Store your HTML content as a separate file in the assets folder and load it programmatically.

According to the Android documentation and developer community:

  • Using raw HTML with CSS in string resources can cause parsing errors
  • It makes localization much more difficult
  • It violates Android’s separation of content and presentation
  • The CSS styles won’t actually render in TextViews anyway

I’d suggest going with Option 1 (CDATA) as it’s the cleanest approach that follows Android best practices while still allowing you to use basic HTML formatting that TextView can actually render.

The CDATA approach will solve your parsing errors and is explicitly recommended in Android’s official documentation for complex HTML content in string resources.

I hope this helps! Let me know if you need any clarification on these approaches.

1 Like