开发者

how to select all desendent from xmlfile

I have the following XML snippet:

<dependency>
  <dependentAssembly dependencyType="install" allowDelayedBinding="true"  size="92开发者_StackOverflow中文版160">
    <hash>
      <dsig:Transforms>
        <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
      </dsig:Transforms>
      <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
      <dsig:DigestValue>CPxsdsbvZSAAkmARkxa8ychL2aLZRc=</dsig:DigestValue>
    </hash>
  </dependentAssembly>
</dependency>

How to select this node using LINQ, or all decendent nodes for it:

<dsig:Transforms> 

Thanks.


XDocument.Load("file.xml").Root.Descendants(XName.Get("dsig", "Transforms"));


Something like this should work:

XElement docElem = XElement.Load(pathToXml);
XNamespace ns = "http://www.w3.org/2000/09/xmldsig#";

// This assumes you know there will be exactly one "Transforms" element
XElement transforms = docElem.Descendants(ns + "Transforms").Single();
foreach (XElement transform in transforms.Elements()) {
    // Do something with each Transform element
}

For this to work the complete XML (with namespace prefix declarations) must be loaded.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜