我有以下 XDocument:
<?xml version="1.0" encoding="utf-8"?>
<D:multistatus xmlns:D="DAV:" xmlns:Office="urn:schemas-microsoft-com:office:office" xmlns:Repl="http://schemas.microsoft.com/repl/" xmlns:Z="urn:schemas-microsoft-com:">
<D:response>
<D:href>http://aaa</D:href>
<D:propstat>
<D:prop>
<D:displayname>a</D:displayname>
<D:isFolder>t</D:isFolder>
</D:prop>
<D:status>HTTP/1.1 200 OK</D:status>
</D:propstat>
</D:response>
<D:response>
.
.
</D:response>
我怎样才能得到所有的回应?(“D:response”标签下的所有内容,显然“D:propstat”和“D:prop”标签下的所有内容 - 我想获得D:href,D:displayname,D:isFolder)
我正在这样做:
XNamespace d = "DAV:";
foreach (var file in doc.Descendants(d + "response"))
{
if ((string)file.Element(d + "href") != (string)Configuration.Configs["baseUrl"])
{
string ref = (string)file.Element(d + "href");
foreach (var propstat in file.Descendants(d + "propstat"))
foreach (var prop in propstat.Descendants(d + "prop"))
{
string name = (string)prop.Element(d + "displayname");
if (prop.Element(d + "isFolder") != null && (string)prop.Element(d + "isFolder") == "t")
string type = "folder";
else
string type = "file";
}
}
}
有没有更好的办法?