Skip to content

Commit

Permalink
implement UAView#dumpXML
Browse files Browse the repository at this point in the history
  • Loading branch information
erossignon committed Jun 29, 2023
1 parent 283bd1f commit b3ac8eb
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 12 deletions.
Expand Up @@ -30,7 +30,8 @@ import {
UAReference,
UAReferenceType,
UAVariable,
UAVariableType
UAVariableType,
UAView
} from "node-opcua-address-space-base";
import { AttributeIds, Int64, minOPCUADate, StatusCode, StatusCodes } from "node-opcua-basic-types";
import { BrowseDescription, EnumDefinition, StructureDefinition, StructureType } from "node-opcua-types";
Expand All @@ -55,6 +56,7 @@ import {
constructNamespacePriorityTable,
hasHigherPriorityThan
} from "./construct_namespace_dependency";
import { UAViewImpl } from "../ua_view_impl";

// tslint:disable:no-var-requires
const XMLWriter = require("xml-writer");
Expand Down Expand Up @@ -939,6 +941,21 @@ function _dumpUADataTypeDefinition(xw: XmlWriter, uaDataType: UADataType) {
}
}

function dumpUAView(xw: XmlWriter, node: UAView) {
_markAsVisited(xw, node);

xw.startElement("UAView");
xw.writeAttribute("NodeId", n(xw, node.nodeId));
xw.writeAttribute("BrowseName", b(xw, node.browseName));

dumpCommonElements(xw, node);

xw.endElement();

dumpAggregates(xw, node);

}

function dumpUADataType(xw: XmlWriter, node: UADataType) {
_markAsVisited(xw, node);

Expand Down Expand Up @@ -1345,6 +1362,10 @@ UADataTypeImpl.prototype.dumpXML = function (xw: XmlWriter) {
dumpUADataType(xw, this);
};

UAViewImpl.prototype.dumpXML = function (xw: XmlWriter) {
dumpUAView(xw, this);
}

function makeTypeXsd(namespaceUri: string): string {
return namespaceUri.replace(/\/$/, "") + "/Type.xsd";
}
Expand Down
59 changes: 48 additions & 11 deletions packages/node-opcua-address-space/test/test_nodeset_to_xml.ts
Expand Up @@ -47,7 +47,7 @@ describe("testing nodeset to xml", () => {
}
});

it("KLKL1 should output a standard extension object datatype to xml (Argument)", () => {
it("NS2XML-1 should output a standard extension object datatype to xml (Argument)", () => {
const argumentDataType = addressSpace.findDataType("Argument")!;
if (doDebug) {
console.log(argumentDataType.toString());
Expand All @@ -59,7 +59,7 @@ describe("testing nodeset to xml", () => {
str.should.match(/Argument/);
});

it("KLKL2 should output a standard Enum node to xml (ServerState)", () => {
it("NS2XML-2 should output a standard Enum node to xml (ServerState)", () => {
// TemperatureSensorType
const serverStateType = addressSpace.findDataType("ServerState")!;
const str = dumpXml(serverStateType);
Expand All @@ -69,7 +69,7 @@ describe("testing nodeset to xml", () => {
str.should.match(/CommunicationFault/);
});

it("KLKL3 should output a custom Enum node to xml (MyEnumType) - Form1( with EnumStrings )", () => {
it("NS2XML-3 should output a custom Enum node to xml (MyEnumType) - Form1( with EnumStrings )", () => {
const myEnumType = namespace.addEnumerationType({
browseName: "MyEnumTypeForm1",
enumeration: ["RUNNING", "STOPPED"]
Expand All @@ -90,7 +90,7 @@ describe("testing nodeset to xml", () => {
str.should.match(/<Field Name="STOPPED" Value="1">/);
});

it("KLKL4 should output a custom Enum node to xml (MyEnumType) - Form2 ( with EnumValues )", () => {
it("NS2XML-4 should output a custom Enum node to xml (MyEnumType) - Form2 ( with EnumValues )", () => {
const myEnumType = namespace.addEnumerationType({
browseName: "MyEnumType",
enumeration: [
Expand All @@ -109,15 +109,15 @@ describe("testing nodeset to xml", () => {
str.should.match(/<Field Name="STOPPED" Value="20">/);
});

it("KLKL5 should output a simple objectType node to xml", () => {
it("NS2XML-5 should output a simple objectType node to xml", () => {
// TemperatureSensorType
const temperatureSensorType = createTemperatureSensorType(addressSpace);

const str = dumpXml(temperatureSensorType);
str.should.match(/UAObjectType/);
});

it("KLKL6 should output a instance of a new ObjectType to xml", () => {
it("NS2XML-6 should output a instance of a new ObjectType to xml", () => {
const ownNamespace = addressSpace.getOwnNamespace();

// TemperatureSensorType
Expand Down Expand Up @@ -153,7 +153,7 @@ describe("testing nodeset to xml", () => {
str.should.match(/UAObjectType/g);
});

it("KLKL7 should output a instance of object with method to xml", () => {
it("NS2XML-7 should output a instance of object with method to xml", () => {
const cameraType = createCameraType(addressSpace);

const camera1 = cameraType.instantiate({
Expand All @@ -175,7 +175,7 @@ describe("testing nodeset to xml", () => {
);
});

it("KLKL8 should output an instance of variable type to xml", () => {
it("NS2XML-8 should output an instance of variable type to xml", () => {
const ownNamespace = addressSpace.getOwnNamespace();
const variableType = ownNamespace.addVariableType({ browseName: "MyCustomVariableType" });

Expand All @@ -186,7 +186,7 @@ describe("testing nodeset to xml", () => {
str.should.match(/UAVariableType/g);
});

it("KLKL9 should output a ReferenceType to xml", () => {
it("NS2XML-9 should output a ReferenceType to xml", () => {
const ownNamespace = addressSpace.getOwnNamespace();
const referenceType = ownNamespace.addReferenceType({
browseName: "HasStuff",
Expand All @@ -202,7 +202,7 @@ describe("testing nodeset to xml", () => {
str.should.match(/HasStuff/g);
});

it("KLKLA should output a Method to xml", () => {
it("NS2XML-A should output a Method to xml", () => {
const ownNamespace = addressSpace.getOwnNamespace();

const rootFolder = addressSpace.findNode("RootFolder")! as UARootFolder;
Expand Down Expand Up @@ -320,6 +320,43 @@ describe("testing nodeset to xml", () => {
</UAVariable>
<!--Object - 1:Object }}}} -->`);
});

it("NS2XML-B should output a View to xml", () => {
const ownNamespace = addressSpace.getOwnNamespace();

const rootFolder = addressSpace.findNode("RootFolder")! as UARootFolder;

const obj1 = ownNamespace.addObject({
browseName: "Object",
organizedBy: rootFolder.objects
});

const view = ownNamespace.addView({
browseName: "View1",
organizedBy: rootFolder.views
});

view.addReference({
nodeId: obj1,
referenceType: "Organizes",
isForward: true
});

const str = dumpXml(view);

str.should.match(/<\/UAView>/g, "must have a complex UAView element");

console.log(str);

str.should.eql(`<?xml version="1.0"?>
<UAView NodeId="ns=1;i=1001" BrowseName="1:View1">
<DisplayName>View1</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
<Reference ReferenceType="Organizes" IsForward="false">i=87</Reference>
</References>
</UAView>`);
});
});

describe("Namespace to NodeSet2.xml", () => {
Expand Down Expand Up @@ -840,7 +877,7 @@ describe("nodeset2.xml with more than one referenced namespace", function (this:
fs.writeFileSync(tmpFilename, xml);

const r_xml2 = await reloadedNodeSet(tmpFilename);

r_xml2.split("\n").should.eql(xml2.split("\n"));
});
it("NSXML9 - matrix of extension objects", async () => {
Expand Down

0 comments on commit b3ac8eb

Please sign in to comment.