Reading node data from XML

Hi,

I’m trying to build a node with the following properties:

public ObservableCollection Qualification { get; set; }

I’d like to charge it in the XML. In the method overcharge: MakeXElement(), I have:

e.Add(XHelper.ReadElements(e.Element(“Qualification”), “Key”,
new ObservableCollection(), ConvertStringToNodeKey));

I took this from the helps, but I don’t know hot to build the function ConvertStringToNodeKey. Furthermore, I’d like to charge the graph by the XML and in the method overcharge LoadFromXElement(), I have the following:

this.Qualification = (ObservableCollection)XHelper.ReadElements(e.Element(“Qualification”), “Key”,
new ObservableCollection(), ConvertStringToNodeKey);

To both cases I need the function: ConvertStringToNodeKey, Please give me any help (How to built it or an example about this)

Thanks!

Just define a function that takes a String and returns the appropriate value that is of the NodeKey type of your model.

If your NodeKey type is String, then maybe you can use the identity function.

Could you be more specific and give me an example please.
thanks

The function is responsible for converting the XElement.Value to a node data key.

You didn’t say what kind of keys you are using for your node data.

If they are strings, and if they are unique per node data, then you can use XHelper.ToString. If the key type is integer, you could use XHelper.ToInt32. If the key type is GUID, you could use XHelper.ToGuid.

More generally, you can use a lambda expression to define whatever conversion you want. The identity conversion XHelper.ToString could also be implemented as:
x => x

Actually, in re-reading your post, it isn’t clear to me what QualificationNode is. Is that your node data type? Is the Qualification property supposed to be a collection of references to other node data?

If so, then you probably don’t want to use XHelper.ReadElements.

But then again, it depends on what your model’s NodeKey type is.