开发者

Properties in XML

开发者 https://www.devze.com 2022-12-14 11:13 出处:网络
Is there a special XML element for name/value property pairs like the following, something that I can leverage in C# code?

Is there a special XML element for name/value property pairs like the following, something that I can leverage in C# code?

   <Properties>
        <Property>
            <Name>xyz</Name>
            <开发者_如何学JAVAValue>abc</Value>
        </Property>
    </Properties>


I dont know anything directly unless you use Serialization to do it for you.

I have found this form to be pretty useful, and fairly compact in most situations:

<properties>
   <property key="xyz">abc</property>
</properties>

Then iterate through them with something similar to:

Dictionary<string, string> properties = new Dictionary<string, string>()
foreach(XmlNode property in root.SelectNodes("properties/property") {
   string name = property.Attributes["key"].Value as string
   string value = property.InnerText;

   properties.add(name, value);
}


XML and C# are completely different. You can parse any valid XML using C#. Could you describe what your end goal is in more detail?


You could use attributes. Attributes are name-value pairs associated to tags like so:

<Tag xyz="abc">
    <!-- more XML tags -->
</Tag>
0

精彩评论

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

关注公众号