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

Announcements

News and Announcements icon
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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 16

#2
Nagendra Varma K Profile Picture

Nagendra Varma K 4

#2
Harisgillani Profile Picture

Harisgillani 4

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans