테이블 형식의 이전 데이터를 새로운 형식으로 변환하는 작업을했습니다.
이전 더미 데이터는 다음과 같습니다.
<table>
<tr>
<td>Some text 1.</td>
<td>Some text 2.</td>
</tr>
..... //any number of TRs goes here
</table>
문제는 새 데이터가 다음과 같은 형식이어야한다는 것입니다.
일부 텍스트 1. - 일부 텍스트 2. ....
여기에서해야 할 일에 대한 요약 :
표의 모든 TR을 찾으십시오. 각 TR에 대해 첫 번째 TD를 찾고 "-"로 구분 된 두 번째 TD와 연결합니다.
VB.Net에서 HTML 민첩성 팩을 사용하고 있습니다.
도와주세요.
고마워, 안부.
Linq 및 HtmlAgilityPack을 사용하여 테이블 노드에서 모든 td를 가져 와서이 노드의 모든 InnerText를 가져 와서 새 TR / TD를 만들 수 있습니다.
// tableNode is the <table> HtmlNode. If you know where is this table you can use XPath to find him.
Dim sb As New StringBuilder()
For Each childNode As HtmlNode In tableNode.DescendantNodes().Where(Function(n) n.Name = "td")
sb.Append(String.Format("{0} - ", childNode.InnerText))
Next
tableNode.RemoveAllChildren()
Dim newTrNode As HtmlNode = tableNode.OwnerDocument.CreateElement("tr")
Dim newTdNode As HtmlNode = tableNode.OwnerDocument.CreateElement("td")
newTdNode.InnerHtml = sb.ToString()
newTrNode.AppendChild(newTdNode)
tableNode.AppendChild(newTrNode)
도움이되기를 바랍니다.