Skip to Content

Need to delete Root node and convert into Json format

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.

Add comment
10|10000 characters needed characters exceeded

  • 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

  • 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>
    
    
  • Get RSS Feed

2 Answers

  • Best Answer
    Jan 24 at 05:55 AM

    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>
    
    
    Add comment
    10|10000 characters needed characters exceeded

  • Jan 23 at 02:51 PM

    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

    Add comment
    10|10000 characters needed characters exceeded