Sfoglia il codice sorgente

xml parse/export Alias, uanodeset attrs

Martin Kunz 9 mesi fa
parent
commit
b45e9418f1
3 ha cambiato i file con 28 aggiunte e 34 eliminazioni
  1. 0 29
      public/nodesets/Opc.Ua.NodeSet2.xml
  2. 23 4
      src/ua/UANodeSet.ts
  3. 5 1
      src/util/XmlElem.ts

+ 0 - 29
public/nodesets/Opc.Ua.NodeSet2.xml

@@ -1,33 +1,4 @@
 <?xml version="1.0" encoding="utf-8" ?>
-<!--
- * Copyright (c) 2005-2022 The OPC Foundation, Inc. All rights reserved.
- *
- * OPC Foundation MIT License 1.00
- * 
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following
- * conditions:
- * 
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * The complete license agreement can be found here:
- * http://opcfoundation.org/License/MIT/1.00/
--->
-
 <UANodeSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" LastModified="2022-11-01T00:00:00Z" xmlns="http://opcfoundation.org/UA/2011/03/UANodeSet.xsd">
   <Models>
     <Model ModelUri="http://opcfoundation.org/UA/" XmlSchemaUri="http://opcfoundation.org/UA/2008/02/Types.xsd" Version="1.05.02" PublicationDate="2022-11-01T00:00:00Z" />

+ 23 - 4
src/ua/UANodeSet.ts

@@ -11,13 +11,19 @@ import { UAObjectType } from './UAObjectType';
 import { UAVariableType } from './UAVariableType';
 import type { AddressSpace } from './AddressSpace';
 import type { IAddressSpace } from './IAddressSpace';
+import { UAAlias } from './UAAlias';
 
 export class UANodeSet implements IToXML{
 
     constructor(public fileName: string,
                 public models: Model[],
+                public aliases: UAAlias[],
                 public nodes: UABaseNode[],
-                public nameSpaceTable: NamespaceTable) {
+                public nameSpaceTable: NamespaceTable,
+                public xmlns_xsi: string,
+                public xmlns_xsd: string,
+                public lastModified: string,
+                public xmlns: string) {
     }
 
     reIndex(nst: NamespaceTable) {
@@ -38,17 +44,24 @@ export class UANodeSet implements IToXML{
 
     toXML(lnst: NamespaceTable, gnst: NamespaceTable): XMLElem {
         const xmlUANodeSet =new XMLElem('UANodeSet');
+        xmlUANodeSet.attr('xmlns:xsi', this.xmlns_xsi);
+        xmlUANodeSet.attr('xmlns:xsd', this.xmlns_xsd);
+        xmlUANodeSet.attr('xmlns', this.xmlns);
+        xmlUANodeSet.attr('LastModified', this.lastModified);
         const xmlNameSpaceUris=xmlUANodeSet.add(new XMLElem('NamespaceUris'));
 
-        for(let i=0;i<this.nameSpaceTable.nsMap.size(); i++) {
+        for(let i=1;i<this.nameSpaceTable.nsMap.size(); i++) { //skip UA(0) ns
             const uri=this.nameSpaceTable.nsMap.get(i);
             xmlNameSpaceUris.elem("Uri", uri);
         }
-
         const xmlModels=xmlUANodeSet.add(new XMLElem('Models'));
         for(const model of this.models) {
             xmlModels.add(model.toXML())
         }
+        const xmlAliases=xmlUANodeSet.add(new XMLElem('Aliases'));
+        for(const alias of this.aliases) {
+            xmlAliases.add(alias.toXML())
+        }
         for(const node of this.nodes) {
             xmlUANodeSet.add(node.toXML(lnst, gnst))
         }
@@ -90,6 +103,11 @@ export class UANodeSet implements IToXML{
         }
         const parser = new XMLParser(parseOptions);
         const xmlObj = parser.parse(xml);
+        const xmlAliases=xmlObj['UANodeSet']['Aliases']||[];
+        const aliases: UAAlias[]=[];
+        for(const xmlAlias of xmlAliases.Alias) {
+            aliases.push(UAAlias.fromXML(xmlAlias));
+        }
         const models: Model[]=[];
         const xmlModels=xmlObj['UANodeSet']['Models']||[];
         for(const xmlModel of xmlModels.Model) {
@@ -125,6 +143,7 @@ export class UANodeSet implements IToXML{
         for(const nsUri of uaNamespaceUris['Uri']||[]) {
             nst.addUri(nsUri['#text'])
         }
-        return new UANodeSet(fileName, models, nodes, nst);
+
+        return new UANodeSet(fileName, models, aliases, nodes, nst, xmlObj['UANodeSet']['@_xmlns'], xmlObj['UANodeSet']['@_xmlns:xsd'], xmlObj['UANodeSet']['@_xmlns:xsi'], xmlObj['UANodeSet']['@_LastModified']);
     }
 }

+ 5 - 1
src/util/XmlElem.ts

@@ -31,7 +31,11 @@ export class XMLElem {
     }
 
     public toString(level: number=0): string {
-        let s=" ".repeat(level+1) + `<${this.name} `;
+        let s="";
+        if(level==0) {
+            s+='<?xml version="1.0" encoding="utf-8" ?>\n'
+        }
+        s+=" ".repeat(level+1) + `<${this.name} `;
         for(const attr of this.attributes) {
             if(attr.value==undefined)
                 continue;