| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5960 人关注过本帖
标题:XML Linq 读取时的问题!
只看楼主 加入收藏
kevintang
Rank: 4
等 级:业余侠客
威 望:9
帖 子:799
专家分:236
注 册:2008-2-14
结帖率:80%
收藏
 问题点数:0 回复次数:2 
XML Linq 读取时的问题!
<?xml version="1.0" encoding="ISO-8859-1"?>
<response version="1.0" transactional="N">
  <result seqno="1">
    <query entityName="timeSheet" seqno="1">
      <spec logicalOperation="OR">
        <fieldSpec comparisonOperation="equal" name="personKey"
                    value="153"></fieldSpec>
        <fieldSpec comparisonOperation="equal" name="personKey"
                    value="133"></fieldSpec>
      </spec>
    </query>
    <collection>
      <timeSheet>
        <code>1</code>
        <timePeriodKey>100</timePeriodKey>
        <beginDate>01-Jan-2010 12:00 AM GMT+08:00</beginDate>
        <personKey>133</personKey>
        <controllerKey></controllerKey>
        <dateCompleted>11-Nov-2010 05:34 PM GMT+08:00</dateCompleted>
        <status>COMPLETED</status>
        <comments>2010-1-1</comments>
        <periodSeqKey>1</periodSeqKey>
        <prevTimesheet>0</prevTimesheet>
        <nextTimesheet>0</nextTimesheet>
        <replaceChildren>N</replaceChildren>
        <totalHours>4</totalHours>
        <timeslip>
          <code>13</code>
          <personTimeKey>1</personTimeKey>
          <projectKey>44</projectKey>
          <taskKey></taskKey>
          <workDate>04-Jan-2010 12:00 AM GMT+08:00</workDate>
          <quantity>1.00</quantity>
          <billRate>10000</billRate>
          <costRate>8000</costRate>
          <staffRoleKey>10</staffRoleKey>
          <comments>test1</comments>
          <activityTypeKey>20</activityTypeKey>
          <projectName>LYS_0001</projectName>
          <taskName></taskName>
          <staffRoleName>PM</staffRoleName>
          <activityTypeName>*Billable</activityTypeName>
          <isAssignedToProject>Y</isAssignedToProject>
          <billRateCurrencyCode>USD</billRateCurrencyCode>
          <costRateCurrencyCode>USD</costRateCurrencyCode>
          <clientKey>62</clientKey>
          <locationKey>0</locationKey>
          <locationName>Unassigned</locationName>
          <rowNumber></rowNumber>
        </timeslip>
        <timeslip>
          <code>14</code>
          <personTimeKey>1</personTimeKey>
          <projectKey>44</projectKey>
          <taskKey></taskKey>
          <workDate>05-Jan-2010 12:00 AM GMT+08:00</workDate>
          <quantity>2.00</quantity>
          <billRate>10000</billRate>
          <costRate>8000</costRate>
          <staffRoleKey>10</staffRoleKey>
          <comments>test2</comments>
          <activityTypeKey>20</activityTypeKey>
          <projectName>LYS_0001</projectName>
          <taskName></taskName>
          <staffRoleName>PM</staffRoleName>
          <activityTypeName>*Billable</activityTypeName>
          <isAssignedToProject>Y</isAssignedToProject>
          <billRateCurrencyCode>USD</billRateCurrencyCode>
          <costRateCurrencyCode>USD</costRateCurrencyCode>
          <clientKey>62</clientKey>
          <locationKey>0</locationKey>
          <locationName>Unassigned</locationName>
          <rowNumber></rowNumber>
        </timeslip>
        <timeslip>
          <code>15</code>
          <personTimeKey>1</personTimeKey>
          <projectKey>44</projectKey>
          <taskKey></taskKey>
          <workDate>06-Jan-2010 12:00 AM GMT+08:00</workDate>
          <quantity>-3.00</quantity>
          <billRate>10000</billRate>
          <costRate>8000</costRate>
          <staffRoleKey>10</staffRoleKey>
          <comments>test3 minus</comments>
          <activityTypeKey>20</activityTypeKey>
          <projectName>LYS_0001</projectName>
          <taskName></taskName>
          <staffRoleName>PM</staffRoleName>
          <activityTypeName>*Billable</activityTypeName>
          <isAssignedToProject>Y</isAssignedToProject>
          <billRateCurrencyCode>USD</billRateCurrencyCode>
          <costRateCurrencyCode>USD</costRateCurrencyCode>
          <clientKey>62</clientKey>
          <locationKey>0</locationKey>
          <locationName>Unassigned</locationName>
          <rowNumber></rowNumber>
        </timeslip>
        <timeslip>
          <code>16</code>
          <personTimeKey>1</personTimeKey>
          <projectKey>44</projectKey>
          <taskKey></taskKey>
          <workDate>07-Jan-2010 12:00 AM GMT+08:00</workDate>
          <quantity>4.00</quantity>
          <billRate>10000</billRate>
          <costRate>8000</costRate>
          <staffRoleKey>10</staffRoleKey>
          <comments>test4</comments>
          <activityTypeKey>20</activityTypeKey>
          <projectName>LYS_0001</projectName>
          <taskName></taskName>
          <staffRoleName>PM</staffRoleName>
          <activityTypeName>*Billable</activityTypeName>
          <isAssignedToProject>Y</isAssignedToProject>
          <billRateCurrencyCode>USD</billRateCurrencyCode>
          <costRateCurrencyCode>USD</costRateCurrencyCode>
          <clientKey>62</clientKey>
          <locationKey>0</locationKey>
          <locationName>Unassigned</locationName>
          <rowNumber></rowNumber>
        </timeslip>
        <totalTimesheets>1</totalTimesheets>
        <financialPeriodKey>0</financialPeriodKey>
        <financialPeriodCode>None</financialPeriodCode>
      </timeSheet>
      <timeSheet>
        <code>3</code>
        <timePeriodKey>100</timePeriodKey>
        <beginDate>08-Jan-2010 12:00 AM GMT+08:00</beginDate>
        <personKey>133</personKey>
        <controllerKey></controllerKey>
        <dateCompleted>12-Nov-2010 06:02 PM GMT+08:00</dateCompleted>
        <status>COMPLETED</status>
        <comments></comments>
        <periodSeqKey>1</periodSeqKey>
        <prevTimesheet>0</prevTimesheet>
        <nextTimesheet>0</nextTimesheet>
        <replaceChildren>N</replaceChildren>
        <totalHours>40</totalHours>
        <timeslip>
          <code>30</code>
          <personTimeKey>3</personTimeKey>
          <projectKey>44</projectKey>
          <taskKey></taskKey>
          <workDate>08-Jan-2010 12:00 AM GMT+08:00</workDate>
          <quantity>8.00</quantity>
          <billRate>10000</billRate>
          <costRate>8000</costRate>
          <staffRoleKey>10</staffRoleKey>
          <comments></comments>
          <activityTypeKey>20</activityTypeKey>
          <projectName>LYS_0001</projectName>
          <taskName></taskName>
          <staffRoleName>PM</staffRoleName>
          <activityTypeName>*Billable</activityTypeName>
          <isAssignedToProject>Y</isAssignedToProject>
          <billRateCurrencyCode>USD</billRateCurrencyCode>
          <costRateCurrencyCode>USD</costRateCurrencyCode>
          <clientKey>62</clientKey>
          <locationKey>0</locationKey>
          <locationName>Unassigned</locationName>
          <rowNumber></rowNumber>
        </timeslip>
        <timeslip>
          <code>31</code>
          <personTimeKey>3</personTimeKey>
          <projectKey>44</projectKey>
          <taskKey></taskKey>
          <workDate>11-Jan-2010 12:00 AM GMT+08:00</workDate>
          <quantity>8.00</quantity>
          <billRate>10000</billRate>
          <costRate>8000</costRate>
          <staffRoleKey>10</staffRoleKey>
          <comments></comments>
          <activityTypeKey>20</activityTypeKey>
          <projectName>LYS_0001</projectName>
          <taskName></taskName>
          <staffRoleName>PM</staffRoleName>
          <activityTypeName>*Billable</activityTypeName>
          <isAssignedToProject>Y</isAssignedToProject>
          <billRateCurrencyCode>USD</billRateCurrencyCode>
          <costRateCurrencyCode>USD</costRateCurrencyCode>
          <clientKey>62</clientKey>
          <locationKey>0</locationKey>
          <locationName>Unassigned</locationName>
          <rowNumber></rowNumber>
        </timeslip>
        <timeslip>
          <code>32</code>
          <personTimeKey>3</personTimeKey>
          <projectKey>44</projectKey>
          <taskKey></taskKey>
          <workDate>12-Jan-2010 12:00 AM GMT+08:00</workDate>
          <quantity>8.00</quantity>
          <billRate>10000</billRate>
          <costRate>8000</costRate>
          <staffRoleKey>10</staffRoleKey>
          <comments></comments>
          <activityTypeKey>20</activityTypeKey>
          <projectName>LYS_0001</projectName>
          <taskName></taskName>
          <staffRoleName>PM</staffRoleName>
          <activityTypeName>*Billable</activityTypeName>
          <isAssignedToProject>Y</isAssignedToProject>
          <billRateCurrencyCode>USD</billRateCurrencyCode>
          <costRateCurrencyCode>USD</costRateCurrencyCode>
          <clientKey>62</clientKey>
          <locationKey>0</locationKey>
          <locationName>Unassigned</locationName>
          <rowNumber></rowNumber>
        </timeslip>
        <timeslip>
          <code>33</code>
          <personTimeKey>3</personTimeKey>
          <projectKey>44</projectKey>
          <taskKey></taskKey>
          <workDate>13-Jan-2010 12:00 AM GMT+08:00</workDate>
          <quantity>8.00</quantity>
          <billRate>10000</billRate>
          <costRate>8000</costRate>
          <staffRoleKey>10</staffRoleKey>
          <comments></comments>
          <activityTypeKey>20</activityTypeKey>
          <projectName>LYS_0001</projectName>
          <taskName></taskName>
          <staffRoleName>PM</staffRoleName>
          <activityTypeName>*Billable</activityTypeName>
          <isAssignedToProject>Y</isAssignedToProject>
          <billRateCurrencyCode>USD</billRateCurrencyCode>
          <costRateCurrencyCode>USD</costRateCurrencyCode>
          <clientKey>62</clientKey>
          <locationKey>0</locationKey>
          <locationName>Unassigned</locationName>
          <rowNumber></rowNumber>
        </timeslip>
        <timeslip>
          <code>34</code>
          <personTimeKey>3</personTimeKey>
          <projectKey>44</projectKey>
          <taskKey></taskKey>
          <workDate>14-Jan-2010 12:00 AM GMT+08:00</workDate>
          <quantity>8.00</quantity>
          <billRate>10000</billRate>
          <costRate>8000</costRate>
          <staffRoleKey>10</staffRoleKey>
          <comments></comments>
          <activityTypeKey>20</activityTypeKey>
          <projectName>LYS_0001</projectName>
          <taskName></taskName>
          <staffRoleName>PM</staffRoleName>
          <activityTypeName>*Billable</activityTypeName>
          <isAssignedToProject>Y</isAssignedToProject>
          <billRateCurrencyCode>USD</billRateCurrencyCode>
          <costRateCurrencyCode>USD</costRateCurrencyCode>
          <clientKey>62</clientKey>
          <locationKey>0</locationKey>
          <locationName>Unassigned</locationName>
          <rowNumber></rowNumber>
        </timeslip>
        <totalTimesheets>1</totalTimesheets>
        <financialPeriodKey>1</financialPeriodKey>
        <financialPeriodCode>2010-1</financialPeriodCode>
      </timeSheet>
      <timeSheet>
        <code>4</code>
        <timePeriodKey>100</timePeriodKey>
        <beginDate>15-Jan-2010 12:00 AM GMT+08:00</beginDate>
        <personKey>133</personKey>
        <controllerKey></controllerKey>
        <dateCompleted>12-Nov-2010 06:07 PM GMT+08:00</dateCompleted>
        <status>COMPLETED</status>
        <comments></comments>
        <periodSeqKey>1</periodSeqKey>
        <prevTimesheet>0</prevTimesheet>
        <nextTimesheet>0</nextTimesheet>
        <replaceChildren>N</replaceChildren>
        <totalHours>-39</totalHours>
        <timeslip>
          <code>35</code>
          <personTimeKey>4</personTimeKey>
          <projectKey>44</projectKey>
          <taskKey></taskKey>
          <workDate>15-Jan-2010 12:00 AM GMT+08:00</workDate>
          <quantity>-8.00</quantity>
          <billRate>10000</billRate>
          <costRate>8000</costRate>
          <staffRoleKey>10</staffRoleKey>
          <comments></comments>
          <activityTypeKey>20</activityTypeKey>
          <projectName>LYS_0001</projectName>
          <taskName></taskName>
          <staffRoleName>PM</staffRoleName>
          <activityTypeName>*Billable</activityTypeName>
          <isAssignedToProject>Y</isAssignedToProject>
          <billRateCurrencyCode>USD</billRateCurrencyCode>
          <costRateCurrencyCode>USD</costRateCurrencyCode>
          <clientKey>62</clientKey>
          <locationKey>0</locationKey>
          <locationName>Unassigned</locationName>
          <rowNumber></rowNumber>
        </timeslip>
        <timeslip>
          <code>36</code>
          <personTimeKey>4</personTimeKey>
          <projectKey>44</projectKey>
          <taskKey></taskKey>
          <workDate>18-Jan-2010 12:00 AM GMT+08:00</workDate>
          <quantity>-8.00</quantity>
          <billRate>10000</billRate>
          <costRate>8000</costRate>
          <staffRoleKey>10</staffRoleKey>
          <comments></comments>
          <activityTypeKey>20</activityTypeKey>
          <projectName>LYS_0001</projectName>
          <taskName></taskName>
          <staffRoleName>PM</staffRoleName>
          <activityTypeName>*Billable</activityTypeName>
          <isAssignedToProject>Y</isAssignedToProject>
          <billRateCurrencyCode>USD</billRateCurrencyCode>
          <costRateCurrencyCode>USD</costRateCurrencyCode>
          <clientKey>62</clientKey>
          <locationKey>0</locationKey>
          <locationName>Unassigned</locationName>
          <rowNumber></rowNumber>
        </timeslip>
        <timeslip>
          <code>37</code>
          <personTimeKey>4</personTimeKey>
          <projectKey>44</projectKey>
          <taskKey></taskKey>
          <workDate>19-Jan-2010 12:00 AM GMT+08:00</workDate>
          <quantity>-9.00</quantity>
          <billRate>10000</billRate>
          <costRate>8000</costRate>
          <staffRoleKey>10</staffRoleKey>
          <comments></comments>
          <activityTypeKey>20</activityTypeKey>
          <projectName>LYS_0001</projectName>
          <taskName></taskName>
          <staffRoleName>PM</staffRoleName>
          <activityTypeName>*Billable</activityTypeName>
          <isAssignedToProject>Y</isAssignedToProject>
          <billRateCurrencyCode>USD</billRateCurrencyCode>
          <costRateCurrencyCode>USD</costRateCurrencyCode>
          <clientKey>62</clientKey>
          <locationKey>0</locationKey>
          <locationName>Unassigned</locationName>
          <rowNumber></rowNumber>
        </timeslip>
        <timeslip>
          <code>38</code>
          <personTimeKey>4</personTimeKey>
          <projectKey>44</projectKey>
          <taskKey></taskKey>
          <workDate>20-Jan-2010 12:00 AM GMT+08:00</workDate>
          <quantity>-8.00</quantity>
          <billRate>10000</billRate>
          <costRate>8000</costRate>
          <staffRoleKey>10</staffRoleKey>
          <comments></comments>
          <activityTypeKey>20</activityTypeKey>
          <projectName>LYS_0001</projectName>
          <taskName></taskName>
          <staffRoleName>PM</staffRoleName>
          <activityTypeName>*Billable</activityTypeName>
          <isAssignedToProject>Y</isAssignedToProject>
          <billRateCurrencyCode>USD</billRateCurrencyCode>
          <costRateCurrencyCode>USD</costRateCurrencyCode>
          <clientKey>62</clientKey>
          <locationKey>0</locationKey>
          <locationName>Unassigned</locationName>
          <rowNumber></rowNumber>
        </timeslip>
        <timeslip>
          <code>39</code>
          <personTimeKey>4</personTimeKey>
          <projectKey>44</projectKey>
          <taskKey></taskKey>
          <workDate>21-Jan-2010 12:00 AM GMT+08:00</workDate>
          <quantity>-6.00</quantity>
          <billRate>10000</billRate>
          <costRate>8000</costRate>
          <staffRoleKey>10</staffRoleKey>
          <comments></comments>
          <activityTypeKey>20</activityTypeKey>
          <projectName>LYS_0001</projectName>
          <taskName></taskName>
          <staffRoleName>PM</staffRoleName>
          <activityTypeName>*Billable</activityTypeName>
          <isAssignedToProject>Y</isAssignedToProject>
          <billRateCurrencyCode>USD</billRateCurrencyCode>
          <costRateCurrencyCode>USD</costRateCurrencyCode>
          <clientKey>62</clientKey>
          <locationKey>0</locationKey>
          <locationName>Unassigned</locationName>
          <rowNumber></rowNumber>
        </timeslip>
        <totalTimesheets>1</totalTimesheets>
        <financialPeriodKey>1</financialPeriodKey>
        <financialPeriodCode>2010-1</financialPeriodCode>
      </timeSheet>
      <timeSheet>
        <code>21</code>
        <timePeriodKey>100</timePeriodKey>
        <beginDate>27-Aug-2010 12:00 AM GMT+08:00</beginDate>
        <personKey>153</personKey>
        <controllerKey></controllerKey>
        <dateCompleted>15-Nov-2010 10:43 AM GMT+08:00</dateCompleted>
        <status>COMPLETED</status>
        <comments></comments>
        <periodSeqKey>1</periodSeqKey>
        <prevTimesheet>0</prevTimesheet>
        <nextTimesheet>0</nextTimesheet>
        <replaceChildren>N</replaceChildren>
        <totalHours>9</totalHours>
        <timeslip>
          <code>43</code>
          <personTimeKey>21</personTimeKey>
          <projectKey>44</projectKey>
          <taskKey></taskKey>
          <workDate>01-Sep-2010 12:00 AM GMT+08:00</workDate>
          <quantity>1.00</quantity>
          <billRate>0</billRate>
          <costRate>0</costRate>
          <staffRoleKey>10</staffRoleKey>
          <comments></comments>
          <activityTypeKey>20</activityTypeKey>
          <projectName>LYS_0001</projectName>
          <taskName></taskName>
          <staffRoleName>PM</staffRoleName>
          <activityTypeName>*Billable</activityTypeName>
          <isAssignedToProject>Y</isAssignedToProject>
          <billRateCurrencyCode>USD</billRateCurrencyCode>
          <costRateCurrencyCode>USD</costRateCurrencyCode>
          <clientKey>62</clientKey>
          <locationKey>0</locationKey>
          <locationName>Unassigned</locationName>
          <rowNumber></rowNumber>
        </timeslip>
        <timeslip>
          <code>44</code>
          <personTimeKey>21</personTimeKey>
          <projectKey>44</projectKey>
          <taskKey></taskKey>
          <workDate>02-Sep-2010 12:00 AM GMT+08:00</workDate>
          <quantity>8.00</quantity>
          <billRate>0</billRate>
          <costRate>0</costRate>
          <staffRoleKey>10</staffRoleKey>
          <comments></comments>
          <activityTypeKey>20</activityTypeKey>
          <projectName>LYS_0001</projectName>
          <taskName></taskName>
          <staffRoleName>PM</staffRoleName>
          <activityTypeName>*Billable</activityTypeName>
          <isAssignedToProject>Y</isAssignedToProject>
          <billRateCurrencyCode>USD</billRateCurrencyCode>
          <costRateCurrencyCode>USD</costRateCurrencyCode>
          <clientKey>62</clientKey>
          <locationKey>0</locationKey>
          <locationName>Unassigned</locationName>
          <rowNumber></rowNumber>
        </timeslip>
        <totalTimesheets>1</totalTimesheets>
        <financialPeriodKey>1</financialPeriodKey>
        <financialPeriodCode>2010-1</financialPeriodCode>
      </timeSheet>
      <timeSheet>
        <code>81</code>
        <timePeriodKey>100</timePeriodKey>
        <beginDate>26-Nov-2010 12:00 AM GMT+08:00</beginDate>
        <personKey>153</personKey>
        <controllerKey>153</controllerKey>
        <dateCompleted>02-Dec-2010 02:37 PM GMT+08:00</dateCompleted>
        <status>INUSE</status>
        <comments></comments>
        <periodSeqKey>1</periodSeqKey>
        <prevTimesheet>0</prevTimesheet>
        <nextTimesheet>0</nextTimesheet>
        <replaceChildren>N</replaceChildren>
        <totalHours>0</totalHours>
        <totalTimesheets>1</totalTimesheets>
        <financialPeriodKey>0</financialPeriodKey>
        <financialPeriodCode>None</financialPeriodCode>
      </timeSheet>
      <timeSheet>
        <code>82</code>
        <timePeriodKey>140</timePeriodKey>
        <beginDate>01-Dec-2010 12:00 AM GMT+08:00</beginDate>
        <personKey>153</personKey>
        <controllerKey>153</controllerKey>
        <dateCompleted>02-Dec-2010 03:14 PM GMT+08:00</dateCompleted>
        <status>INUSE</status>
        <comments></comments>
        <periodSeqKey>1</periodSeqKey>
        <prevTimesheet>0</prevTimesheet>
        <nextTimesheet>0</nextTimesheet>
        <replaceChildren>N</replaceChildren>
        <totalHours>0</totalHours>
        <totalTimesheets>1</totalTimesheets>
        <financialPeriodKey>0</financialPeriodKey>
        <financialPeriodCode>None</financialPeriodCode>
      </timeSheet>
    </collection>
    <isSuccess />
    <elapsedTime seconds="0.055" />
  </result>
</response>


XML 有点长!

我现在的结果如下图:
图片附件: 游客没有浏览图片的权限,请 登录注册


但是我还希望 把 没有 timeSlip 那个节点 TimeSheet 取出来!相当于 表的左连接!

XElement myDoc = XElement.Load("C:\\query_timesheet_result.xml");

        var xml =
             from ele in myDoc.Elements("result").Elements("collection").Elements("timeSheet")
             from ele2 in ele.Elements("timeslip")
             select new
             {
                 timeSheetCode = ele.Element("code").Value,
                 timeSheettotalHours = ele.Element("totalHours").Value,
                 timeslipCode = ele2.Element("code").Value,

             };



        foreach (var item in xml)
        {
            Response.Write(item + "<br/>");
        }
搜索更多相关主题的帖子: XML Linq 
2010-12-03 13:12
lgwei
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-1-18
收藏
得分:0 
学习中···
2011-01-19 08:58
abc65722091
Rank: 1
等 级:新手上路
帖 子:5
专家分:1
注 册:2013-6-26
收藏
得分:0 
不错不错
2013-06-26 21:48
快速回复:XML Linq 读取时的问题!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022673 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved