开发者

how to copy attribute XML node to specified structure or array

how to copy attribute XML node to specified structure or array with one command for example

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

but i will do it in o开发者_如何学Pythonne command


Like this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜