diff --git a/README.md b/README.md index c3272cefb2103423d68107df63a89b123009d739..0e947815b01a0c03d4039177f593fc04a91711e9 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ const doc = DCCDocument.fromXml(xml); // access the properties of the DCC // _attr contains all the attributes of a given element -doc.digitalCalibrationCertificate._attr.schemaVersion // => 3.1.0 +doc.digitalCalibrationCertificate._attr.schemaVersion // => 3.1.1 // _text is used to access the value of the given element doc.digitalCalibrationCertificate.administrativeData.coreData.uniqueIdentifier._text diff --git a/src/DCC.ts b/src/DCC.ts index 1a0e9f4c3cd0688af077084a5ba93773f59013dc..a186379922c13d2ad4ec90e3d993b6d6788e8ff3 100644 --- a/src/DCC.ts +++ b/src/DCC.ts @@ -2,7 +2,7 @@ import * as si from "./DSI"; import { XMLDate, XMLElement, XMLNumber, XMLBoolean, XMLList, INamespaced, ISchemaInformation } from "./BaseTypes"; import { ensureArray } from "./Util"; -const schemaVersion = "3.1.0"; +const schemaVersion = "3.1.1"; const namespace = "dcc"; const namespaceUrl = `https://ptb.de/${namespace}`; const schemaLocation = `${namespaceUrl}/v${schemaVersion}/dcc.xsd`; @@ -1041,6 +1041,7 @@ export class ListType extends DCCXMLElement { constructor(el: Partial<ListType> = {}) { super(el); + if (el.name) this.name = new TextType(el.name); if (el.description) this.description = new RichContentType(el.description); if (el.usedMethods) this.usedMethods = new UsedMethodListType(el.usedMethods); @@ -1062,7 +1063,7 @@ export class ListType extends DCCXMLElement { export class RelativeUncertaintyType extends DCCXMLElement { // region choice relativeUncertaintyXmlList?: si.RealListXMLListType; - relativeUncertainty?: si.RealQuantityType; + relativeUncertaintySingle?: si.RealQuantityType; // endregion choice @@ -1071,7 +1072,7 @@ export class RelativeUncertaintyType extends DCCXMLElement { // choice if (el.relativeUncertaintyXmlList) this.relativeUncertaintyXmlList = new si.RealListXMLListType(el.relativeUncertaintyXmlList); - else if (el.relativeUncertainty) this.relativeUncertainty = new si.RealQuantityType(el.relativeUncertainty); + else if (el.relativeUncertaintySingle) this.relativeUncertaintySingle = new si.RealQuantityType(el.relativeUncertaintySingle); } } diff --git a/src/DCCDocument.ts b/src/DCCDocument.ts index 065f7aec87cb669ec30bb952870f5982a47ec4c2..74d8aa8ffc2873c32d452a913ae885991a967a24 100644 --- a/src/DCCDocument.ts +++ b/src/DCCDocument.ts @@ -1,6 +1,6 @@ import { Element, js2xml, xml2js } from "xml-js"; -import { DigitalCalibrationCertificateType } from "./DCC"; +import { DigitalCalibrationCertificateType, DCC } from "./DCC"; export class DCCDocument { _declaration: unknown; @@ -11,6 +11,16 @@ export class DCCDocument { this.digitalCalibrationCertificate = new DigitalCalibrationCertificateType(el?.digitalCalibrationCertificate); } + static createEmpty() { + return new DCCDocument({ + digitalCalibrationCertificate: new DigitalCalibrationCertificateType({ + _attr: { + schemaVersion: DCC.schemaVersion, + }, + }), + }); + } + static fromXml(xml) { const parsed = <Partial<DCCDocument>>xml2js(xml, { compact: true, diff --git a/tests/DCCDocument.test.ts b/tests/DCCDocument.test.ts index 0bf6753d79988490ce9922ed4ccdf28c7f3f928d..3e1d88919b741ac2cfc6b78369fa83bbc68348d8 100644 --- a/tests/DCCDocument.test.ts +++ b/tests/DCCDocument.test.ts @@ -1,5 +1,5 @@ import { DCCDocument } from "../src"; -import { xml } from "./Resources/siliziumkugel.xml"; +import { xml } from "./Resources/example.xml"; import { expect } from "chai"; import { describe, it } from "mocha"; diff --git a/tests/Resources/siliziumkugel.xml.ts b/tests/Resources/example.xml.ts similarity index 99% rename from tests/Resources/siliziumkugel.xml.ts rename to tests/Resources/example.xml.ts index 12c534b4851702cbd55e112bec51e69fd6ca7b24..ecb64cf607bec72353ec3e48fe26fb57e086e21f 100644 --- a/tests/Resources/siliziumkugel.xml.ts +++ b/tests/Resources/example.xml.ts @@ -1,4 +1,4 @@ -const dcc = `<dcc:digitalCalibrationCertificate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dcc="https://ptb.de/dcc" xmlns:si="https://ptb.de/si" xsi:schemaLocation="https://ptb.de/dcc https://ptb.de/dcc/v3.1.0/dcc.xsd" schemaVersion="3.1.0"> +const dcc = `<dcc:digitalCalibrationCertificate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dcc="https://ptb.de/dcc" xmlns:si="https://ptb.de/si" xsi:schemaLocation="https://ptb.de/dcc https://ptb.de/dcc/v3.1.1/dcc.xsd" schemaVersion="3.1.1"> <dcc:administrativeData> <dcc:dccSoftware> <dcc:software>