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