Method to obtain a List of XML elements within an XMLDocument, given the element name. - CSharp System.Xml

CSharp examples for System.Xml:XML Document

Description

Method to obtain a List of XML elements within an XMLDocument, given the element name.

Demo Code

/*// w w  w.  java 2s. c om
 * Copyright (C) 2006-2010 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography;
using System.Security.Cryptography;
using System.Data;
using System.ComponentModel;
using System.Security;
using System.Collections;
using System.Configuration;
using System.Security.Principal;
using System.IO;
using System.Net;
using System.Collections.Specialized;
using System.Web;
using System.Xml;
using System.Globalization;
using System;

public class Main{
        /// <summary>
        /// Method to obtain a List of XML elements within an XMLDocument,
        /// given the element name.
        /// </summary>
        /// <param name="doc">Xml Document</param>
        /// <param name="name">element name to be found</param>
        /// <returns>List of XML Elements with matcing name</returns>
        public static XmlNodeList FindAllElements(XmlDocument doc, String name)
        {
            XmlNodeList list = doc.GetElementsByTagName(name, name.Equals(Common.ISSUER) ? Common.SAML_NAMESPACE_ASSERTION : Common.SAML_NAMESPACE);
            return list;
        }
}

Related Tutorials