Validate an XML file with a given XSD file

40 views (last 30 days)
Eric Tsai
Eric Tsai on 30 Oct 2019
Answered: Wil Koenen on 6 Feb 2020
Are there any tools in Matlab that will check that an xml file coforms to a given xml schema (.xsd) file?

Answers (2)

Hari Krishna Ravuri
Hari Krishna Ravuri on 5 Nov 2019
As of now, there is no in-built function in MATLAB to validate the given XML file with the XSD given by the user.

Wil Koenen
Wil Koenen on 6 Feb 2020
You can call Java libraries from MATLAB.
Example pure Java code can be found at Translated to Java calls from MATLAB:
schemaFileName = "MySchema.xsd";
xmlFileName = "MyXML.xml";
schemaFile =;
xmlFile =;
schemaFactory = javax.xml.validation.SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
schema = schemaFactory.newSchema(schemaFile);
validator = schema.newValidator();
fileInputStream =;
streamSource =;
validator.validate(streamSource); % throws an exception if not valid

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!