This is a sample xml. If a new font is to be added in the sense, all the existing fonts to be compare with the new font before adding to the preference. How do I check the node(font) whether already exists or not in case of XmlDocument?
<preferences>
<font role="console">
<size>9</size>
<fname>Courier</fname>
</font>
<font role="default">
<fname>Times New Roman</fname>
<size>14</size>
</font>
<font role="titles">
<size>10</size>
<fname>Helvetica</fname>
</font>
</preferences>
One approach would be to create a couple of classes to represent the XML document and implement the
IEquatable<T> Interface.https://dotnetfiddle.net/QZFwDy
Classes for XML
Then use the
Preferencesclass to deserialize the XML. Once the document is deserialized, leverage theList<T>.Contains(T item)method to see if the font node exists. The.Containsmethod will call the implementation ofEqualsin theFontclass.Code to Demonstrate