AdamaJava / adamajava

Other
14 stars 4 forks source link

Set xml namespaceURI in ctor #332

Closed holmeso closed 1 year ago

holmeso commented 1 year ago

Description

When using a java8 VM, setting the namespaceURI attribute once the DOM node has been created works just fine. For later versions of the java VM, this is not the case. The workaround, as presented in this PR, is to set the namespaceURI when creating the node (rather than via the setAttribute method). As such, the method creating the DOM node (XmlUtils.createRootElement) has been overloaded giving the user the option of supplying a namespaceURI.

This issue came to light when running the existing qprofiler2 and ngscheck programs using a JVM version 11 and upwards. Ngscheck would not parse a qprofiler2 xml created by a version 11 JVM due to xml validation issues caused by the namespaceURI being missing.

Type of change

Please delete options that are not relevant.

How Has This Been Tested?

Existing unit tests pass. qprofiler2 has been run using the updated code and the output is parseable by ngscheck using both java 8 and java 11 VMs

Are WDL Updates Required?

nope

Checklist:

ChristinaXu2017 commented 1 year ago

Could you please show the difference between the XMLs created before and after this update? I am just not sure whether it will look like <qProfiler .... uri="XSD_NAMESPACE">

holmeso commented 1 year ago

Could you please show the difference between the XMLs created before and after this update? I am just not sure whether it will look like <qProfiler .... uri="XSD_NAMESPACE">

Before update: <qProfiler xmlns="https://adamajava.org/xsd/qprofiler2/v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" finishTime="2023-05-17 03:38:17" operatingSystem="Linux" startTime="2023-05-17 03:36:31" user="cromwelltst" version="114-9838e15" xsi:schemaLocation="https://adamajava.org/xsd/qprofiler2/v2 https://purl.org/adamajava/xsd/qprofiler2/v2/qprofiler2.xsd">

After update: <qProfiler xmlns="https://adamajava.org/xsd/qprofiler2/v2" finishTime="2023-05-22 09:41:28" operatingSystem="Linux" startTime="2023-05-22 09:39:46" user="oliverH" version="118-129a3c91" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://adamajava.org/xsd/qprofiler2/v2 https://purl.org/adamajava/xsd/qprofiler2/v2/qprofiler2.xsd">

ChristinaXu2017 commented 1 year ago

Ok, Thanks. I may have to clarify what is the difference between the XMLs created before and after this update in JVM 11. I guess you mean that "root.setAttribute( "xmlns", Messages.getMessage(msgResource, "XSD_NAMESPACE"))" does nothing in JVM 11, so the output will miss xmlns="https://adamajava.org/xsd/qprofiler2/v2". is this the problem that this pull request try to solve?

holmeso commented 1 year ago

Ok, Thanks. I may have to clarify what is the difference between the XMLs created before and after this update in JVM 11. I guess you mean that "root.setAttribute( "xmlns", Messages.getMessage(msgResource, "XSD_NAMESPACE"))" does nothing in JVM 11, so the output will miss xmlns="https://adamajava.org/xsd/qprofiler2/v2". is this the problem that this pull request try to solve?

Yes, thats exactly the problem. If you run the current production code using java11, the xmlns attribute is missing, and ngsCheck fails because it can't validate the xml.