Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Suggested answer

Validate XML against XSD located in a web

Posted on by 350

I have an XML file that points to its XSD located on a web server.

 

<order xsi:noNamespaceSchemaLocation="http://something.somewhere.com>

 

In AXv3, validation was simple -- xmlDoc = XMLDocument::newXML(xml, true, true)

 

Although XMLDocument::newXML in AX 2009 still has a parameter for validation, it does not appear to work. No error, no warning, nothing when I step on some values.

 

What is the trick in AX 2009 for validating XML against an XSD housed in a web when the XSD is referenced in the XML?

  • ACO Profile Picture
    ACO 350 on at
    Re: Validate XML against XSD located in a web

    Not quite what I was looking for.  I ended up pulling the expected attribute (xsi:noNamespaceSchemaLocation) from the XML and using XMLSchema.sourceUri() to retrieve it:

     

    xmlReader.moveToAttribute2("xsi:noNamespaceSchemaLocation");
    tempStr = xmlReader.value();
    if (tempStr)
        xmlSchema.sourceUri(tempStr);

     

    Still running into trouble though. I have verified that xmlSchema contains the schema using:

     

    tempStr = xmlSchema.writeToString();

     

    But when I call:

     

    validationError = xmlReader.validate(xmlSchema.writeToString());

     

    I constantly get the error: "The 'myroot' element is not declared." where 'myroot' is the name of the outermost element in the XML.

     

    Any ideas on how to resolve or at least debug this?

  • Suggested answer
    Re: Validate XML against XSD located in a web

    I'm afraid  in AX 2009 to validate an XML file against its XSD you'll have to load the schema by yourself. You can use XmlReader to validate an XML file - see \Classes\AifRequestProcessor\validateParameterSchema for an example:

    
    XmlTextReader xmlReader = XmlTextReader::newXml(xmlText);
    XmlSchemaValidationError xmlError = xmlReader.validate(xsdText);
    if (xmlError) // ...

     

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,246 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,041 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans