如何访问作为芭蕾舞演员关键字的 xml 元素的属性?

问题描述 投票:0回答:1

考虑下面用 ballerina 编写的代码段。

xml xmlHello = xml <para id="greeting">Hello</para>;
string id = check xmlHello.id;
io:println(id);

在上面的场景中,输出将是问候语。

现在考虑以下内容。

xml xmlHello = xml <para type="singlePara">Hello</para>;
string paraType = check xmlHello.type;
io:println(paraType);

这给出了一个无效的令牌错误,因为类型是 Ballerina 中的关键字。在这种情况下如何访问类型属性?

xml xml-parsing attributes keyword ballerina
1个回答
1
投票

关键字可以用单引号转义

string paraType = check xmlHello.'type;
© www.soinside.com 2019 - 2024. All rights reserved.