2012-10-05 3 views
0

내가 같은 웹 페이지의 HTML 코드가 C#으로 문자열의 일부를 대체하는 기능을 가질 수있는 방법 다음나는 일치하고

<html> 
<div class="code" id="one"> 
<pre> 
     int i = 1; 
     int j = 2; 
</pre> 
</div> 
<h1>Sample heading</h1> 
<div class="code" id="two"> 
<pre> 
     int i = 1; 
     int j = 2; 
</pre> 
</div> 

코드는 C#을 문자열에 있고 내가 할 필요 이 같은으로 <pre> 영역을 대체 할 수있는 방법 찾을 수 있습니다 : 나는 원래 문자열을 원래의 데이터 있지만 일부 기능이 구성되는 새 문자열을 만들 수있는 방법

<table> 
<tr><td>1</td><td><code> int i = 1</code></td></tr> 
<tr><td>2</td><td><code> int j = 2</code></td></tr> 
</table> 

<pre> 텍스트를 변환하기를 그 <pre> tex에 적용됩니다. t 영역?

+0

당신은 아마 변환 XSLT의 일종을 사용하려면 : –

+0

이 기사는 XSLT을 수행하는 방법을 설명 http://en.wikipedia.org/wiki/XSLT .NET에서 변환 : http://msdn.microsoft .com/en-us/library/14689742.aspx –

답변

0

내가 너라면, 어떤 형태의 XML 파서를 사용하여 <pre> 요소를 찾을 수 있습니다.

XDocument loDoc = XDocument.Parse(lcHTML); 

    foreach (XElement loElement in loDoc.Descendants("pre")) 
    { 
     //-- Modify the html to your heart's content. 
     //-- You can split the html on newline character, prefix each line with your table stuff along with the line index. Then write the XML back out. 
    } 
관련 문제