I have an xml document with 100 nodes, each node has 10-15 attribues.
I iterate through the nodes and try to read all the 15 attributes and store it...
If the attribute does not exists in the node, then
throws an exception....
If all attributes are found, parse time is 0ms.
If I use a try-catch for handling the non existing attributes, the parse time is 3000ms, which is terrible...
If I use an IndexOf() for the attribute name in the node's text to check wether the attribute is found or not, then the parse time is 200ms. I think this is the overhead of the IndexOf string find operations...
The question is:
How to get an attribute (even if not exists) without this overhead?
In other words how to check for the non existence of an attribute???
public string GetSafeNodeAttribute(XmlNode xNode, string sAttributeName)
if (xNode.OuterXml.IndexOf(sAttributeName + "=\"") > -1)
catch (Exception ex)
//string sEx = ex.ToString();
//Common.Trace(1,"Exception in CharmTabPage.GetSafeNodeAttribute\n" + ex.ToString());