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

关于XML在.net中的小问题
如何将XML中的
<NewDataSet>
  <a>
    <exam_uid>145</exam_uid>
    <exam_name>外国文学测试题</exam_name>
    <exam_descp>外国文学测试题</exam_descp>
    <customerid>22342</customerid>
    <all_level>5</all_level>
    <status>10</status>
    <tag1>chinese</tag1>
    <subject_name>语文</subject_name>
    <subject_lev>2</subject_lev>
    <subject_idx>2</subject_idx>
    <number>30</number>
    <subject_no>00010001</subject_no>
    <all_q>30</all_q>
    <fullname>在线客服九</fullname>
  </a>
  <a>

弄成 string xml="<root><row exam_uid=145/><row exam_name='外国文学测试' />......</root>";

------解决方案--------------------
笨方法:自己对XML进行读取 遍历 然后拼接成你想要的字符串格式。
------解决方案--------------------
private static void Test()
        {
            string xmlStr = @"<a>
    <exam_uid>145</exam_uid>
    <exam_name>外国文学测试题</exam_name>
    <exam_descp>外国文学测试题</exam_descp>
    <customerid>22342</customerid>
    <all_level>5</all_level>
    <status>10</status>
    <tag1>chinese</tag1>
    <subject_name>语文</subject_name>
    <subject_lev>2</subject_lev>
    <subject_idx>2</subject_idx>
    <number>30</number>
    <subject_no>00010001</subject_no>
    <all_q>30</all_q>
    <fullname>在线客服九</fullname>
  </a>";
            var doc = new XmlDocument();
            doc.LoadXml(xmlStr);

            if (!doc.HasChildNodes) return;

            foreach (XmlNode n in doc.ChildNodes)
            {
                if (n.Name == "a" && n.HasChildNodes)
                {
                    string temp = string.Empty;
                    foreach (XmlNode na in n.ChildNodes)
            &