Use Linq to Xml with Xml namespaces

前端 未结 4 1807
深忆病人
深忆病人 2020-11-22 15:19

I have this code :

/*string theXml =
@\"

        
4条回答
  •  醉梦人生
    2020-11-22 15:59

    I have several namespaces listed at the top of an XML document, I don't really care about which elements are from which namespace. I just want to get the elements by their names. I've written this extension method.

        /// 
        /// A list of XElement descendent elements with the supplied local name (ignoring any namespace), or null if the element is not found.
        /// 
        public static IEnumerable FindDescendants(this XElement likeThis, string elementName) {
            var result = likeThis.Descendants().Where(ele=>ele.Name.LocalName==elementName);
            return result;
        }
    

提交回复
热议问题