web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Xml validation with schema.

(0) ShareShare
ReportReport
Posted on by 25

Hello.

 I'm trying to validate a XML file using schemas. The problem is that, when I validate it on a schema of which has another schema linked to it through <xs:include schemaLocation="AnotherSchema.xsd"/>
it won't validate. It's because it won't go through the linked schemas in the schema file.

 I can easily validate a schema by using XmlResolver, but I can't find a way to validate a XML with resolver too.

 This is easily done in .NET using the XmlValidatingReader class.

Any hints and thoughts are welcome too!

 

static void TestSchemaTwo(Args _args)
{
    XMLReader           xmlReader;
    XmlSchema               schema = XMLSchema::newFile(@'C:\XMLTest\xsd\services\Schema1.xsd');
    XmlSchema               tempSchema;
    XmlSchemaObjectTable    elementsTable;
    XmlQualifiedName        qName, schemaTypeQName;
    XmlSchemaElement        schemaElement;
    XmlResolver             resolver;
    str                     targetNamespace;
    XmlSchemaValidationError    validationError;
    XmlSchemaObjectEnumerator   enum;
    XmlSchemaElement            element;
    XmlReaderSettings           readerSettings = new XmlReaderSettings();

    ;

    new InteropPermission(InteropKind::ClrInterop).assert();

    resolver = new XmlResolver();
    resolver.allowFileAccess(true);
    resolver.allowWebAccess(false);
    resolver.baseUrlOverride(@"C:\XMLTest\xsd\services\");

    schema.compile(resolver);

    if(!schema.isCompiled())
        info(schema.validationError().message());

    readerSettings.xmlResolver(resolver);
    xmlReader = XMLReader::newXml(@"C:\XMLTest\SomeXML.xml");
   
    validationError = xmlReader.validate(schema.writeToString());
    info(tempSchema.writeToString());
    if (validationError)
        info(validationError.message());


    CodeAccessPermission::revertAssert();


    xmlReader.close();
    resolver = null;
    schema = null;


}

*This post is locked for comments

I have the same question (0)
  • Denis Patrakov Profile Picture
    on at
    [quote user="Jon Arason"]

     I can easily validate a schema by using XmlResolver, but I can't find a way to validate a XML with resolver too.

    This is easily done in .NET using the XmlValidatingReader class.

    [/quote]Then why not just use XmlValidatingReader from X++?
  • Jon Arason Profile Picture
    25 on at
    Hi. Well, I could by creating a .NET object, but I was hoping it could be done via X++, without working with .NET objects within Dynamics AX. I assume that you mean that I should create a .NET object, which I could do fine...

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans