110,560
社区成员
发帖
与我相关
我的任务
分享
XmlNode child = null;
alliedXmlDocument = new XmlDocument();
alliedXmlDocument.LoadXml(xmlStr);
child = alliedXmlDocument.SelectSingleNode(/html/body/...路径);
if (child != null)
{
WebOrderHeaderEntity.FromGlobalPartnerRoleClassificationCode = PunchoutHelper.GetXMLChildValue(child);
}
/// <summary>
/// Get XML Child Value
/// </summary>
/// <param name="child">xml child node</param>
/// <returns>child node value</returns>
public static string GetXMLChildValue(XmlNode child)
{
if (child != null)
{
XmlNodeReader nr = new XmlNodeReader(child);
while (nr.Read())
{
if (nr.HasValue == true)
{
return nr.Value;
}
}
}
return null;
}
//可以用正则:
using System.Text.RegularExpressions;
Regex reg=new Regex("(?<=<td>[\s\S]*(?=</td>)");
string result=string.Empty;
string html="你的网页代码";
foreach(Match m in reg.Matchs(html))
{
result+=m.Value+"\r\n";
}
或者:
string result=Regex.Replace(html,"<[^>]*>","").Trim();