Im努力返回RDLC文件的TableRows元素下的行元素的XMLNodeList。有很多命名空間的例子是原因,但是我嘗試了它們,並且無法從我的XPath查詢中找回任何節點,儘管公平我並不真正瞭解默認/命名空間等。我已經在quickwatch中檢查了Default Namespace屬性,它說它的 」」 ??雖然我不知道爲什麼或如何將它設置爲只讀。TableRows上的RDLC SelectNodes元素
香港專業教育學院定義我的命名空間有:
Dim doc As XmlDocument = New XmlDocument()
doc.Load(fname)
Dim root As XmlNode = doc.DocumentElement
Dim nsmgr As New XmlNamespaceManager(doc.NameTable)
nsmgr.AddNamespace("rd", "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner")
nsmgr.AddNamespace("pf", "http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition")
然後在IM希望做一些與我通過LST作爲XmlNode的,做行的代碼後:
' FIRST FIND THE <TableRows> NODE, UNDER MY CURRENT <Header> ELEMENT
Dim TableRowsNode As XmlNode = lst.Item("TableRows") ' where lst is the <Header> element of the table in the rdlc i want to process
' GET ALL THE ROWS WITHIN THE <TABLEROWS> NODE
Dim Rows As XmlNodeList = TableRowsNode.SelectNodes("//rd:TableRow", ns) ' where ns is the above nsmgr
' FOR EACH ROW
For Each TableRow As XmlNode In Rows
' GET ALL THE CELLS
Dim TableCells As XmlNode = TableRow.Item("TableCells")
' FOR EACH CELL
For Each TableCell As XmlNode In TableCells
Dim ReportItems As XmlNode = TableCell.Item("ReportItems")
For Each ReportItem As XmlNode In ReportItems
Select Case ReportItem.Name
Case "Textbox"
txt_lst.Add(ReportItem)
Case "Image"
img_lst.Add(ReportItem)
End Select
Next ' each report item
Next ' each cell
Next ' each row
香港專業教育學院試圖 「 ./TableRow 「
」//的TableRow「
」 .//TableRows」
「// RD:的TableRow」
「// PF:的TableRow」
和其他變種的主機上,但TableRowsNode.SelectNodes(..)線永遠不會返回任何結果(計數= 0)
我到底做錯了什麼?
這裏有一對夫婦的RDLC IM裝載的相關部分的片斷:
<?xml version="1.0" encoding="utf-8"?>
<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
和部分IM感興趣...
<Table Name="table2">
.....
<Header>
<TableRows>
<TableRow>
....
</TableRow>
<TableRow>
.....
</TableRow>
</TableRows>
我想要的NodeList的「 TableRow「元素,以便我可以生成圖像,文本框等列表,我將處理和一般做的東西(對於那些感興趣的,生成數學符號圖像,交換資源字符串爲他們相關的文本等)...
我一直在這裏太長了,一定有一些愚蠢的簡單即時通訊丟失,因爲所有的搜索導致相同的解決方案名稱空間,並xpath查詢字符串...
請幫助。
編輯: 得到了XPath查詢排序與工作的「// PF:的TableRow」,但它是從整個文檔返回的所有節點,所以我放棄了,只是用
Dim Rows As XmlNodeList = TableRowsNode.ChildNodes
編輯: 顯然「/」使它從文檔的頂層搜索,但我不能得到「.//pf:TableRow」只返回當前的那些匹配節點?當我有更多的時間時,生病會再回來。
如果沒有默認命名空間的覆蓋聲明,那麼`// pf:TableRow`應該使用`pf`前綴綁定到`http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition `namespace URI – 2011-02-01 14:59:14
好問題,+1。請參閱我的答案以獲取具體說明:) – 2011-02-01 15:35:47