Reading Attribute with SID: DTNV (Name Value) from API
Stacey Hwasser
started a topic
almost 7 years ago
How can I read the Named value list with the API? When I try it and convert it to string I got a lot of Chinese signs. How is it encoded?
Best Answer
S
SystemWeaver Support
said
almost 7 years ago
Here is an example of an attribute that should work the same way as yours. First a picture on how it looks in the client:
The below code will read the attribute. The data will be in xml-format, so you need to parse the data yourself if you want to display it.
In this example, I am replacing "Value2" with "Value3" and writing it back. Notice that you need ZCompressStringToBytes() if you want to you write back.
Attribute after code has replaced "Value2" with "Value3":
1 Comment
SystemWeaver Support
said
almost 7 years ago
Answer
Here is an example of an attribute that should work the same way as yours. First a picture on how it looks in the client:
The below code will read the attribute. The data will be in xml-format, so you need to parse the data yourself if you want to display it.
In this example, I am replacing "Value2" with "Value3" and writing it back. Notice that you need ZCompressStringToBytes() if you want to you write back.
Stacey Hwasser
How can I read the Named value list with the API? When I try it and convert it to string I got a lot of Chinese signs. How is it encoded?
Here is an example of an attribute that should work the same way as yours. First a picture on how it looks in the client:
The below code will read the attribute. The data will be in xml-format, so you need to parse the data yourself if you want to display it.
In this example, I am replacing "Value2" with "Value3" and writing it back. Notice that you need ZCompressStringToBytes() if you want to you write back.
This code will display the xml below
SystemWeaverAPI.SWConnection.Instance.LoginName = "test";
SystemWeaverAPI.SWConnection.Instance.Password = "test";
SystemWeaverAPI.SWConnection.Instance.ServerMachineName = "localhost";
SystemWeaverAPI.SWConnection.Instance.ServerPort = int.Parse("1769");
SystemWeaverAPI.SWConnection.Instance.Login();
var testItem = SWConnection.Instance.Broker.GetItem(SWHandleUtility.ToHandle("x040000000008711F"));
var attr = testItem.Attribute("DTNV");
var xmlStr = attr.ValueAsXML;
Console.Write(xmlStr);
xmlStr = xmlStr.Replace("Value2", "Value3");
testItem.SetAttributeDataWithSID("DTNV", SystemWeaver.Common.Internal.SWCompression.ZCompressStringToBytes(xmlStr));
Xml read from the attribute:
<NamedValues>
<NamedValue>
<Min>1</Min>
<Max>1</Max>
<Name>Value1</Name>
</NamedValue>
<NamedValue>
<Min>2</Min>
<Max>2</Max>
<Name>Value2</Name>
</NamedValue>
</NamedValues>
Attribute after code has replaced "Value2" with "Value3":
SystemWeaver Support
Here is an example of an attribute that should work the same way as yours. First a picture on how it looks in the client:
The below code will read the attribute. The data will be in xml-format, so you need to parse the data yourself if you want to display it.
In this example, I am replacing "Value2" with "Value3" and writing it back. Notice that you need ZCompressStringToBytes() if you want to you write back.
This code will display the xml below
SystemWeaverAPI.SWConnection.Instance.LoginName = "test";
SystemWeaverAPI.SWConnection.Instance.Password = "test";
SystemWeaverAPI.SWConnection.Instance.ServerMachineName = "localhost";
SystemWeaverAPI.SWConnection.Instance.ServerPort = int.Parse("1769");
SystemWeaverAPI.SWConnection.Instance.Login();
var testItem = SWConnection.Instance.Broker.GetItem(SWHandleUtility.ToHandle("x040000000008711F"));
var attr = testItem.Attribute("DTNV");
var xmlStr = attr.ValueAsXML;
Console.Write(xmlStr);
xmlStr = xmlStr.Replace("Value2", "Value3");
testItem.SetAttributeDataWithSID("DTNV", SystemWeaver.Common.Internal.SWCompression.ZCompressStringToBytes(xmlStr));
Xml read from the attribute:
<NamedValues>
<NamedValue>
<Min>1</Min>
<Max>1</Max>
<Name>Value1</Name>
</NamedValue>
<NamedValue>
<Min>2</Min>
<Max>2</Max>
<Name>Value2</Name>
</NamedValue>
</NamedValues>
Attribute after code has replaced "Value2" with "Value3":
-
Comparing two versions of a structure
-
Context and path language
-
Overview of meta model
-
Importing old data
-
Cannot find multiple version items
-
Accumulated bar chart
-
Cannot remove part - is referenced
-
View of non accessable data
-
Path: How to check if an attribute is empty?
-
List and path language
See all 33 topics