2014-06-19 138 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();