将Umbraco xpath从旧模式转换为新模式

本文关键字:模式 新模式 转换 xpath Umbraco | 更新日期: 2023-09-27 18:15:59

我继承了一些旧代码,需要在Umbraco API中转换为最新的模式。

private void GenerateDDL()
{
    int currentId = Int32.Parse(umbraco.library.GetXmlNodeCurrent().Current.SelectSingleNode("@id").Value);
    string xpath = string.Format("//node[@id={0}]/descendant::node[@nodeTypeAlias='FormDropdownOption']", currentId);
    XPathNodeIterator xml = umbraco.library.GetXmlNodeByXPath(xpath);
    while (xml.MoveNext())
    {
        //hsEmailList.Add(xml.Current.SelectSingleNode("./data[@alias='Text']").Value.ToString(), xml.Current.SelectSingleNode("./data[@alias='Value']").Value.ToString());
        hsEmailList.Add(xml.Current.SelectSingleNode("Text").Value.ToString(), xml.Current.SelectSingleNode("Value").Value.ToString());
    }
    foreach (DictionaryEntry de in hsEmailList)
    {
        ListItem list = new ListItem();
        list.Text = de.Key.ToString();
        list.Value = de.Value.ToString();
        ddlMemberName.Items.Add(list);
    }
}

我需要从注释的代码中改变它的状态。/data[@alias='Text']到较新的模式。有什么想法吗?

将Umbraco xpath从旧模式转换为新模式

变化:

hsEmailList.Add(xml.Current.SelectSingleNode("./data[@alias='Text']").Value.ToString(), xml.Current.SelectSingleNode("./data[@alias='Value']").Value.ToString());

:

hsEmailList.Add(xml.Current.SelectSingleNode("./Text").Value.ToString(), xml.Current.SelectSingleNode("./Value").Value.ToString());