Error with arguements of System.Xml.Xsl.XslTransform during webrequest

AronChanAronChan Member Posts: 9
Hi Everybody

Im trying to process a webrequest in NAV2017 with System Dotnet variables.

Im currently trying to implement this: http://forum.mibuso.com/discussion/63741/dotnet-for-webrequest - More specificly the part where i strip the response of namespace and soap.

However im having some issues with the Transform function getting the following error:
A call to System.Xml.Xsl.XslTransform.Transform failed with this message: The type of one or more arguments does not match the method's parameter type.

My RemoveNameSpace function looks like this:

Parameters:
Var	Name	DataType	Subtype	Length
No	Source	DotNet	System.Xml.XmlDocument.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
Yes	Destination	DotNet	System.Xml.XmlDocument.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

Local variables:
Name	DataType	Subtype	Length
XslTransform	DotNet	System.Xml.Xsl.XslTransform.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
XmlStyleSheet	DotNet	System.Xml.XmlDocument.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
Writer	DotNet	System.IO.StringWriter.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
XsltNullArgs	DotNet	System.Xml.Xsl.XsltArgumentList.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
XsltNullArgs2	DotNet	System.Xml.Xsl.XsltArgumentList.'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

Code:
XslTransform := XslTransform.XslTransform;
XmlStyleSheet := XmlStyleSheet.XmlDocument;
XmlStyleSheet.InnerXml(
'<?xml version="1.0" encoding="UTF-8"?>' +
'<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">' +
'<xsl:output method="xml" encoding="UTF-8" />' +
'<xsl:template match="/">' +
'<xsl:copy>' +
'<xsl:apply-templates />' +
'</xsl:copy>' +
'</xsl:template>' +
'<xsl:template match="*">' +
'<xsl:element name="{local-name()}">' +
'<xsl:apply-templates select="@* | node()" />' +
'</xsl:element>' +
'</xsl:template>' +
'<xsl:template match="@*">' +
'<xsl:attribute name="{local-name()}"><xsl:value-of select="."/></xsl:attribute>' +
'</xsl:template>' +
'<xsl:template match="text() | processing-instruction() | comment()">' +
'<xsl:copy />' +
'</xsl:template>' +
'</xsl:stylesheet>'
);
XslTransform.Load(XmlStyleSheet);
Writer := Writer.StringWriter;
XslTransform.Transform(Source,XsltNullArgs2,Writer);
Destination := Destination.XmlDocument;
Destination.InnerXml(Writer.ToString);

Any directions as to why this fails would be greatly appreciated?

Answers

  • HannesHolstHannesHolst Member Posts: 119
    Because of the different .Net-version?

    My version does this job slightly different, but with the same (expected) result:
    LOCAL RemoveXMLNamespaces(VAR pContentContainer : TEMPORARY Record TempBlob)
    pContentContainer.Blob.CREATEINSTREAM(ContainerInStream, TEXTENCODING::UTF8);
    pContentContainer.Blob.CREATEOUTSTREAM(ContainerOutStream, TEXTENCODING::UTF8);
    ContainerInStream.READ(ContainerText);
    
    IF ISNULL(XMLStyleSheet) THEN
      XMLStyleSheet := XMLStyleSheet.DOMDocumentClass;
    
    IF ISNULL(XMLSourceDocument) THEN
      XMLSourceDocument := XMLSourceDocument.DOMDocumentClass;
     
    IF ISNULL(XMLDestinationDocument) THEN
      XMLDestinationDocument := XMLDestinationDocument.DOMDocumentClass;
     
    XMLStyleSheet.loadXML(XSL_Convert);
    XMLSourceDocument.loadXML(ContainerText);
    XMLSourceDocument.transformNodeToObject(XMLStyleSheet,XMLDestinationDocument);
    
    CLEAR(pContentContainer.Blob);
    ContainerOutStream.WRITETEXT(XMLDestinationDocument.xml);
    

    Variables:
    Name	DataType	Subtype	Length
    XMLStyleSheet	DotNet	MSXML.DOMDocumentClass.'Microsoft.MSXML, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'	
    XMLSourceDocument	DotNet	MSXML.DOMDocumentClass.'Microsoft.MSXML, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'	
    XMLDestinationDocument	DotNet	MSXML.DOMDocumentClass.'Microsoft.MSXML, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'	
    ContainerInStream	InStream		
    ContainerOutStream	OutStream		
    ContainerText	Text		
    

    Textconstant:
    Name	ConstValue
    XSL_Convert	<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="xml" encoding="UTF-8" indent="yes" /><xsl:strip-space elements="*"/><xsl:template match="/"><xsl:copy><xsl:apply-templates /></xsl:copy></xsl:template><xsl:template match="*"><xsl:element name="{local-name()}"><xsl:apply-templates select="@* | node()" /></xsl:element></xsl:template><xsl:template match="@*"><xsl:attribute name="{local-name()}"><xsl:value-of select="."/></xsl:attribute></xsl:template><xsl:template match="text() | processing-instruction() | comment()"><xsl:copy /></xsl:template></xsl:stylesheet>
    
  • AronChanAronChan Member Posts: 9
    HannesHolst thanks for replying. However you are using the Office XML variables. I am trying to avoid using anything but the standard DotNet variables so that my code is not dependant on a paid product.
  • HannesHolstHannesHolst Member Posts: 119
    That's an interesting concern. I didn't think about it before.
    But anyway, the MSXML-components are shipped with .Net Framework since Version 3:
    MSXML 6.0 MSXML6 is the latest MSXML product from Microsoft, and (along with MSXML3) is shipped with Microsoft SQL Server 2005, Visual Studio 2005, .NET Framework 3.0, Windows Vista, Windows 7 and Windows XP Service Pack 3. It also has support for native 64-bit environments. It is an upgrade but not replacement for versions 3 and 4 as they still provide legacy features not supported in version 6.[dubious – discuss] Version 6, 4, and 3 may all be installed and running concurrently. MSXML 6 is not supported on Windows 9x. Windows XP SP3 includes MSXML 6.0 SP2.
    (https://en.wikipedia.org/wiki/MSXML)

    Cheers,
  • AronChanAronChan Member Posts: 9
    If a newer version of office is installed your references are no longer valid. So i want to use the System components
Sign In or Register to comment.