Options

Removing XML Namespaces

NAVupNorthNAVupNorth Member Posts: 14
I'm working on an upgrade from v4 to 2018 and using extensions as much as possible. There's a bespoke function in the v4 database to remove namespaces from some XML being imported from a Magento website. It uses automations (Microsoft XML, v6.0) so I can't use it as-is in an extension.

I'm not sure how to replicate it other than as a function in a standard codeunit called from the extension. Does anybody have any ideas?

The original code was from a page on Partnersource which doesn't seem to exist anymore.

Thanks in advance.
//from https://mbs.microsoft.com/partnersource/documentation/howtoarticles/xmlportswebservices.htm?printpage=false

TempBlob.Blob.CREATEOUTSTREAM(OutStreamStylesheet);
TempBlob.Blob.CREATEINSTREAM(InStreamStylesheet);
OutStreamStylesheet.WRITETEXT('<?xml version="1.0" encoding="UTF-8"?>');
OutStreamStylesheet.WRITETEXT('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">');
OutStreamStylesheet.WRITETEXT('<xsl:output method="xml" encoding="UTF-8" />');
OutStreamStylesheet.WRITETEXT('<xsl:template match="/">');
OutStreamStylesheet.WRITETEXT('<xsl:copy>');
OutStreamStylesheet.WRITETEXT('<xsl:apply-templates />');
OutStreamStylesheet.WRITETEXT('</xsl:copy>');
OutStreamStylesheet.WRITETEXT('</xsl:template>');
OutStreamStylesheet.WRITETEXT('<xsl:template match="*">');
OutStreamStylesheet.WRITETEXT('<xsl:element name="{local-name()}">');
OutStreamStylesheet.WRITETEXT('<xsl:apply-templates select="@* | node()" />');
OutStreamStylesheet.WRITETEXT('</xsl:element>');
OutStreamStylesheet.WRITETEXT('</xsl:template>');
OutStreamStylesheet.WRITETEXT('<xsl:template match="@*">');
OutStreamStylesheet.WRITETEXT('<xsl:attribute name="{local-name()}"><xsl:value-of select="."/></xsl:attribute>');
OutStreamStylesheet.WRITETEXT('</xsl:template>');
OutStreamStylesheet.WRITETEXT('<xsl:template match="text() | processing-instruction() | comment()">');
OutStreamStylesheet.WRITETEXT('<xsl:copy />');
OutStreamStylesheet.WRITETEXT('</xsl:template>');
//-001
OutStreamStylesheet.WRITETEXT('<xsl:template match="*[normalize-space() = '''']" />');
//+001
OutStreamStylesheet.WRITETEXT('</xsl:stylesheet>');
IF ISCLEAR(XMLStyleSheet) THEN
  CREATE(XMLStyleSheet);
XMLStyleSheet.load(InStreamStylesheet);
IF ISCLEAR(XMLDestinationDocument) THEN
  CREATE(XMLDestinationDocument);
XMLSourceDocument.transformNodeToObject(XMLStyleSheet,XMLDestinationDocument);

Answers

Sign In or Register to comment.