cancel
Showing results for 
Search instead for 
Did you mean: 

Need to delete Root node and convert into Json format

0 Kudos

Hi Experts,

I have a requirement to delete the root node and convert into Json format through XSLT mapping.

I have to remove this tag <ns0:MT_CSV_City_CONTACT>

and need to convert the entire structure into Json format.

Structure:

<?xml version="1.0" encoding="UTF-8" ?> <ns0:MT_CSV_City_CONTACT xmlns:ns0="http://test.com/xi/SAP/city"> <Timestamp>/Date(1516432826000)/</Timestamp> <UserName>S_PI</UserName> <SourceSystemType>EXT</SourceSystemType> <SourceSystemId>CSV_Source</SourceSystemId> <Contacts> <Id>test@email.com</Id> <IdOrigin>ZCITY</IdOrigin> <FirstName>ram</FirstName> <LastName>test</LastName> <LanguageDescription>DE</LanguageDescription> <CountryDescription>India</CountryDescription> <Facets> <Id>test@email.com</Id> <IdOrigin>SITY</IdOrigin> </Facets> <MarketingPermissions> <Id>test@email.com</Id> <IdOrigin>EMAIL</IdOrigin> <OptIn>Y</OptIn> <OutboundCommunicationMedium>EMAIL</OutboundCommunicationMedium> <CommunicationDirection>O</CommunicationDirection> <CommunicationCategoryId>0000000037</CommunicationCategoryId> </MarketingPermissions> <MarketingAttributes> <CategoryDescription>MC</CategoryDescription> <Value>a</Value> </MarketingAttributes> <MarketingAttributes> <CategoryDescription>MC</CategoryDescription> <Value>i</Value> </MarketingAttributes> <MarketingAttributes> <CategoryDescription>MC</CategoryDescription> <Value>k</Value> </MarketingAttributes> <MarketingAttributes> <CategoryDescription>MC</CategoryDescription> <Value>m</Value> </MarketingAttributes> </Contacts> <Contacts> <Id>rr@gmail.com</Id> <IdOrigin>ZSITY</IdOrigin> <FirstName>ram</FirstName> <LastName>surya</LastName> <CountryDescription>DE</CountryDescription> <Facets> <Id>rr@gmail.com</Id> <IdOrigin>ZSITY</IdOrigin> </Facets> <MarketingPermissions> <Id>rr@gmail.com</Id> <IdOrigin>EMAIL</IdOrigin> <OptIn>Y</OptIn> <OutboundCommunicationMedium>EMAIL</OutboundCommunicationMedium> <CommunicationDirection>O</CommunicationDirection> <CommunicationCategoryId>0000000037</CommunicationCategoryId> </MarketingPermissions> <MarketingAttributes> <CategoryDescription>MC</CategoryDescription> <Value>a</Value> </MarketingAttributes> <MarketingAttributes> <CategoryDescription>MC</CategoryDescription> <Value>e</Value> </MarketingAttributes> <MarketingAttributes> <CategoryDescription>MC</CategoryDescription> <Value>k</Value> </MarketingAttributes> </Contacts> </ns0:MT_CSV_City_CONTACT>

Can anybody please help in this.

former_member308595
Participant
0 Kudos

Hi ,

Use below code

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ser-root1="http://test.com/xi/SAP/city"  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
 <xsl:template match="/ser-root1:MT_CSV_City_CONTACT">  <xsl:copy-of select="*" />   </xsl:template></xsl:stylesheet>

peter_wallner2
Active Contributor
0 Kudos

Hello, I don't know if XSL is a good choice to convert XML to JSON. Have a look at this https://stackoverflow.com/questions/28451370/convert-xml-to-json-with-java

Best regards, Peter

Accepted Solutions (1)

Accepted Solutions (1)

former_member308595
Participant
0 Kudos

Hi ,

Use below code

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ser-root1="http://test.com/xi/SAP/city"  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
 <xsl:template match="/ser-root1:MT_CSV_City_CONTACT">  <xsl:copy-of select="*" />   </xsl:template></xsl:stylesheet>

Answers (1)

Answers (1)

0 Kudos

Hi Shiva,

Thank you for the code, we have successfully implemented requirement with the help of your code.

https://answers.sap.com/comments/408907/view.html