Is it possible to populate xsi:schemaLocation tag within template?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Is it possible to populate xsi:schemaLocation tag within template?

lucasmsanchez
I have some code that defines a Thymeleaf template in the following manner..

<?xml version="1.0" encoding="UTF-8"?>
<td:PendingData xmlns:td="https:/www.secret-site.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="@{${xmlValues['SchemaUrl']}}">
    <dataElement>
    ...
    </dataElement>
</td:PendingData>


I am able to reference ${xmlValues['SchemaUrl']} within the dataElements, however when I try to populate that value into the xsi:schemaLocation tag, the template will always write the literal Spring EL expression instead of pulling the correct value.

What is the correct syntax for referencing a context variable value within the xsi:schemaLocation tag?

Thank you for your time.
-L
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to populate xsi:schemaLocation tag within template?

Metroids
Either of these worked for my in thymeleaf 3.0:

th:xsi:schemaLocation="@{${xmlValues['SchemaUrl']}}"
th:attr="'xsi:schemaLocation'=@{${xmlValues['SchemaUrl']}}"

If you want thymeleaf to parse an expression, you have to prefix it with th: (or else use th:attr).