Validate XML data using a XSD file

lzrlzr Member Posts: 264
Have anyone used XML ports to generate xml-data from NAV and then validated it using a XSD inside NAV?

I have made it using an extension so far but this will have to be installed on every computer.
Navision developer

Answers

  • ta5ta5 Member Posts: 1,164
    You can use DOM to validate it, needs at least xml4.0.
    CREATE(xmlDoc);
    CREATE(xmlSchemaCache);
    
    xmlSchemaCache.add('http://www.foo.ch/xmlns/f001/1', 'C:\temp\theSchema.xsd');
    xmlDoc.schemas := xmlSchemaCache;
    xmlDoc.async := FALSE;
    xmlDoc.load('c:\temp\theXML.xml');
    
    xmlParseError := xmlDoc.parseError;
    
    IF xmlParseError.errorCode <> 0 THEN BEGIN
      ERROR...
     {
      using
            xmlParseError.errorCode,
            xmlParseError.reason,
            xmlParseError.line,
            xmlParseError.linepos,
            xmlParseError.filepos
      }
    END;
    

    Hope this helps
    Thomas
  • ajhvdbajhvdb Member Posts: 672
    In 5.0, the "send to" button creates a xml too..! What do you need to validate?
  • lzrlzr Member Posts: 264
    ta5 wrote:
    You can use DOM to validate it, needs at least xml4.0.
    CREATE(xmlDoc);
    CREATE(xmlSchemaCache);
    
    xmlSchemaCache.add('http://www.foo.ch/xmlns/f001/1', 'C:\temp\theSchema.xsd');
    xmlDoc.schemas := xmlSchemaCache;
    xmlDoc.async := FALSE;
    xmlDoc.load('c:\temp\theXML.xml');
    
    xmlParseError := xmlDoc.parseError;
    
    IF xmlParseError.errorCode <> 0 THEN BEGIN
      ERROR...
     {
      using
            xmlParseError.errorCode,
            xmlParseError.reason,
            xmlParseError.line,
            xmlParseError.linepos,
            xmlParseError.filepos
      }
    END;
    

    Hope this helps
    Thomas

    Sweet, it worked. Thanks a lot!
    Navision developer
Sign In or Register to comment.