Home > Software engineering >  How in Logic Apps can I retrieve a value from a node
How in Logic Apps can I retrieve a value from a node

Time:10-21

<?xml version="1.0" encoding="UTF-8"?>
<?Label XML|NOTETYPE|12345|SUCCESS?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

I would like to retrieve the LABEL node and return the 2 value of NOTETYPE.

In C# I could do this with the following.

var label = doc.FirstChild.NextSibling.InnerText.Split("|")[1] 

CodePudding user response:

I have to admit, I don't understand the <?Value> tag in anyway but if that's what you're after then I don't think you can use the inbuilt XPath functionality.

I tried using XPath in a test tool and wasn't able to select the node.

You may have to use string manipulation, the example shows you how so load that into your tenant to see my answer in full ...

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Initialize_Note_Type": {
                "inputs": {
                    "variables": [
                        {
                            "name": "Note Type",
                            "type": "string",
                            "value": "@{split(variables('Value'), '|')[1]}"
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_Values": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Initialize_Values": {
                "inputs": {
                    "variables": [
                        {
                            "name": "Value",
                            "type": "string",
                            "value": "@{split(split(variables('XML'), '<?Label ')[1], '?>')[0]}"
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_XML": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Initialize_XML": {
                "inputs": {
                    "variables": [
                        {
                            "name": "XML",
                            "type": "string",
                            "value": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?Label XML|NOTETYPE|12345|SUCCESS?>\n<note>\n<to>Tove</to>\n<from>Jani</from>\n<heading>Reminder</heading>\n<body>Don't forget me this weekend!</body>\n</note>"
                        }
                    ]
                },
                "runAfter": {},
                "type": "InitializeVariable"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "manual": {
                "inputs": {
                    "method": "GET",
                    "schema": {}
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "parameters": {}
}

This is the flow ...

Flow

The basic concept is, after I initialize a variable of type string with your XML, I break it out into two step ...

  1. Split the string to find the <?Label> tag using expression ...

    split(split(variables('XML'), '<?Label ')[1], '?>')[0]
    
  2. Then break up the internal tag text to find the NOTETYPE value.

    split(variables('Value'), '|')[1]
    

Happy to be proven wrong but I think that's your best bet.

Result

Result

  • Related