如何使用 KQL extractjson 函数引用以 @ 符号开头的 XML 属性?

How do I reference an XML attribute which begins with an @ symbol using KQL extractjson function?

我正在尝试访问 Azure KQL 中的 XML 元素属性,并已使用 parse_xml 将其转换为 JSON。但是 extractjson 函数似乎不喜欢使用 @ 符号。请参阅下面的代码片段。

let input_xml="<NetAmount currency=\"USD\">150.00</NetAmount>";
let sJson=tostring(parse_xml(input_xml));
let amount=extractjson("$.NetAmount.#text", sJson);
let sCurrency=extractjson($.NetAmount.@currency, sJson);
print input_xml, amount,  sJson //, sCurrency;

如果您 运行 上面的代码将起作用。但是,如果您在 print 语句中对 sCurrency 的引用进行评论,它会显示错误:

运行您的查询有问题。请稍后再试

知道如何在 extractjson 函数中引用货币属性吗?

您不需要使用 extract_json(),您可以简单地使用动态对象访问器:https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/scalar-data-types/dynamic#dynamic-object-accessors

print input_xml = "<NetAmount currency=\"USD\">150.00</NetAmount>"
| project sJson = parse_xml(input_xml)
| project amount = sJson.NetAmount['#text'], currency = sJson.NetAmount['@currency']
amount currency
150.00 USD