remove xml prefixs and parse xml using groovy xml parser and read values;

 

<?xml version="1.0"?>

<feed xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xml:base="https://my302303-api.s4hana.ondemand.com/sap/opu/odata/sap/API_MKT_CAMPAIGN_SRV/">

    <id>https://myxxxxx-api.s4hana.ondemand.com/sap/opu/odata/sap/API_MKT_CAMPAIGN_SRV/Campaigns(guid%27fa163e88-95f5-1eea-83a9-755f929c5e8c%27)/CampaignAssignedTargetGroups</id>

    <title type="text">AssignedTargetGroups</title>

    <updated>2019-12-05T20:02:45Z</updated>

    <author>

        <name/>

    </author>

    <link href="Campaigns(guid%27fa163e88-95f5-1eea-83a9-755f929c5e8c%27)/CampaignAssignedTargetGroups" rel="self" title="AssignedTargetGroups"/>

    <entry>

        <id>https://myxxxx-api.s4hana.ondemand.com/sap/opu/odata/sap/API_MKT_CAMPAIGN_SRV/AssignedTargetGroups(TargetGroupUUID=guid’fa163e88-95f5-1eea-83a9-6fb993561e87′,CampaignUUID=guid’fa163e88-95f5-1eea-83a9-755f929c5e8c’)</id>

        <title type="text">AssignedTargetGroups(TargetGroupUUID=guid’fa163e88-95f5-1eea-83a9-6fb993561e87′,CampaignUUID=guid’fa163e88-95f5-1eea-83a9-755f929c5e8c’)</title>

        <updated>2019-12-05T20:02:45Z</updated>

        <category term="API_MKT_CAMPAIGN_SRV.AssignedTargetGroupEntityType" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>

        <link href="AssignedTargetGroups(TargetGroupUUID=guid’fa163e88-95f5-1eea-83a9-6fb993561e87′,CampaignUUID=guid’fa163e88-95f5-1eea-83a9-755f929c5e8c’)" rel="self" title="AssignedTargetGroupEntityType"/>

        <content type="application/xml">

            <m:properties xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">

                <d:TargetGroup>134</d:TargetGroup>

                <d:TargetGroupUUID>fa163e88-95f5-1eea-83a9-6fb993561e87</d:TargetGroupUUID>

                <d:CampaignUUID>fa163e88-95f5-1eea-83a9-755f929c5e8c</d:CampaignUUID>

            </m:properties>

        </content>

    </entry>

</feed>

-------------

<?xml version="1.0"?>

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output indent="yes" method="xml" encoding="utf-8" 

    omit-xml-declaration="yes"/>

    <!-- Stylesheet to remove all namespaces from a document -->

    <!-- NOTE: this will lead to attribute name clash, if an element contains

       two attributes with same local name but different namespace prefix -->

    <!-- Nodes that cannot have a namespace are copied as such -->

    <!-- template to copy elements -->

    <xsl:template match="*">

        <xsl:element name="{local-name()}">

            <xsl:apply-templates select="@* | node()"/>

        </xsl:element>

    </xsl:template>

    <!-- template to copy attributes -->

    <xsl:template match="@*">

        <xsl:attribute name="{local-name()}">

            <xsl:value-of select="."/>

        </xsl:attribute>

    </xsl:template>

    <!-- template to copy the rest of the nodes -->

    <xsl:template match="comment() | text() | processing-instruction()">

        <xsl:copy/>

    </xsl:template>

</xsl:stylesheet>

----------

<feed base="https://my302303-api.s4hana.ondemand.com/sap/opu/odata/sap/API_MKT_CAMPAIGN_SRV/">

   <id>https://myxxxxx-api.s4hana.ondemand.com/sap/opu/odata/sap/API_MKT_CAMPAIGN_SRV/Campaigns(guid%27fa163e88-95f5-1eea-83a9-755f929c5e8c%27)/CampaignAssignedTargetGroups</id>

   <title type="text">AssignedTargetGroups</title>

   <updated>2019-12-05T20:02:45Z</updated>

   <author>

      <name/>

   </author>

   <link href="Campaigns(guid%27fa163e88-95f5-1eea-83a9-755f929c5e8c%27)/CampaignAssignedTargetGroups"

         rel="self"

         title="AssignedTargetGroups"/>

   <entry>

      <id>https://myxxxx-api.s4hana.ondemand.com/sap/opu/odata/sap/API_MKT_CAMPAIGN_SRV/AssignedTargetGroups(TargetGroupUUID=guid’fa163e88-95f5-1eea-83a9-6fb993561e87′,CampaignUUID=guid’fa163e88-95f5-1eea-83a9-755f929c5e8c’)</id>

      <title type="text">AssignedTargetGroups(TargetGroupUUID=guid’fa163e88-95f5-1eea-83a9-6fb993561e87′,CampaignUUID=guid’fa163e88-95f5-1eea-83a9-755f929c5e8c’)</title>

      <updated>2019-12-05T20:02:45Z</updated>

      <category term="API_MKT_CAMPAIGN_SRV.AssignedTargetGroupEntityType"

                scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>

      <link href="AssignedTargetGroups(TargetGroupUUID=guid’fa163e88-95f5-1eea-83a9-6fb993561e87′,CampaignUUID=guid’fa163e88-95f5-1eea-83a9-755f929c5e8c’)"

            rel="self"

            title="AssignedTargetGroupEntityType"/>

      <content type="application/xml">

         <properties>

            <TargetGroup>134</TargetGroup>

            <TargetGroupUUID>fa163e88-95f5-1eea-83a9-6fb993561e87</TargetGroupUUID>

            <CampaignUUID>fa163e88-95f5-1eea-83a9-755f929c5e8c</CampaignUUID>

         </properties>

      </content>

   </entry>

</feed>

-------------
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import java.text.SimpleDateFormat;
 
def Message processData(Message message) {
   
    def map = message.getProperties();
    def body = message.getBody(String.class);
    def parseXML = new XmlParser().parseText(body);
 
 def TargetGroup = "${parseXML.entry.content.properties.TargetGroup.text()}";
 def TargetGroupUUID = "${parseXML.entry.content.properties.TargetGroupUUID.text()}";
 
    message.setProperty("TargetGroup", TargetGroup);
    message.setProperty("TargetGroupUUID", TargetGroupUUID);
   
    return message;
 
}
-------------------------


Popular posts from this blog

pss book : శ్రీకృష్ణుడు దేవుడా, భగవంతుడా completed , second review needed. 26th April 2024

pss book: గురు ప్రార్థనామంజరి . completed 21st july 2024

pss book: కధల జ్ఞానము read review pending. 25th june 2024