Parsing xml file with linq

前端 未结 2 1128
攒了一身酷
攒了一身酷 2021-01-23 17:51

No matter what I try I am unable to parse this xml with linq and get the full-path value:




        
2条回答
  •  一向
    一向 (楼主)
    2021-01-23 18:40

    You can use the XDocument.Load static method in order to read the full-path value easily, but don't forget to use the element namespace as a prefix:

    var zip = ZipFile.Open(file.FullName, ZipArchiveMode.Read);
    var info = zip.GetEntry("META-INF/container.xml");
    
    var doc = XDocument.Load(info.Open());
    XNamespace ns = "urn:oasis:names:tc:opendocument:xmlns:container";
    var element = doc.Descendants(ns+"rootfile").FirstOrDefault();
    
    if(element != null)
    {
        var fullPath = element.Attribute("full-path").Value;
    }  
    

提交回复
热议问题