开发者

XML formatting for later parsing in c#

I'm using XML to hold some settings, so let's go with the following example:

<PermissionLevels>
    <Permission Name="MyPermission 1" Bases="XXX" />
    <Permission Name="MyPermission 2" Bases="XXX" />
</PermissionLevels>

So the XXX is my problem. I will have several base permissions, e.g. "Read, Create, Delete", and I know C# has the .Split method, so I could probably try it with "," as a delimiter. I could also have child nodes to <Permission>.

Is there a correct way to do it? With correct I mean the following: I'm not sure whether I should use LINQ (XDocument) or the regular System.Xml variant (XmlDocument) and I am not sure if some different way might be better to handle.

With .Split I will have to take the node.Attributes["Base"].Value, split it and do a foreach for all elements in the array - maybe LINQ is smarter and can do something differently?

Sorry for my rambling, this is just not my domain. The question actually is: When I have multiple values for one attribute, do I concatenate th开发者_StackOverflowem with e.g. a ",", or do I do it differently (e.g. with child nodes of the object)?


I would prefer child nodes. Attributes are meant for scalar (single) values.

Also, this way your source code in C# with LINQ will be simple and that's good.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜