Public Function FnNodesToArray(itemList As Object, nodeNames() As String) As String()
Dim i As Integer
Dim j As Integer
i_end = itemList.Length - 1
j_end = nodeNames.Length - 1
Dim arr() As String
ReDim arr(0 To i_end, 0 To j_end) As String
For i = 0 To i_end
For j = 0 To j_end
itemList(i).SelectSingleNode(nodeNames(j)).Text
arr(i, j) = itemList(i).SelectSingleNode(nodeNames(j)).Text
Next j
Next i
FnNodesToArray = arr()
'Set arr = Nothing
End Function
Pri spousteni makra ve wordu mi to hlasi
invalid qualifier
radek:
Public Function FnNodesToArray(itemList As Object, nodeNames() As String) As String()
Vubec netusim, co je za chybu. Zbytek kodu vypada takto:
Dim XDoc As Object, root As Object
Dim Xml_path As String
Xml_path = "getDiplomaSupplement.xml"
Set XDoc = CreateObject("MSXML2.DOMDocument")
XDoc.async = False: XDoc.validateOnParse = False
XDoc.Load (ThisDocument.Path & "\" & Xml_path)
Dim root_str As String
root_str = "/ns1:getDiplomaSupplement2Response/reports_diploma_supplement2_GDipsup2"
Dim student_list As Object
Set student_list = XDoc.SelectNodes(root_str)
Dim predmety_arr() As String
Dim predmety_xml() As String
ReDim predmety_xml(0 To 6) As String
predmety_xml(0) = "predmetZkratka"
predmety_xml(1) = "predmetNazevdlouhyEn"
predmety_xml(2) = "predmetNazevdlouhyCz"
predmety_xml(3) = "predmetDatum"
predmety_xml(4) = "predmetHodnocCz" ' prepocitat, zamena R U nebo tak neco !!!
predmety_xml(5) = "predmetPockred"
predmety_xml(6) = "predmetJazykEn"
Dim predmety_node As Object
Set predmety_node = XDoc.SelectNodes(root_str & "/" & "predmety/item")
(cyklus...)
predmety_arr = FnNodesToArray(predmety_node, predmety_xml)
1) Potrebuji ulozit ze xml nody s tagem
<predmety> <item></item> <item></item> ... </predmety>
Do nejake promenne.
2) Pak z toho vyfiltrovat konkretni sub-tagy jako <predmetNazevdlouhyCz>. Chci to ulozit do pole.
3) Pak bude nasledovat faze, kdy pridam radky do nejake tabulky. Tou jsem se zatim nezabyval, kod vypada predbezne takto. Ale ted bych potreboval vedet, jak spravit tu funkci.
Public Function FnArrayToTable(objDoc As Object, name As String, data As Variant)
Dim objTable
Set objTable = objDoc.Tables(name)
j_end = FnArrayLen(data)
For j = 1 To j_end
i_end = FnArrayLen(data(i))
For i = 1 To i_end
objTable.Cell(j, i).Range.Text = data(j, i)
Next i
Next j
End Function