如果您在解析之后将 XML 转换为 JSON 对象,那么它会简单得多。这两者都可以通过使用xml 和json 函数来完成。
此外,由于您知道 XML 的格式,因此您将知道转换后的 JSON 的格式,并让您使用 Parse JSON 操作来获取简单的令牌以在逻辑应用的其余部分中使用。
然后您可以直接在 SQL 查询中使用这些标记。
这是一个逻辑应用程序,展示了这种情况(没有 SQL 和 HTTP 步骤)
及其定义要明确
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"CSV_Data": {
"inputs": {
"variables": [
{
"name": "random_data_csv",
"type": "String",
"value": "@{body('Parse_JSON')?['data']?['name']},@{body('Parse_JSON')?['data']?['awesome']}"
}
]
},
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Parse_JSON": {
"inputs": {
"content": "@json(xml(variables('random_data_xml')))",
"schema": {
"properties": {
"data": {
"properties": {
"awesome": {
"type": "string"
},
"name": {
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
}
},
"runAfter": {
"XML_Data": [
"Succeeded"
]
},
"type": "ParseJson"
},
"XML_Data": {
"inputs": {
"variables": [
{
"name": "random_data_xml",
"type": "String",
"value": "<data>\n<name>Azure Logic Apps</name>\n<awesome>true</awesome>\n</data>"
}
]
},
"runAfter": {},
"type": "InitializeVariable"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
}
}