Remove Namespace – Web Service Response (DotNet Variable)

Hey Everybody,

This Post is about How to Import directly an XML which is coming as Web-Service from different platform like .NET. Whenever we get a response from a .NET Service we usually get Namespaces coming as enclosed in it. Now being a NAV developer  it’s something which becomes a barrier to us while getting it directly Imported from NAV XML Ports. So here we are to how get rid from this.

What exactly you need to do is you have to write below piece of code with the same DotNet variable references which you have used while getting sending a Request.

Capture

When you will save this in the last call your response will get saved without Namespaces. Now you can directly Import it Via your XML Port.

XmlStyleSheet – MSXML.DOMDocumentClass.’Microsoft.MSXML, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’

XMLSourceDocument – MSXML.DOMDocumentClass.’Microsoft.MSXML, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’

XMLDestinationDocument – MSXML.DOMDocumentClass.’Microsoft.MSXML, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’

CHEERS.

Advertisements

22 comments on “Remove Namespace – Web Service Response (DotNet Variable)

  1. Yes! That was what I meant
    I have an order xml-file with multiple namespaces that I’m trying to import with an xml-port and I guess I have to remove the namespaces and prefix to get it to work in NAV 2013 R2.

    • Hey Anna,

      Yes you are 100% right, if you want to import a Web Service response XML with a XML Port made in NAV then you need to remove Namespaces then only you can Import.

  2. it seems to lack a couple of lines as indicated

    ” +
    ” +
    ” +
    —> ” +
    —> ” +
    ” +
    ” +
    ” +

    Otherwise didnt work to me, nav2013R2 tested.

    • Hi JoaquinR,

      I too did this on NAV2013R2 around a year before and it worked in a single go and till now no Issues. I believe there might be some level of differences in the response XML.

  3. Hello,
    I’m working on NAV 2016, I have created above function but don’t know how to call this function with parameter.

  4. Hi Sandeep,

    Like this you need to call

    RemoveNamespace(XmlDoc,DestinationDocument,Path);

    XmlDoc – DotNetVariable – MSXML.DOMDocumentClass.’Microsoft.MSXML, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’

    DestinationDocument – MSXML.DOMDocumentClass.’Microsoft.MSXML, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’

    Both are same Variable

    Path – Your desired Path.

    • thank you for reply. i can’t see 3rd parameter on above image of function. Please tell me which type of variable i need to create as 3rd parameter

  5. I have created foll. function in codeunit :

    LOCAL RemoveNamespaceDotnet(XMLSourceDocument : DotNet “MSXML.DOMDocumentClass” RUNONCLIENT;XMLDestinationDocument : DotNet “MSXML.DOMDocumentClass” RUNONCLIENT;Path : Text[100])

    IF ISNULL(XmlStyleSheet) THEN
    XmlStyleSheet := XmlStyleSheet.DOMDocumentClass;

    IF ISNULL(XMLSourceDocument) THEN
    XMLSourceDocument := XMLSourceDocument.DOMDocumentClass;

    IF ISNULL(XMLDestinationDocument) THEN
    XMLDestinationDocument := XMLDestinationDocument.DOMDocumentClass;

    XmlStyleSheet.loadXML(” +
    ” +
    ” +
    ” +
    ” +
    ” +
    ” +
    ” +
    ” +
    ” +
    ” +
    ” +
    ” +
    ” +
    ” +
    ” +
    ” +
    ” +
    ” +
    ”);

    XMLSourceDocument.transformNodeToObject(XmlStyleSheet,XMLDestinationDocument);
    XMLSourceDocument.save(‘E:\Retail Import folder\Insotre\INF0004_ExchangeRate.xml’);

    and i have call this function from run procedure of codeunit :
    RemoveNamespaceDotnet(XmlDoc,DestinationDocument,’E:\Retail Import folder\Insotre\INF0004_ExchangeRate_20161116-143719-942.xml’);

    foll. are global variable :
    1)XmlDoc DotNet MSXML.DOMDocumentClass.’Microsoft.MSXML, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’
    2)DestinationDocument DotNet MSXML.DOMDocumentClass.’Microsoft.MSXML, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’

    on running codeunit it shows error :

    A DotNet variable has not been instantiated. Attempting to call MSXML.DOMDocumentClass.transformNodeToObject in CodeUnit Remove Namespaces: RemoveNamespaceDotnet

    on debugging , error line is :
    XMLSourceDocument.transformNodeToObject(XmlStyleSheet,XMLDestinationDocument);

  6. Did you did this part for each and every DotNet variable wherever it was needed

    IF ISNULL(XmlStyleSheet) THEN
    XmlStyleSheet := XmlStyleSheet.DOMDocumentClass;

    RUNONCLIENT Property should be YES

  7. thanks for your outstanding feedback.
    after instantiation of “xmlSourceDocument” we need to put one line :
    XMLSourceDocument.load(Path);

    And
    I think last statement on image should be like this : XMLDestinationDocument.save(‘C:\Test.xml’);
    instead of
    XMLSourceDocument.save(‘C:\Test.xml’);

    Now file created correctly. Thank you very much for your reply.

  8. HI Pranav,
    I send you en email, because I’ve an error on XMLSourceDocument.transformNodeToObject.

    Please let me know.
    Thx.

  9. Luigi,

    So this was the error you were facing – The type of arguments doesn’t match with the Parameter type. It seems that the parameter type is getting disrespected. Can you please let me know the Parameter type which you are sending as XML Source Document, XML Destination Document and the StyleSheet please.

    • My problem was solve with following steps :

      Steps :
      1)Create a procedure “RemoveNamespaceDotnet”
      2)parameters : Path text 100
      3)local variables used :
      i) XmlStyleSheet DotNet MSXML.DOMDocumentClass.’Microsoft.MSXML, Version=8.0.0.0,
      ii)XMLSourceDocument DotNet MSXML.DOMDocumentClass.’Microsoft.MSXML, Version=8.0.0.0,
      iii)XMLDestinationDocument DotNet MSXML.DOMDocumentClass.’Microsoft.MSXML, Version=8.0.0.0,

      4)write following code :

      //—————————————–procedure content—————–
      IF ISNULL(XMLSourceDocument) THEN BEGIN
      XMLSourceDocument := XMLSourceDocument.DOMDocumentClass;
      XMLSourceDocument.load(Path);
      END;

      IF ISNULL(XmlStyleSheet) THEN
      XmlStyleSheet := XmlStyleSheet.DOMDocumentClass;

      IF ISNULL(XMLDestinationDocument) THEN
      XMLDestinationDocument := XMLDestinationDocument.DOMDocumentClass;

      XmlStyleSheet.loadXML(” +
      ” +
      ” +
      ” +
      ” +
      ” +
      ” +
      ” +
      ” +
      ” +
      ” +
      ” +
      ” +
      ” +
      ” +
      ” +
      ” +
      ” +
      ” +
      ”);

      XMLSourceDocument.transformNodeToObject(XmlStyleSheet,XMLDestinationDocument);
      XMLDestinationDocument.save(Path);
      //————————————————-

      5)pass path of file in which you want to remove namespaces, this file replaced with new files with removed namespaces

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s