Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

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?

*This post is locked for comments

  • 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) // ...

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans