我在下面的格式獲取XML從嵌入式機器:解析XML無支鏈的C#
<?xml version="1.0" encoding="utf-8"?>
<Horizon-Export>
<BatchNo.>1</BatchNo.>
<SpecimenID>CL1</SpecimenID>
<OperatorName>Anuj</OperatorName>
<SpecimenAge>1.00</SpecimenAge>
<Grade>M12</Grade>
<DateofCasting>01/09/2012</DateofCasting>
<SpecimenShape>Cube</SpecimenShape>
<SpecimenSize>150.00</SpecimenSize>
<Area>22,500</Area>
<Weight>10.0</Weight>
<Density>1.00</Density>
<TestDate>17/09/2012</TestDate>
<TestTime>9:41:08 AM</TestTime>
<BatchDate>17/09/2012</BatchDate>
<UltimateForce>
</UltimateForce>
<UltimateStress>
</UltimateStress>
<Remarks>Pass</Remarks>
<BatchNo.>1</BatchNo.>
<SpecimenID>CL1</SpecimenID>
<OperatorName>Anuj</OperatorName>
<SpecimenAge>1.00</SpecimenAge>
<Grade>M12</Grade>
<DateofCasting>01/09/2012</DateofCasting>
<SpecimenShape>Cube</SpecimenShape>
<SpecimenSize>150.00</SpecimenSize>
<Area>22,500</Area>
<Weight>10.0</Weight>
<Density>1.00</Density>
<TestDate>17/09/2012</TestDate>
<TestTime>9:47:10 AM</TestTime>
<BatchDate>17/09/2012</BatchDate>
<UltimateForce>25.3</UltimateForce>
<UltimateStress>1.12</UltimateStress>
<Remarks>Pass</Remarks>
<BatchNo.>1</BatchNo.>
<SpecimenID>CL1</SpecimenID>
<OperatorName>Anuj</OperatorName>
<SpecimenAge>1.00</SpecimenAge>
<Grade>M12</Grade>
<DateofCasting>01/09/2012</DateofCasting>
<SpecimenShape>Cube</SpecimenShape>
<SpecimenSize>150.00</SpecimenSize>
<Area>22,500</Area>
<Weight>10.0</Weight>
<Density>1.00</Density>
<TestDate>17/09/2012</TestDate>
<TestTime>9:48:57 AM</TestTime>
<BatchDate>17/09/2012</BatchDate>
<UltimateForce>8.3</UltimateForce>
<UltimateStress>0.37</UltimateStress>
<Remarks>Pass</Remarks>
<BatchNo.>1</BatchNo.>
<SpecimenID>CL1</SpecimenID>
<OperatorName>Anuj</OperatorName>
<SpecimenAge>1.00</SpecimenAge>
<Grade>M12</Grade>
<DateofCasting>01/09/2012</DateofCasting>
<SpecimenShape>Cube</SpecimenShape>
<SpecimenSize>150.00</SpecimenSize>
<Area>22,500</Area>
<Weight>10.0</Weight>
<Density>1.00</Density>
<TestDate>17/09/2012</TestDate>
<TestTime>9:49:20 AM</TestTime>
<BatchDate>17/09/2012</BatchDate>
<UltimateForce>10.9</UltimateForce>
<UltimateStress>0.49</UltimateStress>
<Remarks>Pass</Remarks>
<BatchNo.>1</BatchNo.>
<SpecimenID>CL1</SpecimenID>
<OperatorName>Anuj</OperatorName>
<SpecimenAge>1.00</SpecimenAge>
<Grade>M12</Grade>
<DateofCasting>01/09/2012</DateofCasting>
<SpecimenShape>Cube</SpecimenShape>
<SpecimenSize>150.00</SpecimenSize>
<Area>22,500</Area>
<Weight>10.0</Weight>
<Density>1.00</Density>
<TestDate>17/09/2012</TestDate>
<TestTime>9:49:42 AM</TestTime>
<BatchDate>17/09/2012</BatchDate>
<UltimateForce>2.6</UltimateForce>
<UltimateStress>0.12</UltimateStress>
<Remarks>Pass</Remarks>
</Horizon-Export>
據實際測試具有在單個XML多個測試結果輸出。 AFAIK xml有一些錯誤的格式,因爲所有的測試都在一個級別上,並且它們沒有分支。爲了使XML可讀,我在結果集之間放置了一行。測試結果從<BatchNo></BatchNo.>
開始,結束於<Remarks></Remarks>
。我有同樣的課。對於單個結果集或分支結果,我可以解析,但在這種情況下,我的代碼只解析一次。我需要創建一個相同類的列表。我使用
代碼:
var root = XDocument.Load(path).Root;
var s = root.Element("BatchNo.").value; // and so on for other nodes.
我有類似的問題貼出來,因爲我不知道的從客戶的實際需求。現在他們說它不是一次測試它實際上多次測試的結果,所以我再次發佈問題。請不要投票結束或倒退。
Unable to Parse XML using LINQ in ASP.Net & C#
你能解釋更多請問你的意思是「對於單個結果集或分支結果我可以解析,但在這種情況下,我的代碼只解析一次,我需要創建一個相同類的列表 –