zoukankan      html  css  js  c++  java
  • 怎么将XML字符串转换为XmlDocument,并获取部分节点值

    我们的目标:解析XML字符串,并获取节点:z:row下的属性:ows_LinkFilename的值集合???

    XML字符串数据结构如下:

    <listitems xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882' xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882' xmlns:rs='urn:schemas-microsoft-com:rowset' xmlns:z='#RowsetSchema' xmlns='http://schemas.microsoft.com/sharepoint/soap/'>
    <rs:data ItemCount='5'>
       <z:row ows_DocIcon='docx' ows_LinkFilename='RL-RYTG-V1.0-BZ.001_岗位说明书编制标准.docx' ows_Modified='2014-03-31 09:54:04' ows_Editor='7437;#(已离职)A-张强' ows_MetaInfo='6;#Subject:SW|远洋地产控股有限公司流程 Keywords:EW| _Status:EW| vti_parserversion:SR|12.0.0.6421 vti_modifiedby:SR|SINOOCEANLAND\v-zhangqiang vti_title:EW| _Author:SW|路平 _Category:EW| ContentType:EW| ContentTypeId:SW|0x0101006FC9BC54865EB7418119055CF0BD51C8 _Comments:EW| vti_author:SR|SINOOCEANLAND\v-zhangqiang ' ows__ModerationStatus='0' ows__Level='1' ows_Last_x0020_Modified='6;#2014-03-31 09:54:04' ows_ID='6' ows_owshiddenversion='1' ows_UniqueId='6;#{DF5527D4-F122-465D-B9F2-07887D317D9B}' ows_FSObjType='6;#0' ows_Created_x0020_Date='6;#2014-03-31 09:54:04' ows_ProgId='6;#' ows_FileLeafRef='6;#RL-RYTG-V1.0-BZ.001_岗位说明书编制标准.docx' ows_FileRef='6;#sites/ServiceBiz/Service25/4/1/RL-RYTG-V1.0-BZ.001_岗位说明书编制标准.docx' />
       <z:row ows_DocIcon='docx' ows_LinkFilename='RL-RYTG-V1.0-BZ.002_招聘方案设置和发布标准.docx' ows_Modified='2014-03-31 09:54:04' ows_Editor='7437;#(已离职)A-张强' ows_MetaInfo='7;#Subject:SW|远洋地产控股有限公司流程 Keywords:EW| _Status:EW| vti_parserversion:SR|12.0.0.6421 vti_modifiedby:SR|SINOOCEANLAND\v-zhangqiang vti_title:EW| _Author:EW| _Category:EW| ContentType:EW| ContentTypeId:SW|0x0101006FC9BC54865EB7418119055CF0BD51C8 _Comments:EW| vti_author:SR|SINOOCEANLAND\v-zhangqiang ' ows__ModerationStatus='0' ows__Level='1' ows_Last_x0020_Modified='7;#2014-03-31 09:54:05' ows_ID='7' ows_owshiddenversion='1' ows_UniqueId='7;#{94DFC367-99A6-4A64-8CB2-D398ECAB0CA7}' ows_FSObjType='7;#0' ows_Created_x0020_Date='7;#2014-03-31 09:54:05' ows_ProgId='7;#' ows_FileLeafRef='7;#RL-RYTG-V1.0-BZ.002_招聘方案设置和发布标准.docx' ows_FileRef='7;#sites/ServiceBiz/Service25/4/1/RL-RYTG-V1.0-BZ.002_招聘方案设置和发布标准.docx' />
       <z:row ows_DocIcon='docx' ows_LinkFilename='RL-RYTG-V1.0-BZ.003_录用管理标准.docx' ows_Modified='2014-03-31 09:54:04' ows_Editor='7437;#(已离职)A-张强' ows_MetaInfo='8;#Subject:SW|远洋地产控股有限公司流程 Keywords:EW| _Status:EW| vti_parserversion:SR|12.0.0.6421 vti_modifiedby:SR|SINOOCEANLAND\v-zhangqiang vti_title:EW| _Author:SW|路平 _Category:EW| ContentType:EW| ContentTypeId:SW|0x0101006FC9BC54865EB7418119055CF0BD51C8 _Comments:EW| vti_author:SR|SINOOCEANLAND\v-zhangqiang ' ows__ModerationStatus='0' ows__Level='1' ows_Last_x0020_Modified='8;#2014-03-31 09:54:05' ows_ID='8' ows_owshiddenversion='1' ows_UniqueId='8;#{1B24DB6A-47E0-4827-BAA9-EB2B3F3294C3}' ows_FSObjType='8;#0' ows_Created_x0020_Date='8;#2014-03-31 09:54:05' ows_ProgId='8;#' ows_FileLeafRef='8;#RL-RYTG-V1.0-BZ.003_录用管理标准.docx' ows_FileRef='8;#sites/ServiceBiz/Service25/4/1/RL-RYTG-V1.0-BZ.003_录用管理标准.docx' />
       <z:row ows_DocIcon='docx' ows_LinkFilename='RL-RYTG-V1.0-GF.001_内部应聘规范.docx' ows_Modified='2014-03-31 09:54:04' ows_Editor='7437;#(已离职)A-张强' ows_MetaInfo='9;#Subject:SW|远洋地产控股有限公司流程 Keywords:EW| _Status:EW| vti_parserversion:SR|12.0.0.6421 vti_modifiedby:SR|SINOOCEANLAND\v-zhangqiang vti_title:EW| _Author:EW| _Category:EW| ContentType:EW| ContentTypeId:SW|0x0101006FC9BC54865EB7418119055CF0BD51C8 _Comments:EW| vti_author:SR|SINOOCEANLAND\v-zhangqiang ' ows__ModerationStatus='0' ows__Level='1' ows_Last_x0020_Modified='9;#2014-03-31 09:54:05' ows_ID='9' ows_owshiddenversion='1' ows_UniqueId='9;#{BD7529F5-DAB2-4C35-9DEC-C8F83013336B}' ows_FSObjType='9;#0' ows_Created_x0020_Date='9;#2014-03-31 09:54:05' ows_ProgId='9;#' ows_FileLeafRef='9;#RL-RYTG-V1.0-GF.001_内部应聘规范.docx' ows_FileRef='9;#sites/ServiceBiz/Service25/4/1/RL-RYTG-V1.0-GF.001_内部应聘规范.docx' />
       <z:row ows_DocIcon='docx' ows_LinkFilename='RL-RYTG-V1.0-GF.002_内部推荐规范.docx' ows_Modified='2014-03-31 09:54:05' ows_Editor='7437;#(已离职)A-张强' ows_MetaInfo='10;#Subject:SW|远洋地产控股有限公司流程 Keywords:EW| _Status:EW| vti_parserversion:SR|12.0.0.6421 vti_modifiedby:SR|SINOOCEANLAND\v-zhangqiang vti_title:EW| _Author:EW| _Category:EW| ContentType:EW| ContentTypeId:SW|0x0101006FC9BC54865EB7418119055CF0BD51C8 _Comments:EW| vti_author:SR|SINOOCEANLAND\v-zhangqiang ' ows__ModerationStatus='0' ows__Level='1' ows_Last_x0020_Modified='10;#2014-03-31 09:54:05' ows_ID='10' ows_owshiddenversion='1' ows_UniqueId='10;#{9B2ECE9E-4544-476C-BD32-7182CBBF49FE}' ows_FSObjType='10;#0' ows_Created_x0020_Date='10;#2014-03-31 09:54:05' ows_ProgId='10;#' ows_FileLeafRef='10;#RL-RYTG-V1.0-GF.002_内部推荐规范.docx' ows_FileRef='10;#sites/ServiceBiz/Service25/4/1/RL-RYTG-V1.0-GF.002_内部推荐规范.docx' />
    </rs:data>
    </listitems>

    C#代码如下:

    string xmlStr = "<listitems xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882' xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882' xmlns:rs='urn:schemas-microsoft-com:rowset' xmlns:z='#RowsetSchema' xmlns='http://schemas.microsoft.com/sharepoint/soap/'>";
                xmlStr += "<rs:data ItemCount='5'>";
                xmlStr += "<z:row ows_DocIcon='docx' ows_LinkFilename='RL-RYTG-V1.0-BZ.001_岗位说明书编制标准.docx' ows_Modified='2014-03-31 09:54:04' ows_Editor='7437;#(已离职)A-张强' ows_MetaInfo='6;#Subject:SW|远洋地产控股有限公司流程 Keywords:EW| _Status:EW| vti_parserversion:SR|12.0.0.6421 vti_modifiedby:SR|SINOOCEANLAND\v-zhangqiang vti_title:EW| _Author:SW|路平 _Category:EW| ContentType:EW| ContentTypeId:SW|0x0101006FC9BC54865EB7418119055CF0BD51C8 _Comments:EW| vti_author:SR|SINOOCEANLAND\v-zhangqiang ' ows__ModerationStatus='0' ows__Level='1' ows_Last_x0020_Modified='6;#2014-03-31 09:54:04' ows_ID='6' ows_owshiddenversion='1' ows_UniqueId='6;#{DF5527D4-F122-465D-B9F2-07887D317D9B}' ows_FSObjType='6;#0' ows_Created_x0020_Date='6;#2014-03-31 09:54:04' ows_ProgId='6;#' ows_FileLeafRef='6;#RL-RYTG-V1.0-BZ.001_岗位说明书编制标准.docx' ows_FileRef='6;#sites/ServiceBiz/Service25/4/1/RL-RYTG-V1.0-BZ.001_岗位说明书编制标准.docx' />";
                xmlStr += "<z:row ows_DocIcon='docx' ows_LinkFilename='RL-RYTG-V1.0-BZ.002_招聘方案设置和发布标准.docx' ows_Modified='2014-03-31 09:54:04' ows_Editor='7437;#(已离职)A-张强' ows_MetaInfo='7;#Subject:SW|远洋地产控股有限公司流程 Keywords:EW| _Status:EW| vti_parserversion:SR|12.0.0.6421 vti_modifiedby:SR|SINOOCEANLAND\v-zhangqiang vti_title:EW| _Author:EW| _Category:EW| ContentType:EW| ContentTypeId:SW|0x0101006FC9BC54865EB7418119055CF0BD51C8 _Comments:EW| vti_author:SR|SINOOCEANLAND\v-zhangqiang ' ows__ModerationStatus='0' ows__Level='1' ows_Last_x0020_Modified='7;#2014-03-31 09:54:05' ows_ID='7' ows_owshiddenversion='1' ows_UniqueId='7;#{94DFC367-99A6-4A64-8CB2-D398ECAB0CA7}' ows_FSObjType='7;#0' ows_Created_x0020_Date='7;#2014-03-31 09:54:05' ows_ProgId='7;#' ows_FileLeafRef='7;#RL-RYTG-V1.0-BZ.002_招聘方案设置和发布标准.docx' ows_FileRef='7;#sites/ServiceBiz/Service25/4/1/RL-RYTG-V1.0-BZ.002_招聘方案设置和发布标准.docx' />";
                xmlStr += "<z:row ows_DocIcon='docx' ows_LinkFilename='RL-RYTG-V1.0-BZ.003_录用管理标准.docx' ows_Modified='2014-03-31 09:54:04' ows_Editor='7437;#(已离职)A-张强' ows_MetaInfo='8;#Subject:SW|远洋地产控股有限公司流程 Keywords:EW| _Status:EW| vti_parserversion:SR|12.0.0.6421 vti_modifiedby:SR|SINOOCEANLAND\v-zhangqiang vti_title:EW| _Author:SW|路平 _Category:EW| ContentType:EW| ContentTypeId:SW|0x0101006FC9BC54865EB7418119055CF0BD51C8 _Comments:EW| vti_author:SR|SINOOCEANLAND\v-zhangqiang ' ows__ModerationStatus='0' ows__Level='1' ows_Last_x0020_Modified='8;#2014-03-31 09:54:05' ows_ID='8' ows_owshiddenversion='1' ows_UniqueId='8;#{1B24DB6A-47E0-4827-BAA9-EB2B3F3294C3}' ows_FSObjType='8;#0' ows_Created_x0020_Date='8;#2014-03-31 09:54:05' ows_ProgId='8;#' ows_FileLeafRef='8;#RL-RYTG-V1.0-BZ.003_录用管理标准.docx' ows_FileRef='8;#sites/ServiceBiz/Service25/4/1/RL-RYTG-V1.0-BZ.003_录用管理标准.docx' />";
                xmlStr += "<z:row ows_DocIcon='docx' ows_LinkFilename='RL-RYTG-V1.0-GF.001_内部应聘规范.docx' ows_Modified='2014-03-31 09:54:04' ows_Editor='7437;#(已离职)A-张强' ows_MetaInfo='9;#Subject:SW|远洋地产控股有限公司流程 Keywords:EW| _Status:EW| vti_parserversion:SR|12.0.0.6421 vti_modifiedby:SR|SINOOCEANLAND\v-zhangqiang vti_title:EW| _Author:EW| _Category:EW| ContentType:EW| ContentTypeId:SW|0x0101006FC9BC54865EB7418119055CF0BD51C8 _Comments:EW| vti_author:SR|SINOOCEANLAND\v-zhangqiang ' ows__ModerationStatus='0' ows__Level='1' ows_Last_x0020_Modified='9;#2014-03-31 09:54:05' ows_ID='9' ows_owshiddenversion='1' ows_UniqueId='9;#{BD7529F5-DAB2-4C35-9DEC-C8F83013336B}' ows_FSObjType='9;#0' ows_Created_x0020_Date='9;#2014-03-31 09:54:05' ows_ProgId='9;#' ows_FileLeafRef='9;#RL-RYTG-V1.0-GF.001_内部应聘规范.docx' ows_FileRef='9;#sites/ServiceBiz/Service25/4/1/RL-RYTG-V1.0-GF.001_内部应聘规范.docx' />";
                xmlStr += "<z:row ows_DocIcon='docx' ows_LinkFilename='RL-RYTG-V1.0-GF.002_内部推荐规范.docx' ows_Modified='2014-03-31 09:54:05' ows_Editor='7437;#(已离职)A-张强' ows_MetaInfo='10;#Subject:SW|远洋地产控股有限公司流程 Keywords:EW| _Status:EW| vti_parserversion:SR|12.0.0.6421 vti_modifiedby:SR|SINOOCEANLAND\v-zhangqiang vti_title:EW| _Author:EW| _Category:EW| ContentType:EW| ContentTypeId:SW|0x0101006FC9BC54865EB7418119055CF0BD51C8 _Comments:EW| vti_author:SR|SINOOCEANLAND\v-zhangqiang ' ows__ModerationStatus='0' ows__Level='1' ows_Last_x0020_Modified='10;#2014-03-31 09:54:05' ows_ID='10' ows_owshiddenversion='1' ows_UniqueId='10;#{9B2ECE9E-4544-476C-BD32-7182CBBF49FE}' ows_FSObjType='10;#0' ows_Created_x0020_Date='10;#2014-03-31 09:54:05' ows_ProgId='10;#' ows_FileLeafRef='10;#RL-RYTG-V1.0-GF.002_内部推荐规范.docx' ows_FileRef='10;#sites/ServiceBiz/Service25/4/1/RL-RYTG-V1.0-GF.002_内部推荐规范.docx' />";
                xmlStr += "</rs:data>";
                xmlStr += "</listitems>";
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.LoadXml(xmlStr);
                XmlNodeList listitemsNodeList = xmlDocument.GetElementsByTagName("rs:data");
                XmlNodeList dataNodeList = listitemsNodeList[0].ChildNodes;
                List<string> result = new List<string>();
                foreach (XmlNode node in dataNodeList)
                {
                    string fileName = node.Attributes["ows_LinkFilename"].Value;
                    result.Add(fileName);
                }
                result.ForEach(re =>
                {
                    Console.WriteLine(re);
                });
                Console.ReadLine();

    结果图如下:

    总结关键知识点:

    1-如何将XML字符串转换为XmlDocdument:

      XmlDocument xmlDocument = new XmlDocument();

      xmlDocument.LoadXml(xmlStr);

    2-获取XmlDoment下的节点:

      xmlDocument.GetElementsByTagName("rs:data")

    3-获取XmlNode下的属性值:

      node.Attributes["ows_LinkFilename"].Value

     
  • 相关阅读:
    SharePoint 2013 商务智能报表发布
    sharepoint designer web 服务器似乎没有安装microsoft sharepoint foundation
    SharePoint 2013 Designer系列之数据视图
    SharePoint 2013 Designer系列之数据视图筛选
    SharePoint 2013 Designer系列之自定义列表表单
    SharePoint 2013 入门教程之创建及修改母版页
    SharePoint 2013 入门教程之创建页面布局及页面
    SharePoint 2010 级联下拉列表 (Cascading DropDownList)
    使用SharePoint Designer定制开发专家库系统实例!
    PL/SQL Developer 建立远程连接数据库的配置 和安装包+汉化包+注册机
  • 原文地址:https://www.cnblogs.com/lxhbky/p/6872446.html
Copyright © 2011-2022 走看看