Search XDocument with LINQ with out knowing the Namespace
- by BarDev
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