Prechádzať zdrojové kódy

fix xml element names/nodeClass

Martin Kunz 9 mesiacov pred
rodič
commit
fe2bcee484

+ 1 - 1
src/ua/UABaseNode.ts

@@ -184,7 +184,7 @@ export class UABaseNode implements IToXML{
 
     toXML(lnst: NamespaceTable, gnst: NamespaceTable): XMLElem {
         const nid=UABaseNode.localNodeId(this.nodeId, lnst, gnst);
-        const elem =new XMLElem('UAVariable');
+        const elem =new XMLElem('UABaseNode');
         elem.attr('NodeId', nid.toString())
             .attr('BrowseName', this.browseName)
             .attr('WriteMask', this.writeMask.toString())

+ 2 - 1
src/ua/UAMethod.ts

@@ -11,7 +11,7 @@ export class UAMethod extends UABaseNode {
     constructor(options: UAMethodNodeOptions) {
                     super(options);
                     Object.assign(this, options);  
-                    this.nodeClass="Method";
+                    this.nodeClass="UAMethod";
     }
 
     static  fromXML(uaMethod: any, addressSpace: IAddressSpace): UAMethod{
@@ -24,6 +24,7 @@ export class UAMethod extends UABaseNode {
 
     toXML(lnst:NamespaceTable, gnst:NamespaceTable): XMLElem {
         const elem =super.toXML(lnst, gnst);
+        elem.name=this.nodeClass;
         elem.attr("MethodDeclarationId", this.methodDeclarationId);
         elem.attr("UserExecutable", this.userExecutable.toString());
         elem.attr("Executable", this.executable.toString());

+ 2 - 1
src/ua/UAObject.ts

@@ -13,7 +13,7 @@ export class UAObject extends UABaseNode {
     constructor(options: UAObjectNodeOptions) {
         super(options);
         Object.assign(this, options);  
-        this.nodeClass="Object";
+        this.nodeClass="UAObject";
     }
 
     static  fromXML(uaObject: any, addressSpace: IAddressSpace): UAObject{
@@ -25,6 +25,7 @@ export class UAObject extends UABaseNode {
 
     toXML(lnst:NamespaceTable, gnst:NamespaceTable): XMLElem {
         const elem =super.toXML(lnst, gnst);
+        elem.name=this.nodeClass;
         elem.attr("ParentNodeId", this.parentNodeId);
         elem.attr("EventNotifier", this.eventNotifier?.toString());
         return elem;

+ 2 - 0
src/ua/UAObjectType.ts

@@ -9,6 +9,7 @@ export class UAObjectType extends UABaseNode{
     constructor(options: UAObjectTypeOptions) {
         super(options)
         Object.assign(this, options);  
+        this.nodeClass="UAObjectType";
         this.isAbstract=options.isAbstract||false;
     }
 
@@ -19,6 +20,7 @@ export class UAObjectType extends UABaseNode{
 
     toXML(lnst:NamespaceTable, gnst:NamespaceTable): XMLElem {
         const elem =super.toXML(lnst, gnst);
+        elem.name=this.nodeClass;
         elem.attr('IsAbstract', this.isAbstract);
         return elem;
     }

+ 2 - 0
src/ua/UAReferenceType.ts

@@ -9,6 +9,7 @@ export class UAReferenceType extends UABaseNode{
     constructor(options: UAReferenceTypeOptions) {
         super(options)
         Object.assign(this, options);  
+        this.nodeClass="UAReferenceType";
         this.isAbstract=options.isAbstract||false;
     }
 
@@ -19,6 +20,7 @@ export class UAReferenceType extends UABaseNode{
 
     toXML(lnst:NamespaceTable, gnst:NamespaceTable): XMLElem {
         const elem=super.toXML(lnst, gnst);
+        elem.name=this.nodeClass;
         elem.attr('IsAbstract', this.isAbstract);
         return elem;
     }

+ 2 - 1
src/ua/UAVariable.ts

@@ -16,7 +16,7 @@ export class UAVariable extends UABaseNode {
     constructor(options: UAVariableNodeOptions) {
                     super(options);
                     Object.assign(this, options);  
-                    this.nodeClass="Variable";
+                    this.nodeClass="UAVariable";
     }
 
     static  fromXML(uaObject: any, addressSpace: IAddressSpace): UAVariable{
@@ -34,6 +34,7 @@ export class UAVariable extends UABaseNode {
 
     toXML(lnst:NamespaceTable, gnst:NamespaceTable): XMLElem {
         const elem=super.toXML(lnst, gnst);
+        elem.name=this.nodeClass;
         elem.attr("ParentNodeId", this.parentNodeId);
         elem.attr("DataType", this.dataType);
         elem.attr("ValueRank", this.valueRank.toString());

+ 1 - 0
src/ua/UAVariableType.ts

@@ -21,6 +21,7 @@ export class UAVariableType extends UABaseNode{
 
     toXML(lnst:NamespaceTable, gnst:NamespaceTable): XMLElem {
         const elem =super.toXML(lnst, gnst);
+        elem.name=this.nodeClass;
         elem.attr('IsAbstract', this.isAbstract);
         return elem;
     }

+ 9 - 5
src/xml.test.ts

@@ -5,9 +5,13 @@ import * as fs from 'fs';
 
 test('xml', () => {
     const as=new AddressSpace([]);
-    const data = fs.readFileSync('public/nodesets/Opc.Ua.NodeSet2.xml', 'utf8');
-    const nodeset= UANodeSet.parse(data,"NodeSet2",as);
-    as.addNodeset(nodeset);
-    const xmlElem=nodeset.toXML(nodeset.nameSpaceTable, as.nst);
-    fs.writeFileSync("nodeset2.xml", xmlElem.toString());
+    const nodeset2= UANodeSet.parse(fs.readFileSync('public/nodesets/Opc.Ua.NodeSet2.xml', 'utf8'),"NodeSet2",as);
+    as.addNodeset(nodeset2);
+    const dinodeset2= UANodeSet.parse(fs.readFileSync('public/nodesets/Opc.Ua.Di.NodeSet2.xml', 'utf8'),"Di.NodeSet2",as);
+    as.addNodeset(dinodeset2);
+
+    fs.writeFileSync("nodeset2.xml", nodeset2.toXML(nodeset2.nameSpaceTable, as.nst).toString());
+    fs.writeFileSync("dinodeset2.xml", dinodeset2.toXML(dinodeset2.nameSpaceTable, as.nst).toString());
+
+
 })