开发者

how to copy attribute XML node to specified structure or array

开发者 https://www.devze.com 2022-12-25 08:50 出处:网络
how to copy attributeXML node to specifiedstructureor array with one command for example public struct PossibilityJavamed

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

精彩评论

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