You are on the right track. In order to insert an XML fragment, the fragment must be well formed on its own. If no namespace prefix is used, as it is in your working policy, then the XML is well formed and it can be inserted. If a namespace prefix is used but the namespace is not declared, as it is in your not-working policy, then the XML is not well formed. So when you define ${addxml} it MUST include a namespace declaration. Paste the following in to replace your Set Context Variable for ${addxml} to see what I mean. The resulting XML after the insert will have the namespace re-declared in the element, but that's no harm, no foul.
<?xml version="1.0" encoding="UTF-8"?>
<wsp:Policy xmlns:L7p="http://www.layer7tech.com/ws/policy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2002/12/policy">
<wsp:All wsp:Usage="Required">
<L7p:SetVariable>
<L7p:AssertionComment assertionComment="included">
<L7p:Properties mapValue="included">
<L7p:entry>
<L7p:key stringValue="RIGHT.COMMENT"/>
<L7p:value stringValue="Element definieren en vullen met de juiste waarde"/>
</L7p:entry>
</L7p:Properties>
</L7p:AssertionComment>
<L7p:Base64Expression stringValue="PHRuczpPcGVuYmFyZXJ1aW10ZW5hYW0geG1sbnM6dG5zPSJodHRwOi8vd3d3LnZpY3JlYS5ubC9OZXVyb25HZWdldmVuc21hZ2F6aWpuL1NvYXAvUEM2X0JBR05ML0FkcmVzQnlQYzZfYmFnbmwvUGM2X2JhZ25sX1NlcnZpY2UvR2V0UGM2X2JhZ25sX0RhdGFUeXBlcyI+b3V0cHV0PC90bnM6T3BlbmJhcmVydWltdGVuYWFtPg=="/>
<L7p:VariableToSet stringValue="addxml"/>
</L7p:SetVariable>
</wsp:All>
</wsp:Policy>
------------------------------
Jay MacDonald - Adoption Architect - Broadcom API Management (Layer 7)
------------------------------
Original Message:
Sent: 06-05-2020 06:30 AM
From: Adriaan van Loon
Subject: Re: Add/Remove XML element assertion
Hey Jay,
Thanks for the reply. I've created two examples. One that is working and one that isn't working. De message I get is that L7 is complaining that the new element that it needs to add is not a well formed xml fragment. I think it is cause its possible to add namespaces to elements (when they're declared ofcourse). Am I doing something wrong?
Cheers
Original Message:
Sent: 05-20-2020 01:42 PM
From: Jay MacDonald
Subject: Re: Add/Remove XML element assertion
Can you paste the policy you have that is not working here? I don't have any context for your question.
------------------------------
Jay MacDonald - Adoption Architect - Broadcom API Management (Layer 7)
Original Message:
Sent: 05-20-2020 04:59 AM
From: Adriaan van Loon
Subject: Re: Add/Remove XML element assertion
Hey all,
Thanks for the example. Got it working here too. Just wondering though. When i try to add namespaces to the xml element the add remove element assertion complains about not being aable to add the element to the xml because it isn't a valid element to be added.
Wanted to add a new post but can't see how tot start a new thread (maybe because i'm a newbie). Does anyone have an idea about the above question?
Original Message:
Sent: 09-22-2016 06:45 PM
From: Stephen Hughes
Subject: Re: Add/Remove XML element assertion
Brijendra,
The problem is in the add element assertion as it needs to be responseXpath.elements not element. I've attached a policy snippet from a version 9.1 gateway that does do what has been outlined.
Sincerely,
Stephen Hughes
Director, CA Support