我有一个包含XML标签的字符串,我将字符串值转换为XmlDocument
。
它有多个树节点,所以我想从字符串中删除最后一个节点。
string strvalue = Request.QueryString["Data"];
strvalue = "<menulist><requestId>1529866354</requestId><msisdn>918885473702</msisdn><starCode>600</starCode><keyWord>600DYN</keyWord><userData>*600#</userData><featureId>DYNAMIC_USSD_MENU</featureId><url1><![CDATA[http://216.198.200.36/USSD/receive.aspx]]></url1><dataSet><param><id>CIRCLEID</id><value>1</value></param></dataSet><timeStamp>2014/01/31 11:04:26</timeStamp></menulist><msisdn>918885473702</msisdn>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(strvalue);
//Get your nodes
XmlNodeList nodes = doc.DocumentElement.SelectNodes("//menulist");
//This will build your string
StringBuilder yourString = new StringBuilder();
yourString.Append("user details : ");
//Iterates through your String appending the available Names
foreach (XmlNode node in nodes)
{
yourString.Append(node["Name"].InnerText + ",");
}
//Variable for your final string (replaces the trailing comma with a period)
string result = yourString.Remove(yourString.Length - 1, 1).ToString() + ".";
Response.Write(result);