openminted / omtd-registry-api

Other
0 stars 0 forks source link

Root element of serialized XML representation #11

Closed reckart closed 7 years ago

reckart commented 7 years ago

The first line XML written out from a in memory JAXB representation of the OMTDS classes in this module should be

<ms:componentMetadataRecord 
  xsi:schemaLocation="http://www.meta-share.org/OMTD-SHARE_XMLSchema http://www.meta-share.org/OMTD-SHARE_XMLSchema/v200/OMTD-SHARE-Component.xsd" 
  xmlns:ms="http://www.meta-share.org/OMTD-SHARE_XMLSchema" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 

instead of


<ns1:componentMetadataRecord
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:ns1="http://www.meta-share.org/OMTD-SHARE_XMLSchema" 
  xsi:schemaLocation="http://www.meta-share.org/OMTD-SHARE_XMLSchema http://www.meta-share.org/OMTD-SHARE_XMLSchema/v200/OMTD-SHARE-Component.xsd">
``
courado commented 7 years ago

Is the same as #6 ?

reckart commented 7 years ago

I guess so - unless the order of the attributes somehow matters to @pennyl67 .

reckart commented 7 years ago

In the feedback I got from @pennyl67 the namespace and this case/example were two separate bullet points. I am not sure if this had a special meaning or was just by chance.

pennyl67 commented 7 years ago

in #6 there's a general comment about the namespace, which is used as a prefix for all elements in the xml file. Here the point is about the first line of the XML record. The two are connected in the sense that the first line includes the setting of the prefix of the namespace. I don't know if the order matters.

courado commented 7 years ago

Although since the namespace is a technical issue and the XML produced is a valid document according to the schema. Is it necessary to change?

pennyl67 commented 7 years ago

The namespace is not a technical issue; it also has to do with semantics IMHO. Could you please check if and how it can be done?

courado commented 7 years ago

ms==ns0 if ms and ns0 point to the same namespace. Having ms is just for beauty purposes, the backend does not mind.

pennyl67 commented 7 years ago

can you check where ns0 points?

courado commented 7 years ago

Me ?

reckart commented 7 years ago

@pennyl67 in the example in the first post, I don't see an ns0 only an ns1:

xmlns:ns1="http://www.meta-share.org/OMTD-SHARE_XMLSchema"

@courado is right that from an XML validation/semantics point of view, the namespace prefix is just a shorthand for the full namespace and whether it is some auto-generated nsX or a fixed ms is mainly a matter of beauty (and a matter of whether or not the XML generator is allowed to manage namespace prefixes itself and to ensure their uniqueness).

But ms (or why not omdts?) may still be preferred for the sake of usability/readability.

courado commented 7 years ago

For readability, default namespace wins. To make the change, it has to be made in the XSD model, since these classes are auto-generated. The documentation is outdated and poor, so this is in the bottom of the priorities.

pennyl67 commented 7 years ago

The XSD model? It's already declared in the XSD as "ms". So, where did ns1 appear? I'm missing something here.

pennyl67 commented 7 years ago

Sorry to insist but we will end up with the following situation:

@reckart "ms" comes from MetaShare (legacy); normally, we should have both namespaces with "omtds" (or anything shorter...) for the new elements that have been added through OpenMinTed (never had the time to do it properly...) @courado This means that at some point we should also allow for more than one namespaces and with semantics - not just for beauty sake

reckart commented 7 years ago

@pennyl67 XML validation does not take into account the prefix - it only considers the namespace to which the prefix is bound.

The following two XML documents are equivalent and validate against an XSD which is bound to the http://lala.org namespace irrespective of which prefix is used in the actual XSD:

<ns1:root xmlns:ns1="http://lala.org">
</ns1:root>

<foo:root xmlns:foo="http://lala.org">
</foo:root>

From a consistency point of view: Isn't it also confusing if the ms prefix points to an OMTD namespace when it traditionally points to a metashare namespace? The confusion would be complete if you had an XML document with elements from OMTD-SHARE and from META-SHARE inside it.

For the semantics of the document, the prefix name is irrelevant. What is relevant is the namespace to which the prefix is bound. If you care for consistency then IMHO the OMTD-SHARE XSDs should be changed to reflect that these are no longer META-SHARE elements but OMTD-SHARE elements under the OMTD-SHARE namespace - using the omtds prefix would seem reasonable to me.

Then also the Java classes generated from the XSD should be fixed for consistency sake to generate the prefix used in the OMTD-SHARE XSD files.

pennyl67 commented 7 years ago

Sorry but I am trying to find where the problem has started - because the XSD's that are in github have the following line: <xs:schema xmlns:ms="http://www.meta-share.org/OMTD-SHARE_XMLSchema" where "ms" is declared for the namespace.

I check in the site for resources (https://openminted.github.io/releases/omtd-share/2.0.1/) and the "ms" namespace is missing! I don't know how this has happened, but this explains why we have different files generated. (Hopefully this is the only difference between them - I'll need to check at a later point).

@reckart To make things more confusing, right now, even the XSD points to the MetaShare site... I have not understood yet why they could not be uploaded to OpenMinTeD in a way that the url could be used to properly validate the files.

To close the discussion with the least changes, I can change for THIS version the XSD to replace "ms" with "ns1" so that all XML files are validated no matter what the source - will that be ok? Will it require more changes?

@courado and @reckart However, I would like in the next version of the registry/backend/whatever to properly address this, with the "omtds" namespace or whatever we agree to use.

reckart commented 7 years ago

Sorry but I am trying to find where the problem has started - because the XSD's that are in github have the following line:

<xs:schema xmlns:ms="http://www.meta-share.org/OMTD-SHARE_XMLSchema"

where "ms" is declared for the namespace.

ms is declared here as the prefix. The namespace is http://www.meta-share.org/OMTD-SHARE_XMLSchema.

The namespace is just a name. It has absolutely nothing to do with where the XSD files are hosted.

The place where the files for validation for a given namespace are hosted is indicated be the schemaLocation attribute:

xsi:schemaLocation="http://www.meta-share.org/OMTD-SHARE_XMLSchema http://www.meta-share.org/OMTD-SHARE_XMLSchema/v200/OMTD-SHARE-Component.xsd" 

The line above indicates that the XSD files to validate the namespace http://www.meta-share.org/OMTD-SHARE_XMLSchema can be found at the URL http://www.meta-share.org/OMTD-SHARE_XMLSchema/v200/OMTD-SHARE-Component.xsd. Mind, the prefix doesn't even appear here.

As long as the XSD and the XML files use the same namespace, they should validate. For validation should not matter which prefix is used either in the XML or XSD files. So in fact, it should not be necessary to change anything. The XML files should already validate against the XSDs.

reckart commented 7 years ago

@pennyl67 You can change the schemaLocationattribute to point to any place where we host the XSD files. Currently, this could be your GitHub repo:

xsi:schemaLocation="http://www.meta-share.org/OMTD-SHARE_XMLSchema https://raw.githubusercontent.com/openminted/omtd-share-schema/v2.0.1/Schema/OMTD-SHARE-Component.xsd" 

... or the OpenMinTeD GitHub website ...

xsi:schemaLocation="http://www.meta-share.org/OMTD-SHARE_XMLSchema https://openminted.github.io/releases/omtd-share/2.0.1/xsd/OMTD-SHARE-Component.xsd"
reckart commented 7 years ago

Mind that a production system (e.g. the OMTD registry) should not rely on the schemaLocation attribute at all, otherwise it would be a problem if the server was down, if there were a network problem, etc. Production systems that perform schema validation should always validate against a local copy of the schema. In my experience, the schemaLocation is mainly for documentation and for convenience, i.e. to allow you to easily validate a file in an XML editor without having to set up a local schema catalog.

pennyl67 commented 7 years ago

Thanks for the explanations! I do understand all this, but I'm just wondering how in one XSD the prefix is there and in the other XSD it isn't!

As I said before, I'll take the prefix out of the current version, close the issue and revisit it at the next version.

@reckart For some reason, with the Altova (at least the version I have) the OpenMinTeD github website didn't work for validation. I'll check again with the site and also with the github - but in any case there should be one and only one place where we all refer to the schema xsd.

reckart commented 7 years ago

Maybe Altova had problems with https. If so, try using an http URL.

reckart commented 6 years ago

Btw. when I just used the JAXB classes with the new Java 9, the XML that it generated didn't include any namespace prefixes at all. Switching back to Java 8 added the current ns1 prefix again.