OpcUaXmlStreamDecoder implements UaDecoder { public Object readVariantValue() { if (currentNode(null)) { Node node = currentNode; String nodeName = node.getLocalName(); if (nodeName.startsWith("ListOf")) { String type = nodeName.substring(6); List<Object> values = new ArrayList<>(); NodeList childNodes = node.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { currentNode = childNodes.item(i); if (currentNode.getNodeType() == Node.ELEMENT_NODE) { values.add(readBuiltinType(type, type)); } } Object array = Array.newInstance(builtinTypeClass(type), values.size()); for (int i = 0; i < values.size(); i++) { Array.set(array, i, values.get(i)); } return array; } else if (nodeName.equals("Matrix")) { List<Integer> dimensions = new ArrayList<>(); Node child = node.getFirstChild(); for (int i = 0; i < child.getChildNodes().getLength(); i++) { currentNode = child.getChildNodes().item(i); if (currentNode.getNodeType() == Node.ELEMENT_NODE) { dimensions.add(readInt32("Int32")); } } List<Object> elements = new ArrayList<>(); child = child.getNextSibling(); for (int i = 0; i < child.getChildNodes().getLength(); i++) { currentNode = child.getChildNodes().item(i); if (currentNode.getNodeType() == Node.ELEMENT_NODE) { String type = currentNode.getLocalName(); elements.add(readBuiltinType(type, type)); } } Class<?> clazz = elements.get(0).getClass(); Object array = Array.newInstance(clazz, elements.size()); for (int i = 0; i < elements.size(); i++) { Array.set(array, i, elements.get(i)); } int[] dims = new int[dimensions.size()]; for (int i = 0; i < dimensions.size(); i++) { dims[i] = dimensions.get(i); } return ArrayUtil.unflatten(array, dims); } else { return readBuiltinType(nodeName, nodeName); } } else { return null; } } OpcUaXmlStreamDecoder(SerializationContext context); OpcUaXmlStreamDecoder setInput(Document document); OpcUaXmlStreamDecoder setInput(Reader reader); OpcUaXmlStreamDecoder setInput(InputStream inputStream); @Override Boolean readBoolean(String field); @Override Byte readSByte(String field); @Override Short readInt16(String field); @Override Integer readInt32(String field); @Override Long readInt64(String field); @Override UByte readByte(String field); @Override UShort readUInt16(String field); @Override UInteger readUInt32(String field); @Override ULong readUInt64(String field); @Override Float readFloat(String field); @Override Double readDouble(String field); @Override String readString(String field); @Override DateTime readDateTime(String field); @Override UUID readGuid(String field); @Override ByteString readByteString(String field); @Override XmlElement readXmlElement(String field); @Override NodeId readNodeId(String field); @Override ExpandedNodeId readExpandedNodeId(String field); @Override StatusCode readStatusCode(String field); @Override QualifiedName readQualifiedName(String field); @Override LocalizedText readLocalizedText(String field); @Override ExtensionObject readExtensionObject(String field); @Override DataValue readDataValue(String field); @Override Variant readVariant(String field); Object readVariantValue(); @Override DiagnosticInfo readDiagnosticInfo(String field); @Override UaMessage readMessage(String field); @Override T readEnum(
        String field,
        Class<T> enumType
    ); @Override Object readStruct(String field, NodeId dataTypeId); @Override Object readStruct(String field, ExpandedNodeId dataTypeId); @Override Object readStruct(String field, DataTypeCodec codec); @Override @SuppressWarnings("unchecked") T[] readArray(
        String field,
        Function<String, T> decoder,
        Class<T> clazz); @Override Boolean[] readBooleanArray(String field); @Override Byte[] readSByteArray(String field); @Override Short[] readInt16Array(String field); @Override Integer[] readInt32Array(String field); @Override Long[] readInt64Array(String field); @Override UByte[] readByteArray(String field); @Override UShort[] readUInt16Array(String field); @Override UInteger[] readUInt32Array(String field); @Override ULong[] readUInt64Array(String field); @Override Float[] readFloatArray(String field); @Override Double[] readDoubleArray(String field); @Override String[] readStringArray(String field); @Override DateTime[] readDateTimeArray(String field); @Override UUID[] readGuidArray(String field); @Override ByteString[] readByteStringArray(String field); @Override XmlElement[] readXmlElementArray(String field); @Override NodeId[] readNodeIdArray(String field); @Override ExpandedNodeId[] readExpandedNodeIdArray(String field); @Override StatusCode[] readStatusCodeArray(String field); @Override QualifiedName[] readQualifiedNameArray(String field); @Override LocalizedText[] readLocalizedTextArray(String field); @Override ExtensionObject[] readExtensionObjectArray(String field); @Override DataValue[] readDataValueArray(String field); @Override Variant[] readVariantArray(String field); @Override DiagnosticInfo[] readDiagnosticInfoArray(String field); @Override Object[] readEnumArray(
        String field,
        Class<T> enumType
    ); @Override Object[] readStructArray(String field, NodeId dataTypeId); @Override Object[] readStructArray(String field, ExpandedNodeId dataTypeId);  }
@Test public void testReadVariantValue() throws Exception { String xml = "<ListOfExtensionObject xmlns=\"http: "<ExtensionObject><TypeId><Identifier>i=297</Identifier>\n" + " </TypeId><Body><Argument><Name>BreakLockStatus</Name><DataType><Identifier>i=6</Identifier>\n" + " </DataType><ValueRank>-1</ValueRank><ArrayDimensions/><Description xmlns:p5=\"http: " </Argument>\n" + " </Body>\n" + " </ExtensionObject>\n" + " </ListOfExtensionObject>\n"; OpcUaXmlStreamDecoder decoder = new OpcUaXmlStreamDecoder(new TestSerializationContext()) .setInput(new StringReader(xml)); assertNotNull(decoder.readVariantValue()); }