Validate an XML file with a given XSD file

Hello,
Are there any tools in Matlab that will check that an xml file coforms to a given xml schema (.xsd) file?
Thanks!

回答 (2 件)

Wil Koenen
Wil Koenen 2020 年 2 月 6 日

1 投票

You can call Java libraries from MATLAB.
Example pure Java code can be found at stackoverflow.com. Translated to Java calls from MATLAB:
schemaFileName = "MySchema.xsd";
xmlFileName = "MyXML.xml";
schemaFile = java.io.File(schemaFileName);
xmlFile = java.io.File(xmlFileName);
schemaFactory = javax.xml.validation.SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
schema = schemaFactory.newSchema(schemaFile);
validator = schema.newValidator();
fileInputStream = java.io.FileInputStream(xmlFile);
streamSource = javax.xml.transform.stream.StreamSource(fileInputStream);
validator.validate(streamSource); % throws an exception if not valid
Hari Krishna Ravuri
Hari Krishna Ravuri 2019 年 11 月 5 日

0 投票

As of now, there is no in-built function in MATLAB to validate the given XML file with the XSD given by the user.

カテゴリ

質問済み:

2019 年 10 月 30 日

回答済み:

2020 年 2 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by