日期:2014-05-17  浏览次数:20844 次

如何读取一段标准xml格式的string,只需要里面几个节点属性值
<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<DATASETS><DATASET><PERSONUUID>d839c5642de540dc9750139ccc72a262</PERSONUUID><USERID>01363</USERID><ACCOUNT_TYPE>0</ACCOUNT_TYPE><FULL_NAME>姓名</FULL_NAME><ALIASNAME></ALIASNAME><PERSONCODE>12345</PERSONCODE><FIRSTNAME>名</FIRSTNAME><LASTNAME>姓</LASTNAME><IDNUM>430XXXXXXXXXXXXXXX</IDNUM><CARDTYPE>1</CARDTYPE><SEX>1</SEX><NATIONALITY>汉族</NATIONALITY><BIRTHDATE>1900-01-1</BIRTHDATE><NATIVE_PLACE>中国北京</NATIVE_PLACE><MARRIAGE>2</MARRIAGE><HOMETEL></HOMETEL><OFFICETEL>010-88888888</OFFICETEL><OFFICEFAX></OFFICEFAX><MOBILE>1398888888</MOBILE><EMAIL>xhh@msdi.cn</EMAIL><COUNTRY></COUNTRY><PROVINCE></PROVINCE><CITY></CITY><CONNECTADDR></CONNECTADDR><ZIP></ZIP><EDU></EDU><DEGREE>4</DEGREE><POLITICAL>3</POLITICAL><POSITION></POSITION><EXTENDED_ATTRIBUTES></EXTENDED_ATTRIBUTES></DATASET></DATASETS>

比如我只需要FULL_NAME PERSONCODE 如何弄

------解决方案--------------------
string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><DATASETS><DATASET><PERSONUUID>d839c5642de540dc9750139ccc72a262</PERSONUUID><USERID>01363</USERID><ACCOUNT_TYPE>0</ACCOUNT_TYPE><FULL_NAME>姓名</FULL_NAME><ALIASNAME></ALIASNAME><PERSONCODE>12345</PERSONCODE><FIRSTNAME>名</FIRSTNAME><LASTNAME>姓</LASTNAME><IDNUM>430XXXXXXXXXXXXXXX</IDNUM><CARDTYPE>1</CARDTYPE><SEX>1</SEX><NATIONALITY>汉族</NATIONALITY><BIRTHDATE>1900-01-1</BIRTHDATE><NATIVE_PLACE>中国北京</NATIVE_PLACE><MARRIAGE>2</MARRIAGE><HOMETEL></HOMETEL><OFFICETEL>010-88888888</OFFICETEL><OFFICEFAX></OFFICEFAX><MOBILE>1398888888</MOBILE><EMAIL>xhh@msdi.cn</EMAIL><COUNTRY></COUNTRY><PROVINCE></PROVINCE><CITY></CITY><CONNECTADDR></CONNECTADDR><ZIP></ZIP><EDU></EDU><DEGREE>4</DEGREE><POLITICAL>3</POLITICAL><POSITION></POSITION><EXTENDED_ATTRIBUTES></EXTENDED_ATTRIBUTES></DATASET></DATASETS>";
                XDocument xDoc = XDocument.Parse(xml);
                string FULL_NAME = xDoc.Root.Element("DATASET").Element("FULL_NAME").Value;//姓名
                string PERSONCODE = xDoc.Root.Element("DATASET").Element("PERSONCODE").Value;//12345

------解决方案--------------------

            string Info = "<?xml version=\"1.0\" encoding=\"U