NAV2013R2: dotNet XSD check

DHendriksenDHendriksen Member Posts: 32
edited 2014-11-05 in NAV Three Tier
Hi All,

We have some NAV code based on dotNet variables which checks an XML document with an XSD Schema:

doc := doc.XmlDocument();
doc.Load('c:\temp\dev\test.xml');
schemas := doc.Schemas;
schemas.Add('', 'c:\temp\dev\test.xsd');
doc.Validate(null);

//doc DotNet 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlDocument
//schemas DotNet 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.Schema.XmlSchemaSet
//null DotNet 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Object

This code compiles in a NAV2009R2 environment, but not in a NAV2013R2 environment. The compile Error is:
ENU: The function call was ambiguous. No matching method was found.
NLD: De functieaanroep is dubbelzinnig. Er is geen overeenkomende methode gevonden.

Does anyone have any clue why this error occures in NAV2013R2 and what is the solution to prevend this error?

Thanks in advance.

Regards, Don

Comments

  • wakestarwakestar Member Posts: 207
    which line is it exactly?
  • DHendriksenDHendriksen Member Posts: 32
    Good question! It's the last line, the validate.
  • DHendriksenDHendriksen Member Posts: 32
    Solved:

    doc := doc.XmlDocument();
    doc.Load('c:\temp\dev\test.xml');
    schemas := doc.Schemas;
    schemas.Add('', 'c:\temp\dev\test.xsd');
    doc.Validate(handler);

    //doc DotNet System.Xml.XmlDocument.'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    //schemas DotNet System.Xml.Schema.XmlSchemaSet.'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    //handler DotNet System.Xml.Schema.ValidationEventHandler.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
  • jhenavjhenav Member Posts: 6
    Thanks for that piece of code! Was searching around for some examples.
    Do you know how to store the return string (if the xml is invalid) and prevent the error message from the DotNet variable?
  • DHendriksenDHendriksen Member Posts: 32
    Hi jhenav,

    If the XML is not valid you get an Error message from the [doc.Validate(null);]. We show this Error message to the user. So we don't have any more code around it.

    Regards, Don
  • geordiegeordie Member Posts: 655
    Hi jhenav,

    If the XML is not valid you get an Error message from the [doc.Validate(null);]. We show this Error message to the user. So we don't have any more code around it.

    Regards, Don

    What about insert it in a codeunit to call with "IF codeunit.RUN" statement?
  • GierkinkGierkink Member Posts: 18
    Hello DHendriksen :

    1. In my case the handler could not be declared as variable :

    doc := doc.XmlDoc//handler DotNet System.Xml.Schema.ValidationEventHandler.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'[/quote]

    It is not available :-k

    2. I would think this is asynchrone programming, and Navision does not support this.

    warm Regard,
    Gierkink
  • landlordlandlord Member Posts: 18
    Hi Gierkink,

    have you been able to resolve this? I also need to validate an xml file against an xsd schema.

    Anyone can help with this one?

    Thanks.
    Gierkink wrote:
    Hello DHendriksen :

    1. In my case the handler could not be declared as variable :

    doc := doc.XmlDoc//handler DotNet System.Xml.Schema.ValidationEventHandler.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

    It is not available :-k

    2. I would think this is asynchrone programming, and Navision does not support this.

    warm Regard,
    Gierkink
  • DHendriksenDHendriksen Member Posts: 32
    The method can't be declared from the overview, but you can copy-paste it while declaring a variable. Undocumented feature :-)
    System.Xml.Schema.ValidationEventHandler.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

    Variables:
    DotNetSchemas, DotNet, System.Xml.Schema.XmlSchemaSet.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    DotNetSchemaHandler, DotNet, System.Xml.Schema.ValidationEventHandler.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

    Code lines:
    DotNetSchemas := DotNetXmlDoc.Schemas;
    DotNetSchemas.Add('',<XSDSchemaLocation>); // Change <XSDSchemaLocation> with the location.
    DotNetXmlDoc.Validate(DotNetSchemaHandler);

    This is working correct in our processes... Hopefully this helps.

    Regards,
    Don
Sign In or Register to comment.