2012-11-09 4 views
0

XDocument (또는 다른 유사한 라이브러리)를 사용하여 일부 XHTML을 생성하고 싶습니다. 불행히도 중첩 된 태그는 서로가 아닌 동일한 레벨에서 종료됩니다. 누군가이 간단한 문제로 나를 도울 수 있습니까?XDocument를 사용하여 중첩 태그가있는 XHTML 작성

내가 지금까지 가지고하는 것은 :

var html = new XDocument(
    new XElement("div", new XAttribute("class", "MyTable"), 
    new XElement("table", 
     new XElement("thead"), 
     new XElement("tr"), 
      new XElement("th", "Test")))); 

이것은 다음과 같은 결과 :

<div class="MyTable"> 
    <table> 
    <thead> 
     <tr> 
     <th>Test</th> 
     </tr> 
    </thead> 
    </table> 
</div> 

답변

1
new XDocument(
    new XElement("div", new XAttribute("class", "MyTable"), 
    new XElement("table", 
     new XElement("thead", 
     new XElement("tr", 
      new XElement("th", "Test")))))) 

봐 : 여기

<div class="MyTable"> 
    <table> 
    <thead /> 
    <tr /> 
    <th>Test</th> 
    </table> 
</div> 

내가 달성하고자하는 레이아웃입니다 너의 닫힌 괄호에에및 tr. 요소를 닫으 려하지 않는 한 닫지 않아야합니다. 나는 단순히 그들을 끝까지 움직였다.

+0

감사합니다. 어리석은 짓을하는 줄 알았어. 방금 찾지 못했습니다. – Rethic

관련 문제