2010-02-25 77 views
1

感謝您在 search dataset from xml file 中給出的建議,以便像我之前的文章中那樣使用Xpath代替數據集。我已經使用xpath成功地過濾了我的xml數據(請參閱上一篇文章),但現在我需要在表中顯示數據。我該怎麼做呢?我需要顯示某些值。我如何選擇我想要的節點並顯示它們?如何在HTML表格中顯示XML數據

Dim xdoc As New XPathDocument(xt) 
    Dim nav As XPathNavigator = xdoc.CreateNavigator() 

    Dim expr As XPathExpression = nav.Compile("pf:CONTRACTS/pf:CONTRACT[contains(pf:KEYWORDS,'" word "')]") 

    Dim tr As String = Nothing 
    Dim namespaceManager As XmlNamespaceManager = New XmlNamespaceManager(nav.NameTable) 
    namespaceManager.AddNamespace("pf", "http://namespace.co.uk/") 
    expr.SetContext(namespaceManager) 
    Dim nodes As XPathNodeIterator = nav.Select(expr) 

     While nodes.MoveNext() 
    'I would need to have "Contact ID", "Contract Name", etc.   
     tr += "<tr><td>" & nodes.Current.Value & "</td><td></td><td></td><td></td></tr>" 
    End While 
      Dim th As String = "<th>Commodity</th><th>Name</th><th>Supplier</th><th>Name</th>" 
    div1.InnerHtml = ("<table class='datatable1'>" & th) + tr & "</table>" 
+1

另外,您可能想重新考慮您的整個方法。在ASP.NET中通過字符串連接創建輸出HTML在這麼多級別上是錯誤的... – Tomalak 2010-02-25 18:17:34

+0

將xml解析爲xdocument/xdocument,然後使用xslt進行轉換 - 閱讀xsl,我非常肯定您可以這樣做。 – Haroon 2011-03-16 16:53:31

+0

最後使用了xslt嗎? – 2011-05-23 05:08:25

回答

0

使用XSLT將XML轉換爲任何其他XML(包括HTML)。