What is the more efficient way to check an XmlDocument for an XmlDeclaration node?
What is the more efficient way to check an XmlDocument for an XmlDeclaration node?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
What sort of “efficiency” are you after? Efficiency of expression, or efficiency at execution time? Here’s a LINQ query which finds the declaration pretty quickly:
I strongly suspect that will be efficient enough. It’s possible that you could just test whether the first child node was an
XmlDeclaration… I don’t think anything else can come before it.If there’s any possibility of using LINQ to XML instead, then it becomes even easier – you just use the
XDocument.Declarationproperty.