将Umbraco xpath从旧架构转换为新架构

时间:2011-11-27 22:10:31

标签: c# api xpath umbraco

我继承了一些旧代码,需要转换为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']更改为更新的架构。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

变化:

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());