日期:2014-05-17  浏览次数:20499 次

求大神解答下怎么把XML节点元素的值赋值给lab标签
C# code

返回结果的方法
 private static string GetExceptionPoint(XmlNode node)
    {
        XmlDocument xmldoc = new XmlDocument();
        XmlElement root = xmldoc.CreateElement("root");
        XmlElement el;
        for (int i = 0; i < node.ChildNodes.Count; i++)
        {
            el = xmldoc.CreateElement("item");
            el.SetAttribute("label", GetLabelName(node.ChildNodes[i].Attributes["label"].Value)//调用下面的方法);
            if (node.ChildNodes[i].Attributes["outside"] != null) el.SetAttribute("val", "超厚");
            else el.SetAttribute("val", node.ChildNodes[i].Attributes["val"].Value.Split(',')[0]);
            root.AppendChild(el);
        }
        return root.InnerXml;
    }

//重新设置节点的名称和值
 private static string GetLabelName(string str)
    {
        string[] labs = "L,M,D,LA,E,LB,F,LC,G,H,I,RC,J,RB,K,RA,N".Split(',');
        string[] names = "右前翼子板,引擎盖,左前翼子板,左A柱,左前门,左B柱,左后门,左C柱,左后翼子板,行李箱盖,右后翼子板,右C柱,右后门,右B柱,右前门,右A柱,车顶".Split(',');
        for (int i = 0; i < labs.Length; i++)
        {
            if (str == labs[i]) return names[i];
        }
        return "";
    }



现在我在外面定义了一个字符串变量 来接受上面返回的 root.InnerXml(还有更好的办法么?),如下:
 string jzd = GetExceptionPoint(root["fg"]);

问题来了,现在我不知道怎么把这里面的值一一取出来赋值给lab标签了,我要的结果如下;


C# code

    <p class="name"><span class="dance">右前翼子板:</span><span>[color=#FF0000]lab[/color]</span></p><br />
        <p class="name"><span class="dance">引擎盖:</span><span>[color=#FF0000]lab[/color]</span></p><br />
     <p class="name"><span class="dance">左前翼子板:</span><span>lab</span></p><br />
      <p class="name"><span class="dance">左A柱:</span><span>lab</span></p><br />
    <p class="name"><span class="dance">左前门:</span><span>lab</span></p><br />
    <p class="name"><span class="dance">左B柱:</span><span>lab</span></p><br />
    <p class="name"><span class="dance">左后门:</span><span>lab</span></p><br />
     <p class="name"><span class="dance">左C柱:</span><span>lab</span></p><br />
      <p class="name"><span class="dance">左后翼子板:</span><span>lab</span></p><br />
   <p class="name"><span class="dance">行李箱盖:</span><span>lab</span></p><br />
   <p class="name"><span class="dance">右后翼盖子板:</span><span>lab</span></p><br />
   <p class="name"><span class="dance">右C柱:</span><span>95</span></p><br />
     <p class="name"><span class="dance">右后门:</span><span>95</span></p><br />
     <p class="name"><span class="dance">左B柱:</span><span>95</span></p><br />
     <p class="name"><span class="dance">右前门:</span><span>95</span></p><br />
      <p class="name"><span class="dance">右A柱:</span><