Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about Document.validate #628

Open
sbalaji1996 opened this issue Jun 15, 2023 · 3 comments
Open

Question about Document.validate #628

sbalaji1996 opened this issue Jun 15, 2023 · 3 comments

Comments

@sbalaji1996
Copy link

I have a decently sized xsd file (~7 mb) that I'm using to validate various xml documents that I'm constructing. My code looks something like this

async function validateXML(xmlString) {
    const xsdString = (await fs.readFile(xsdFilePath)).toString();
    const xsd = libxmljs.parseXml(xsdString);
    const xml = libxmljs.parseXml(xmlString);
    xml.validate(xsd);
}

I'm finding that after I invoke validate, the majority of the time spent during validation (a few hundred milliseconds) is in the xmlSchemaParse function here, based on some console statements that I've added to test performance:

const schema = xmlSchemaParse(parser_ctxt);

My question is - if the xsd file is static, is there a way to provide the library that file (or a reference to that file) once and just have it reference that instead of attempting to parse the xsd every time I invoke validate?

@rchipka
Copy link
Member

rchipka commented Jun 20, 2023

There isn't currently a way, but we could provide a function to parse and return schema documents then overload Document.validate to accept an already-parsed schema document

@axel-capodaglio
Copy link

Hi, is there any update on this?

@CCheminaud
Copy link

I have the same need on my side, here is a PR: #656.
Probably it could be improved, I'm open to suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants