本文介绍了XPath适用于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi there,

困难在于某些行以开始 span> < tr bgcolor =#DDEEFF">而其中一些带有< tr>

我只需要提取以下格式的数据:

I need to extract just the data in the following format:

路径,帐户,路径,目录所有者,权限(简单), 应用于, 继承, 权限(高级).

Path,Account,Path,Directory Owner,Permission (Simple),Apply To,Inherited,Permissions (Advanced) .

任何XPath都能完成此操作吗?

< table cellpadding ="1" class ="sortable"< tr>< th bgcolor =#C4D7F2" nowrap ="nowrap">路径< th bgcolor =#C4D7F2" nowrap ="nowrap">帐户/th.< th bgcolor =#C4D7F2" nowrap ="nowrap"类型.< th bgcolor =#C4D7F2" nowrap ="nowrap">目录所有者.< th bgcolor =#C4D7F2" nowrap ="nowrap">许可(简单).< th bgcolor =#C4D7F2" nowrap ="nowrap"应用于< th bgcolor =#C4D7F2" nowrap ="nowrap">继承的/th.< th bgcolor =#C4D7F2" nowrap ="nowrap">权限(高级).</tr>< tr bgcolor =#DDEEFF">< td valign ="top" nowrap ="nowrap"> \\ MYSERVER \ .FSG</td>< td valign ="top" nowrap ="nowrap"> BUILTIN \ Administrators</td>< td valign ="top" nowrap ="nowrap">允许/td.< td valign ="top" nowrap ="nowrap"> BUILTIN \ Administrators</td>< td valign ="top" nowrap ="nowrap">完全控制/td.< td valign ="top" nowrap ="nowrap">该文件夹,子文件夹和文件.< td valign ="top" nowrap ="nowrap"> False/td.< td valign ="top" nowrap ="nowrap">完全控制,遍历文件夹/执行文件,列出文件夹/读取数据,读取属性,读取扩展属性,创建文件/写入数据,创建文件夹/追加数据,写入属性,写入扩展属性,删除子文件夹和文件,删除,读取权限,更改权限,取得所有权</td></tr>< tr bgcolor =#DDEEFF">< td valign ="top" nowrap ="nowrap"> \\ MYSERVER \ .FSG</td>< td valign ="top" nowrap ="nowrap"> MYDOMAIN \ VL5101.XYZ/td.< td valign ="top" nowrap ="nowrap">允许/td.< td valign ="top" nowrap ="nowrap"> BUILTIN \ Administrators</td>< td valign ="top" nowrap ="nowrap">完全控制/td.< td valign ="top" nowrap ="nowrap">该文件夹,子文件夹和文件.< td valign ="top" nowrap ="nowrap"> False/td.< td valign ="top" nowrap ="nowrap">完全控制,遍历文件夹/执行文件,列出文件夹/读取数据,读取属性,读取扩展属性,创建文件/写入数据,创建文件夹/追加数据,写入属性,写入扩展属性,删除子文件夹和文件,删除,读取权限,更改权限,取得所有权</td></tr>< tr bgcolor =#DDEEFF">< td valign ="top" nowrap ="nowrap"> \\ MYSERVER \ .FSG</td>< td valign ="top" nowrap ="nowrap"> MYDOMAIN \ Domain Admins/td< td valign ="top" nowrap ="nowrap">允许/td.< td valign ="top" nowrap ="nowrap"> BUILTIN \ Administrators</td>< td valign ="top" nowrap ="nowrap">完全控制/td.< td valign ="top" nowrap ="nowrap">该文件夹,子文件夹和文件.< td valign ="top" nowrap ="nowrap"> False/td.< td valign ="top" nowrap ="nowrap">完全控制,遍历文件夹/执行文件,列出文件夹/读取数据,读取属性,读取扩展属性,创建文件/写入数据,创建文件夹/追加数据,写入属性,写入扩展属性,删除子文件夹和文件,删除,读取权限,更改权限,取得所有权</td></tr>< tr bgcolor =#DDEEFF">< td valign ="top" nowrap ="nowrap"> \\ MYSERVER \ .FSG</td>< td valign ="top" nowrap ="nowrap"> MYDOMAIN \ GD-SITE-MYSERVER-ACCESSADMIN-F/td.< td valign ="top" nowrap ="nowrap">允许/td.< td valign ="top" nowrap ="nowrap"> BUILTIN \ Administrators</td>< td valign ="top" nowrap ="nowrap">完全控制/td.< td valign ="top" nowrap ="nowrap">该文件夹,子文件夹和文件.< td valign ="top" nowrap ="nowrap"> False/td.< td valign ="top" nowrap ="nowrap">完全控制,遍历文件夹/执行文件,列出文件夹/读取数据,读取属性,读取扩展属性,创建文件/写入数据,创建文件夹/追加数据,写入属性,写入扩展属性,删除子文件夹和文件,删除,读取权限,更改权限,取得所有权</td></tr>< tr bgcolor =#DDEEFF">< td valign ="top" nowrap ="nowrap"> \\ MYSERVER \ .FSG</td>< td valign ="top" nowrap ="nowrap"> MYDOMAIN \ GD-SITE-MYSERVER-FILESHARE_G-L</td>< td valign ="top" nowrap ="nowrap">允许/td.< td valign ="top" nowrap ="nowrap"> BUILTIN \ Administrators</td>< td valign ="top" nowrap ="nowrap">列出文件夹内容</td>.< td valign ="top" nowrap ="nowrap">此文件夹和子文件夹</td>< td valign ="top" nowrap ="nowrap"> False/td.< td valign ="top" nowrap ="nowrap">遍历文件夹/执行文件,列表文件夹/读取数据,读取属性,读取扩展属性,读取权限.</tr>< tr>< td valign ="top" nowrap ="nowrap"> \\ MYSERVER \ .FSG</td>< td valign ="top" nowrap ="nowrap"> MYDOMAIN \ GD-SITE-MYSERVER-FILESHARE_G-L</td>< td valign ="top" nowrap ="nowrap">允许/td.< td valign ="top" nowrap ="nowrap"> BUILTIN \ Administrators</td>< td valign ="top" nowrap ="nowrap"> Read/td.< td valign ="top" nowrap ="nowrap">该文件夹,子文件夹和文件.< td valign ="top" nowrap ="nowrap"> False/td.< td valign ="top" nowrap ="nowrap">列出文件夹/读取数据,读取属性,读取扩展属性,读取权限.</tr>

<table cellpadding="1" class="sortable"><tr><th bgcolor="#C4D7F2" nowrap="nowrap">Path</th><th bgcolor="#C4D7F2" nowrap="nowrap">Account</th><th bgcolor="#C4D7F2" nowrap="nowrap">Type</th><th bgcolor="#C4D7F2" nowrap="nowrap">Directory Owner</th><th bgcolor="#C4D7F2" nowrap="nowrap">Permission (Simple)</th><th bgcolor="#C4D7F2" nowrap="nowrap">Apply To</th><th bgcolor="#C4D7F2" nowrap="nowrap">Inherited</th><th bgcolor="#C4D7F2" nowrap="nowrap">Permissions (Advanced)</th></tr><tr bgcolor="#DDEEFF"><td valign="top" nowrap="nowrap">\\MYSERVER\.FSG</td><td valign="top" nowrap="nowrap">BUILTIN\Administrators</td><td valign="top" nowrap="nowrap">Allow</td><td valign="top" nowrap="nowrap">BUILTIN\Administrators</td><td valign="top" nowrap="nowrap">Full Control</td><td valign="top" nowrap="nowrap">This folder, subfolders and files</td><td valign="top" nowrap="nowrap">False</td><td valign="top" nowrap="nowrap">Full Control, Traverse Folder / Execute File, List Folder / Read Data, Read Attributes, Read Extended Attributes, Create Files / Write Data, Create Folders / Append Data, Write Attributes, Write Extended Attributes, Delete Subfolders and Files, Delete, Read Permissions, Change Permissions, Take Ownership</td></tr><tr bgcolor="#DDEEFF"><td valign="top" nowrap="nowrap">\\MYSERVER\.FSG</td><td valign="top" nowrap="nowrap">MYDOMAIN\VL5101.XYZ</td><td valign="top" nowrap="nowrap">Allow</td><td valign="top" nowrap="nowrap">BUILTIN\Administrators</td><td valign="top" nowrap="nowrap">Full Control</td><td valign="top" nowrap="nowrap">This folder, subfolders and files</td><td valign="top" nowrap="nowrap">False</td><td valign="top" nowrap="nowrap">Full Control, Traverse Folder / Execute File, List Folder / Read Data, Read Attributes, Read Extended Attributes, Create Files / Write Data, Create Folders / Append Data, Write Attributes, Write Extended Attributes, Delete Subfolders and Files, Delete, Read Permissions, Change Permissions, Take Ownership</td></tr><tr bgcolor="#DDEEFF"><td valign="top" nowrap="nowrap">\\MYSERVER\.FSG</td><td valign="top" nowrap="nowrap">MYDOMAIN\Domain Admins</td><td valign="top" nowrap="nowrap">Allow</td><td valign="top" nowrap="nowrap">BUILTIN\Administrators</td><td valign="top" nowrap="nowrap">Full Control</td><td valign="top" nowrap="nowrap">This folder, subfolders and files</td><td valign="top" nowrap="nowrap">False</td><td valign="top" nowrap="nowrap">Full Control, Traverse Folder / Execute File, List Folder / Read Data, Read Attributes, Read Extended Attributes, Create Files / Write Data, Create Folders / Append Data, Write Attributes, Write Extended Attributes, Delete Subfolders and Files, Delete, Read Permissions, Change Permissions, Take Ownership</td></tr><tr bgcolor="#DDEEFF"><td valign="top" nowrap="nowrap">\\MYSERVER\.FSG</td><td valign="top" nowrap="nowrap">MYDOMAIN\GD-SITE-MYSERVER-ACCESSADMIN-F</td><td valign="top" nowrap="nowrap">Allow</td><td valign="top" nowrap="nowrap">BUILTIN\Administrators</td><td valign="top" nowrap="nowrap">Full Control</td><td valign="top" nowrap="nowrap">This folder, subfolders and files</td><td valign="top" nowrap="nowrap">False</td><td valign="top" nowrap="nowrap">Full Control, Traverse Folder / Execute File, List Folder / Read Data, Read Attributes, Read Extended Attributes, Create Files / Write Data, Create Folders / Append Data, Write Attributes, Write Extended Attributes, Delete Subfolders and Files, Delete, Read Permissions, Change Permissions, Take Ownership</td></tr><tr bgcolor="#DDEEFF"><td valign="top" nowrap="nowrap">\\MYSERVER\.FSG</td><td valign="top" nowrap="nowrap">MYDOMAIN\GD-SITE-MYSERVER-FILESHARE_G-L</td><td valign="top" nowrap="nowrap">Allow</td><td valign="top" nowrap="nowrap">BUILTIN\Administrators</td><td valign="top" nowrap="nowrap">List Folder Contents</td><td valign="top" nowrap="nowrap">This folder and subfolders</td><td valign="top" nowrap="nowrap">False</td><td valign="top" nowrap="nowrap">Traverse Folder / Execute File, List Folder / Read Data, Read Attributes, Read Extended Attributes, Read Permissions</td></tr><tr ><td valign="top" nowrap="nowrap">\\MYSERVER\.FSG</td><td valign="top" nowrap="nowrap">MYDOMAIN\GD-SITE-MYSERVER-FILESHARE_G-L</td><td valign="top" nowrap="nowrap">Allow</td><td valign="top" nowrap="nowrap">BUILTIN\Administrators</td><td valign="top" nowrap="nowrap">Read</td><td valign="top" nowrap="nowrap">This folder, subfolders and files</td><td valign="top" nowrap="nowrap">False</td><td valign="top" nowrap="nowrap">List Folder / Read Data, Read Attributes, Read Extended Attributes, Read Permissions</td></tr>


上帝保佑大家:)

推荐答案

string path = <YourXMLFilePath>;
List<TableData> lst = new List<TableData>();

XElement xml = XElement.Load(path);

var rows = xml.Descendants("tr")
        .Where(x => x.Element("td") != null)
        .Select(x => x);

foreach (var item in rows)
{
    var res = item.Descendants("td")
        .Select(x => x).ToList<XElement>();
    
    lst.Add(new TableData
    {
        Path = res[0].Value,
        Account = res[1].Value,
        Type = res[2].Value,
        DirectoryOwner = res[3].Value,
        PermissionsSimple = res[4].Value,
        ApplyTo = res[5].Value,
        PermissionsAdvanced = res[6].Value
    });
}

我使用了一个小型的TableData类,其中仅包含此处所需的那些属性.

I used a small class TableData with just those properties needed here.

public class TableData
{
    public string Path { get; set; }
    public string Account { get; set; }
    public string Type { get; set; }
    public string DirectoryOwner { get; set; }
    public string PermissionsSimple { get; set; }
    public string ApplyTo { get; set; }
    public string Inherited { get; set; }
    public string PermissionsAdvanced { get; set; }
}

希望


这篇关于XPath适用于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 17:45