On 28. Aug 2017, at 23:02, Dave Day David.Day@duke-software.com wrote:
Greetings BaseX list,
I've got some very basic questions I was hoping I could get the answers to on this list. Questions really break down into two categories. My background is strictly on IBM mainframes, so please bear with me. 1)Some XML schema questions, and 2)Questions regarding how to configure/use BaseX for what I want to do. XML schema. I've got a record definition created by IBM that changes somewhat depending upon the release of the system. I want to create XML schema for each release dependent definition, and then make that definition available to BaseX. I thought using namespaces was the way to go, but now am not sure. What I was hoping to do was to connect to a running BaseX, and send the schema definitions that would be used to validate the XML. In reading doc, I see it is possible to create namespaces and use them, but the format has to be either a URL or a URN. Is it possible to create a URN for a namespace on the fly, and then tell the code later on which namespace to use? Regards, -- Dave Day
Hi Dave,
is it possible to see one of those 'record definitions created by IBM’ as an example?
I guess, what you would want to generate given a ‘record definition’ is twofold:
- Multiple XML representations of actual data that corresponds to the ‘record definition’. - A schema definition to validate instances of those XML representions.
Example:
A ‘record definition’: Mainframe defines an event. An event has a start and end time as integers. Each event has an id.
I guess such a definition is probably burried in some kind of specification or even source code, but can be extracted somehow. So you finally get something from which you would be able to automatically generate a schema definition. This generated schema definition could look like this (in RELAX NG [1]):
[mainframe.rng] ``` <grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<start> <ref name="mainframe"/> </start>
<define name="mainframe"> <element name="mainframe"> <zeroOrMore> <ref name="event"/> </zeroOrMore> </element> </define>
<define name="event"> <element name="event"> <ref name="event.attlist"/> </element> </define>
<define name="event.attlist"> <ref name="id.attrib"/> <ref name="start.attrib"/> <ref name="end.attrib"/> </define>
<define name="id.attrib"> <attribute name="id"> <ref name="id.datatype"/> </attribute> </define>
<define name="start.attrib"> <attribute name="start"> <ref name="integer.datatype"/> </attribute> </define>
<define name="end.attrib"> <attribute name="end"> <ref name="integer.datatype"/> </attribute> </define>
<define name="id.datatype"> <data type="ID"/> </define>
<define name="integer.datatype"> <data type="integer"/> </define>
</grammar> ```
Now events occur on the mainframe and your code produces event XML instances, such as:
[event-1.xml] ``` <mainframe> <event start="1000" end="1700" id="e1"/> <event start="3300" end="4000" id="e2"/> </mainframe> ```
To ‘validate’ those XML instances you use a software such as jing [2].
[terminal] ``` $ jing mainframe.rng event-1.xml ```
No BaseX involved so far.
If you need to store a lot of those XML documents, it may, of course, be handy to store them in BaseX. To validate them against the schema you can use the Validation Module [3].
[validate.xq] ``` validate:rng-report('event-1.xml', 'mainframe.rng') ```
Am I on the right track of what you are trying to achieve?
Kind regards, Alex
[1] http://relaxng.org [2] http://relaxng.org/#validators [3] http://docs.basex.org/wiki/Validation_Module#RelaxNG_Validation