简体   繁体   English

如何获得几乎没有差异的XML节点的内容? (C#)

[英]How to get the content of XML nodes that have little differences? (C#)

I want to parse different XML that all of them have the same content but with this differences: 我想解析不同的XML,它们都具有相同的内容,但存在以下差异:

Some of the XML are like: 一些XML如下:

<ds:X509Data><ds:X509Certificate>MIIDtT[...]lLgXlaoNwM=</ds:X509Certificate></ds:X509Data>

Others are: 其他是:

<dsig:X509Data><dsig:X509Certificate>MIIDtT[...]lLgXlaoNwM=</dsig:X509Certificate></dsig:X509Data>

I want to get the content of the "X509Certificate" node to save it in a file. 我想获取“ X509Certificate”节点的内容以将其保存在文件中。

For other parts of the XML that are always the same, I was using: 对于XML的其他始终相同的部分,我正在使用:

doc.GetElementsByTagName("CountryName");

But I cant do the same here. 但是我不能在这里做同样的事情。

What should I do? 我该怎么办?

You can use XDocument Class and query it with LINQ. 您可以使用XDocument类 ,并使用LINQ查询它。

var certificates = from doc in xDoc.Root.documents()
         from attr in doc.Attributes()
         where attr.Name.ToString().Contains("X509Certificate")
         select attr;

You can now loop through certificates and read in the values 您现在可以遍历certificates并读取值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM