sandialabs / InterSpec

spectral radiation analysis software
https://sandialabs.github.io/InterSpec
GNU Lesser General Public License v2.1
126 stars 21 forks source link

DHS: namespace in output N42s has no definition. #14

Open jpbrodsky opened 2 years ago

jpbrodsky commented 2 years ago

Interspec v 1.0.10 rc2

I used the Interspec "Export" function to produce a N42 (2012) file. This file looks like this (with some sections removed):

`<?xml version="1.0" encoding="utf-8"?>

Source of intrinsic activity:Cesium137 InterSpec ... ... ... 2 ... ` The "DHS" namespace designation in `` is not defined in the document as required by the XML standard (i.e. using an `xmlsn=....`). This makes the file unparseable by the python package lxml due it the non-compliance with the XML standard. As lxml is based on libxml2, presumably that package will also have trouble parsing these files. lxml error message: Namespace prefix DHS on Interspec is not defined, line xx, column yy I suggest this issue be corrected by defining the DHS namespace in the output xml. While different parsers may be more or less tolerant of this issue, my understanding is that lxml is correct here in objecting to the use of an undefined namespace (even if I wish it might "loosen up a little" and parse the file regardless of this issue).
wcjohns commented 2 years ago

Thanks for reporting this Jason.

This is an item that has been on my TODO list for quite a while - however, I hadn't been aware of impact to any one (e.g., all the other spectroscopy programs seem to read the files without issues), so it has been low priority; I'll bump it up in priority, but can't promise a date when it will be done by.

A few things worth noting are:

thanks again, -will

jpbrodsky commented 2 years ago

Thanks, Will!

At this point, we're not planning on modifying our software to specifically support the output of InterSpec, but being able to read it alongside other N42s would be a nice bonus. SpecUtils may be a good solution for that, but for the reasons you mention it's a relatively large job to solve a somewhat small problem.

Best, Jason

Am6er commented 2 years ago

Or just do something like that, before fix incoming.

            //Add DHS namespace for Interspec compatibility
            XmlDocument xmldoc = new XmlDocument();
            XmlReaderSettings settings = new XmlReaderSettings { NameTable = new NameTable() };
            XmlNamespaceManager xmlns = new XmlNamespaceManager(settings.NameTable);
            xmlns.AddNamespace("DHS", "http://www.w3.org/2001/XMLSchema-instance");
            XmlParserContext context = new XmlParserContext(null, xmlns, "", XmlSpace.Default);
            //Add DHS namespace for Interspec compatibility
            RadInstrumentData radInstrumentData = new RadInstrumentData();
            using (XmlReader reader = XmlReader.Create(filename, settings, context))