
12/04/2024

I need to define a default value for the properties of my custom events. These properties are arrays of KeyValuePair objects, mimicking Map<String, SomeType>. In my case, the values can be either of type String or a custom structure.
Here’s an example of my current setup:
<ObjectType SymbolicName=”Custom:CustomEventType” BaseType=”ua:BaseEventType”>
<Description>A custom event.</Description>
<Children>
<Property SymbolicName=”Custom:MapOfStrings” DataType=”ua:KeyValuePair” ValueRank=”Array” ModellingRule=”Mandatory”>
<DefaultValue>
<!– TODO –>
</DefaultValue>
</Property>
<Property SymbolicName=”Custom:MapOfCustomDataType” DataType=”ua:KeyValuePair” ValueRank=”Array” ModellingRule=”Mandatory”>
<DefaultValue>
<!– TODO –>
</DefaultValue>
</Property>
</Children>
</ObjectType>
<DataType SymbolicName=”Custom:CustomDataType” BaseType=”ua:Structure”>
<Description>A custom structure.</Description>
<Fields>
<Field Name=”Name” DataType=”ua:String” ValueRank=”Scalar”>
<Description>Some name.</Description>
</Field>
<Field Name=”Value” DataType=”ua:Int32″ ValueRank=”Array”>
<Description>Some values.</Description>
</Field>
</Fields>
</DataType>
I’m struggling to define the DefaultValue part for these arrays. The default can be either:
- An empty array.
- An array with a dummy value.
Unfortunately, I couldn’t find any examples or resources addressing this specific case. Does anyone have suggestions or references for implementing this?

05/30/2017

The best way to get the XML for a default value is to create a simple test program
var dict = new List<Opc.Ua.KeyValuePair>();
public void SaveAsXml(ISystemContext context, Stream ostrm)
{
ServiceMessageContext messageContext = new ServiceMessageContext {
NamespaceUris = context.NamespaceUris,
ServerUris = context.ServerUris,
Factory = context.EncodeableFactory
};
XmlWriterSettings settings = Utils.DefaultXmlWriterSettings();
settings.CloseOutput = true;
using (XmlWriter writer = XmlWriter.Create(ostrm, settings))
{
XmlQualifiedName root = new XmlQualifiedName(“DefaultValue”, “https://opcfoundation.org/UA/ModelDesign.xsd”));
using (XmlEncoder encoder = new XmlEncoder(root, writer, messageContext))
{
encoder.WriteEncodeableArray(“ListOfExtensionObjects”, dict.ToArray(), typeof(KeyValuePair));
encoder.Close();
}
}
}
1 Guest(s)