2014-06-19 182 views
1

我有一個文本文件,其中包含普通文本和XML(包含兩個結束標記&自關閉標記)。從包含純文本和XML的文本文件獲取Xml

如何從基於通過ErrorID

6/13/2014 11:50:51 PM : StudentInfo : ErrorId - 6124 
Below is the sample XML 
<student> 
    <Id>1</Id> 
    <Name>Test</Name>  (having end tag) 
    <Age xsi:nil="true"/> (self closing tag) 
</student> 

6/13/2014 11:50:51 PM : StudentInfo : ErrorId - 6127 
Below is the sample XML 
<student> 
    <Id>2</Id> 
    <Name>Sample</Name> 
    <Age>23</Age> 
</student> 

文件單獨提取XML。 。 。

在這裏我只能得到基於錯誤的XML文本
使用正則表達式嘗試,但沒有運氣。

我shoulg得到如下的輸出,當我通過ErrorID中爲6127

<student> 
    <Id>2</Id> 
    <Name>Sample</Name> 
    <Age>23</Age> 
</student> 

回答

0
var students = XElement.Parse("<doc>" + text + "</doc>") 
    .Elements("student") 
    .ToArray();