bulk associate documents to a schema

Having trouble installing <oXygen/>? Got a bug to report? Post it all here.
bernardusgui
Posts: 10
Joined: Thu Oct 18, 2018 11:45 am

bulk associate documents to a schema

Post by bernardusgui » Sat May 11, 2019 3:00 pm

I have about 1000 XML documents that I'd like to associate with a single customized schema (.rng file). Is there a method in Oxygen for associating a collection of XML documents with a specific schema? Or do I have to do this one by one?

Or perhaps there a way to add an attribute in the XML document root to point to the schema .rng file? If I'm pointing to it, how do I do that in the following case where everything is in eXist-DB:

the xml files are all kept in eXist-DB under db/apps/myapp/data , but the schema is in a separate collection db/apps/myapp/schema

Thanks in advance.

adrian
Posts: 2533
Joined: Tue May 17, 2005 4:01 pm

Re: bulk associate documents to a schema

Post by adrian » Tue May 14, 2019 3:45 pm

Hi,

Oxygen doesn't have a specialized batch (bulk ) "Associate Schema" operation that makes the association within the XML file. Note that the association with RelaxNG appears in the XML file as a processing instruction. e.g.

Code: Select all

<?xml-model href="path/to/my/schema.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
Unfortunately XML Refactoring cannot be used in this case (the change/insertion) in the XML is before the root element.

However, for local files you may not need to make this association if you use the files within Oxygen with an Oxygen project. You can create a custom validation scenario that specifies your customized schema (project level), and associate that validation scenario with your XML files in the Project view. Oxygen will use the schema from the custom validation scenario for validation and content completion.

To accomplish this:
1. Make sure you have a persistent project (.xpr) file. Create/save a project (Project > New Project) in the parent folder (or higher in the hierarchy) of your XML files.
2. If the project file is in the parent folder or higher, you should already see your files when expanding folders in the Project view. If not, you can manually link your XML files folder (right click on project root and pick Add folder), or the individual files (right click on project root and pick Add Files)
3. In the Project view right click on one of the files (or the entire folder or file selection) and pick Validate > Configure Validation Scenario, New. Give it a proper name (e.g."Validate with myschema.rng"). Double click the Schema cell, pick Use custom schema, and browse for your schema. OK in all dialogs and Save and close.
4. If you want to associate this with additional files, right click on the folder or file selection, pick Validate > Configure Validation Scenario, and just select (check the box) for the scenario configured at step 3.
5. Now when you open one of the files for which you made this validation scenario association, it will automatically be validated with your configured scenario. You can check in the Properties view (Window > Show view > ...) for Validation scenario and the schema being used, Content Completion.


Since you mentioned eXist-db, you might have to make the schema association within the files anyway. Since XML Refactoring cannot be used in this situation, the quick and dirty way is to use "Find/Replace in Files".
eXist usually omits the XML declaration, so you can add your schema association at the beginning or right before the root.
How does your average XML file look like (first couple of lines up to and including the root)?

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Post Reply