How to convert an XML string to XmlDocument and obtain some node values, xmlxmldocument

Source: Internet
Author: User

How to convert an XML string to XmlDocument and obtain some node values, xmlxmldocument

Our goal is to parse the XML string and get the value set of ows_LinkFilename under node: z: row ???

 

The XML string data structure is as follows:

<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' comment 'ows_modified = '2017-03-31 09:54:04' ows_Editor = '2017; # (resigned) A-Zhangqiang 'ows_metainfo = '6; # Subject: SW | process Keywords: EW of Cosco Real Estate Holdings Ltd. | _ Status: EW | vti_parserversion: SR | 12.0.0.6421 vti_modifiedby: SR | SINOOCEANLAND \ v-zhangqiang vti_title: EW | _ Author: SW | Lupin _ Category: EW | ContentType: EW | ContentTypeId: SW | comment _ Comments: EW | vti_author: SR | SINOOCEANLAND \ v-zhangqiang 'oss _ ModerationStatus = '0' OSS _ 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; # 'hangzhou' ows_FileRef = '6; # sites/ServiceBiz/Service25/4/1/rl-rytg v1.0-bz.001_job description writing standard .docx '/> <z: row ows_DocIcon = 'docx' comment 'ows_modified = '2017-03-31 09:54:04 'ows_Editor = '2017; # (resigned) A-Zhangqiang' ows_MetaInfo = '7; # Subject: SW | process 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 'oss _ ModerationStatus = '0' OSS _ Level = '1' ows_Last_x0020_Modified = '7; #09:54:05 'ows_id = '7' ows_owshiddenversion = '1' ows_UniqueId = '7; # {region} 'ows_fsobjtype = '7; # 0' ows_Created_x0020_Date = '7; #09:54:05 'ows_progid = '7; # 'hangzhou' ows_FileRef = '7; # sites/ServiceBiz/Service25/4/1/rl-rytg v1.0-bz.002_recruitment proposal and standards .docx '/> <z: row ows_DocIcon = 'docx' comment 'ows_modified = '2017-03-31 09:54:04 'ows_Editor = '2017; # (resigned) A-Zhangqiang' ows_MetaInfo = '8; # Subject: SW | process Keywords: EW | _ Status: EW | vti_parserversion: SR | 12.0.0.6421 vti_modifiedby: SR | SINOOCEANLAND \ v-zhangqiang vti_title: EW | _ Author: SW | lupidcategory: EW | ContentType: EW | ContentTypeId: SW | 0x0101006FC9BC54865EB7418119055CF0BD51C8 _ Comments: EW | vti_author: SR | SINOOCEANLAND \ v-zhangqiang 'oss _ ModerationStatus = '0' OSS _ Level = '1' ows_Last_x0020_Modified = '8; #09:54:05 'ows_id = '8' ows_owshiddenversion = '1' ows_UniqueId = '8; # {region} 'ows_fsobjtype = '8; # 0' ows_Created_x0020_Date = '8; #09:54:05 'ows_progid = '8; # 'hangzhou' ows_FileRef = '8; # sites/ServiceBiz/Service25/4/1/rl-rytg v1.0-bz.003_recording Management Standard .docx'/> <z: row ows_DocIcon = 'docx' comment 'ows_modified = '2017-03-31 09:54:04 'ows_Editor = '2017; # (resigned) A-Zhangqiang' ows_MetaInfo = '9; # Subject: SW | process 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 'oss _ ModerationStatus = '0' OSS _ 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; #09:54:05 'ows_progid = '9; # 'hangzhou' ows_FileRef = '9; # Inner candidates for sites/ServiceBiz/Service25/4/1/rl-rytg v1.0-gf.00133. docx '/> <z: row ows_DocIcon = 'docx' comment 'ows_modified = '2017-03-31 09:54:05 'ows_Editor = '2017; # (resigned) A-Zhangqiang' ows_MetaInfo = '10; # Subject: SW | process 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 'oss _ ModerationStatus = '0' OSS _ Level = '1' ows_Last_x0020_Modified = '10; #09:54:05 'ows_id = '10' ows_owshiddenversion = '1' ows_UniqueId = '10; # {region} 'ows_fsobjtype = '10; # 0' ows_Created_x0020_Date = '10; #2014-03-31 09:54:05 'ows_progid = '10; # 'hangzhou' ows_FileRef = '10; # sites/ServiceBiz/Service25/4/1/rl-rytg v1.0-gf.002_internal recommendation mongo.docx '/> </rs: data> </listitems>

C # The Code is as follows:

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' comment 'ows_modified = '2017-03-31 09:54:04 'ows_Editor = '2017; # (resigned) A-Zhangqiang' ows_MetaInfo = '6; # Subject: SW | process Keywords: EW | _ Status: EW | vti_parserversion: SR | 12.0.0.6421 vti_modifiedby: SR | SINOOCEANLAND \ v-zhangqiang vti_title: EW | _ Author: SW | lupidcategory: EW | ContentType: EW | ContentTypeId: SW | 0x0101006FC9BC54865EB7418119055CF0BD51C8 _ Comments: EW | vti_author: SR | SINOOCEANLAND \ v-zhangqiang 'oss _ ModerationStatus = '0' OSS _ 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; #09:54:04 'ows_progid = '6; # 'hangzhou' ows_FileRef = '6; # sites/ServiceBiz/Service25/4/1/hangzhou'/> "; xmlStr + =" <z: row ows_DocIcon = 'docx' comment 'ows_modified = '2017-03-31 09:54:04 'ows_Editor = '2017; # (resigned) A-Zhangqiang' ows_MetaInfo = '7; # Subject: SW | process 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 'oss _ ModerationStatus = '0' OSS _ Level = '1' ows_Last_x0020_Modified = '7; #09:54:05 'ows_id = '7' ows_owshiddenversion = '1' ows_UniqueId = '7; # {region} 'ows_fsobjtype = '7; # 0' ows_Created_x0020_Date = '7; #09:54:05 'ows_progid = '7; # 'hangzhou' ows_FileRef = '7; # sites/ServiceBiz/Service25/4/1/hangzhou'/> "; xmlStr + =" <z: row ows_DocIcon = 'docx' comment 'ows_modified = '2017-03-31 09:54:04 'ows_Editor = '2017; # (resigned) A-Zhangqiang' ows_MetaInfo = '8; # Subject: SW | process Keywords: EW | _ Status: EW | vti_parserversion: SR | 12.0.0.6421 vti_modifiedby: SR | SINOOCEANLAND \ v-zhangqiang vti_title: EW | _ Author: SW | lupidcategory: EW | ContentType: EW | ContentTypeId: SW | 0x0101006FC9BC54865EB7418119055CF0BD51C8 _ Comments: EW | vti_author: SR | SINOOCEANLAND \ v-zhangqiang 'oss _ ModerationStatus = '0' OSS _ Level = '1' ows_Last_x0020_Modified = '8; #09:54:05 'ows_id = '8' ows_owshiddenversion = '1' ows_UniqueId = '8; # {region} 'ows_fsobjtype = '8; # 0' ows_Created_x0020_Date = '8; #09:54:05 'ows_progid = '8; # 'hangzhou' ows_FileRef = '8; # sites/ServiceBiz/Service25/4/1/hangzhou'/> "; xmlStr + =" <z: row ows_DocIcon = 'docx' comment 'ows_modified = '2017-03-31 09:54:04 'ows_Editor = '2017; # (resigned) A-Zhangqiang' ows_MetaInfo = '9; # Subject: SW | process 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 'oss _ ModerationStatus = '0' OSS _ 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; #09:54:05 'ows_progid = '9; # 'hangzhou' ows_FileRef = '9; # sites/ServiceBiz/Service25/4/1/hangzhou'/> "; xmlStr + =" <z: row ows_DocIcon = 'docx' comment 'ows_modified = '2017-03-31 09:54:05 'ows_Editor = '2017; # (resigned) A-Zhangqiang' ows_MetaInfo = '10; # Subject: SW | process 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 'oss _ ModerationStatus = '0' OSS _ Level = '1' ows_Last_x0020_Modified = '10; #09:54:05 'ows_id = '10' ows_owshiddenversion = '1' ows_UniqueId = '10; # {region} 'ows_fsobjtype = '10; # 0' ows_Created_x0020_Date = '10; #2014-03-31 09:54:05 'ows_progid = '10; # 'hangzhou' ows_FileRef = '10; # sites/ServiceBiz/Service25/4/1/rl-rytg v1.0-gf.002_internal recommendation mongo.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 ();

The result is as follows:

 

Summarize key knowledge points:

1-how to convert an XML string to XmlDocdument:

XmlDocument xmlDocument = new XmlDocument ();

XmlDocument. LoadXml (xmlStr );

2-get nodes under XmlDoment:

XmlDocument. GetElementsByTagName ("rs: data ")

3-get the attribute values under XmlNode:

  Node. Attributes ["ows_LinkFilename"]. Value

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.