Search XDocument using LINQ without knowing the namespace

后端 未结 6 1822
春和景丽
春和景丽 2020-11-30 04:49

Is there a way to search an XDocument without knowing the namespace? I have a process that logs all SOAP requests and encrypts the sensitive data. I want to find any elemen

6条回答
  •  没有蜡笔的小新
    2020-11-30 05:00

    I think I found what I was looking for. You can see in the following code I do the evaluation Element.Name.LocalName == "CreditCardNumber". This seemed to work in my tests. I'm not sure if it's a best practice, but I'm going to use it.

    XDocument xDocument = XDocument.Load(@"C:\temp\Packet.xml");
    var elements = xDocument.Root.DescendantsAndSelf().Elements().Where(d => d.Name.LocalName == "CreditCardNumber");
    

    Now I have elements where I can encrypt the values.

    If anyone has a better solution, please provide it. Thanks.

提交回复
热议问题