xs:string("<")

Sunday, 25 August 2019 · 3 messages
GC
Giuseppe G. A. Celano25 Aug 2019 14:16 #
Hi, I am wondering why xs:string("&") is not possible, but xs:string("<") is (although XML does not allow both ). Is there any reason? Thanks. Best, Giuseppe
MH
Martin Honnen25 Aug 2019 14:26 #
Quoted text · Giuseppe G. A. Celano · 8 lines
Am 25.08.2019 um 14:16 schrieb Giuseppe G. A. Celano: > > > I am wondering why xs:string("&") is not possible, but > xs:string("<") is (although XML does not allow both ). Is there any > reason? Thanks. > >
You are allowed to use some predefined entity references and to use character references in string literals, see https://www.w3.org/TR/xquery-31/#prod-xquery31-StringLiteral which defines [222] StringLiteral ::= ('"' (PredefinedEntityRef | CharRef | EscapeQuot | [^"&])* '"') | ("'" (PredefinedEntityRef | CharRef | EscapeApos | [^'&])* "'") so you can use the ampersand as a meta character for e.g. &lt; and e.g. &#160;, on the other hand, to use it literally, you need some escape mechanism in the form of &amp;. Inside XML the angle brackets are needed for markup but that is not the case inside of a string literal so you can use them freely in there.
GC
Giuseppe G. A. Celano25 Aug 2019 14:30 #
Thanks!
Quoted text · Martin Honnen · 15 lines
> On Aug 25, 2019, at 2:26 PM, Martin Honnen <martin.honnen at gmx.de> wrote: > > Am 25.08.2019 um 14:16 schrieb Giuseppe G. A. Celano: >> >> >> I am wondering why xs:string("&") is not possible, but xs:string("<") is (although XML does not allow both ). Is there any reason? Thanks. >> >> > > You are allowed to use some predefined entity references and to use character references in string literals, see https://www.w3.org/TR/xquery-31/#prod-xquery31-StringLiteral <https://www.w3.org/TR/xquery-31/#prod-xquery31-StringLiteral> which defines > [222] StringLiteral ::= ('"' (PredefinedEntityRef | CharRef | EscapeQuot | [^"&])* '"') | ("'" (PredefinedEntityRef | CharRef | EscapeApos | [^'&])* "'") > > so you can use the ampersand as a meta character for e.g. `&lt;` and e.g. `&#160;`, on the other hand, to use it literally, you need some escape mechanism in the form of `&amp;`. > > Inside XML the angle brackets are needed for markup but that is not the case inside of a string literal so you can use them freely in there.

⚡Generated with XQuery