簡體   English   中英

如何將屬性XML節點復制到指定的結構或數組

[英]how to copy attribute XML node to specified structure or array

例如,如何使用一個命令將屬性XML節點復制到指定的結構或數組

    public struct PossibilityJavamed
    {
        public string derv;
        public string dervt;
        public string num;
        public string gend;
    }
    PossibilityJavamed tmpstructnew = tmpstruct;
    ArrayList alstout = new ArrayList();// my array has some initial value 
    XmlNodeList nodeList;
    nodeList = docHarf.SelectNodes("//adatesmi");
            for (int i = 0; i < nodeList.Count; i++)
            {


                    tmpstructnew.derv = nodeList[i].Attributes["derv"].Value;
                    tmpstructnew.dervt = nodeList[i].Attributes["dervt"].Value;
                    tmpstructnew.num = nodeList[i].Attributes["num"].Value;
                    tmpstructnew.gend = nodeList[i].Attributes["gend"].Value;
                    alstout.Add(tmpstructnew);
            }

但我會在一個命令中完成

像這樣:

alstout.AddRange(docHarf.SelectNodes("//adatesmi")
    .Select(n => new PossibilityJavamed {
        derv  = n.Attributes["derv"].Value,
        dervt = n.Attributes["dervt"].Value,
        num   = n.Attributes["num"].Value,
        gend  = n.Attributes["gend"].Value
    }));
      alstout.AddRange(  (
                 from n in docHarf.SelectNodes("//adatesmi")
                 select new PossibilityJavamed(){
                    derv = n.Attributes["derv"].Value;
                    dervt = n.Attributes["dervt"].Value;
                    num = n.Attributes["num"].Value;
                    gend = n.Attributes["gend"].Value;
                 }
            ).ToList());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM