[英]Extracting values from xml using xpath based on a condition
我正在使用xpath解析並從xml文件獲取屬性值。
這是我的xpath表達式
./result/object/group[@mode = 'invalid']
xpath生成
<group mode="invalid" name="3"/>
<group mode="invalid" name="4"/>
我想進一步解析和獲取名稱的詳細信息,就像
name="3"
name="4"
要不就
"3"
"4"
我不確定如何根據條件繼續進行。
您可以使用GetAttribute
方法獲取“名稱”。 例如,在您的情況下:
string name = driver.FindElement(By.Xpath("./result/object/group[@mode = 'invalid']")).GetAttribute("name");
我設法使用./result/object/group[@mode ='invalid'] / @ name完成操作以獲取名稱值。 我使用以下方法獲取名稱的值
XmlNodeList xmlNodeList = xmlDoc.SelectNodes("./result/object/group[@mode = \'invalid\']/@name");
foreach (XmlAttribute node in xmlNodeList)
{
Console.WriteLine(node.Value);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.