Search XDocument with LINQ with out knowing the Namespace

Posted by BarDev on Stack Overflow See other posts from Stack Overflow or by BarDev
Published on 2010-04-09T21:09:47Z Indexed on 2010/04/09 21:13 UTC
Read the original article Hit count: 462

Filed under:
|
|
|
|

Is there a way to search a XDocument without knowing the Namespace. I have a process that logs all soap requests and encrypts the sensitive data. I want to find any elements based on name. Something like, give me all elements where the name is CreditCard. I don't care what the namespace is.

My problem seems to be with LINQ and requiring a xml namespace.

I have other processes that retrieve values from XML, but I know the namespace for these other process. XDocument xDocument = XDocument.Load(@"C:\temp\Packet.xml"); XNamespace xNamespace = "http://CompanyName.AppName.Service.Contracts";

var elements = xDocument.Root.DescendantsAndSelf().Elements().Where(d => d.Name == xNamespace + "CreditCardNumber");

But what I really want, is to have the ability to search xml without knowing about namespaces, something like this: XDocument xDocument = XDocument.Load(@"C:\temp\Packet.xml"); var elements = xDocument.Root.DescendantsAndSelf().Elements().Where(d => d.Name == "CreditCardNumber")

But of course this will not work be cause I do no have a namespace.

BarDev

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET