Danke habs mit den validator von w3 gemerkt - http://validator.w3.org/
Lese gerade dieses Thema (http://atnotes.de/index.php/topic,45337.0.html) und wenn ich es richtig verstehe kann ich diesen Block in das Beispiel von IBM einfügen um ein neues Dokument anzulegen und auch die Nodes in die Dokumente einzuschreiben?
Case DOMNODETYPE_ELEMENT_NODE:
Dim doc As NotesDocument
Dim session As NotesSession
Dim db As NotesDatabase
Set session = New NotesSession
Set db = session.CurrentDatabase
If node.nodename = "machineID" Then
Set doc = db.CreateDocument
doc.form = "all"
End If
Doch irgendwie kommt dabei nicht herraus wenn ich dies in den walkTree abschnitt setze ...
Sieht jemand den fehler ???
Case DOMNODETYPE_ELEMENT_NODE: ' Most nodes are Elements
domParser.Output("Element node: "+node.NodeName )
Set elt = node
Dim doc As NotesDocument
Dim session As NotesSession
Dim db As NotesDatabase
Set session = New NotesSession
Set db = session.CurrentDatabase
If node.nodename = "machineID" Then
Set doc = db.CreateDocument
doc.form = "form_machine"
doc.machineId = Node.Firstchild.Nodevalue
Call doc.Save( True, True )
End if
If node.nodename = "machineManufacturer" Then
doc.form = "form_machine"
doc.machineManufacturer = Node.Firstchild.Nodevalue
Call doc.Save( True, True )
End If
Es wird ein neus Dokument und der Eintrag für machineID erstellt, aber machineManufacturer bleibt leer...
Guten Morgen!
Habe die DIMs aus der Schleife entfernt, aber das bringt es auch noch nicht, wäre ja auch zu schön gewesen :) Kurz noch: machineID steht in der xml vor machineManufacturer. ;)
Wenn ich mit den debugger Schritt für Schritt durch gehe, sehe ich auch das ein Wert für machineManufacturer bei node -> firstchild vorhanden ist. Lasse ich bei machineManufacturer, ähnlich wie für machineID ein neues Dokument erstellen, dann trägt er den Wert für machineManufacturer im neuen Dokument auch ein. Also irgendwo verlieren ich also den Zugriff auf das frisch erstellte Dokument oder liegt ich da falsch? Ist der call save befehl daran schuld? habe es auch schon nur bei machineManufacturer, sowie auserhalb der Schleife mal rein gepackt aber kein Erfolg.
Hier mal meine Daten:
Decleration
Dim domParser As NotesDOMParser
Dim LF As String
Public doc As NotesDocument
Sub Initialize
Dim session As NotesSession
Dim db As NotesDatabase
Dim inputStream As NotesStream, outputStream As NotesStream
Dim docNode As NotesDOMDocumentNode
Dim origXML As String, outputFile As String
origXML = "c:\dxl\xmldom.xml"
outputFile = "c:\dxl\DOMtree.txt"
Dim header As String
header = "Walk Tree agent"
LF = Chr(13)+Chr(10)
On Error Goto errh
Set session = New NotesSession
Set db = session.CurrentDatabase
'create the output file
Set outputStream =session.CreateStream
outputStream.Open (outputFile)
outputStream.Truncate
'write report title
outputStream.WriteText ("DOM Parser Report - " )
outputStream.WriteText (header+LF)
'open the XML file
Set inputStream = session.CreateStream
inputStream.Open (origXML)
If inputStream.Bytes = 0 Then
outputStream.WriteText (origXML+" is empty"+LF)
Goto results
End If
'create DOM parser and process
Set domParser=session.CreateDOMParser(inputStream, outputStream)
domParser.Process
'get the document node
Set docNode = domParser.Document
Call walkTree(docNode)
results:
Call outputStream.Close
Exit Sub
errh:
outputStream.WriteText ("errh: "+Cstr(Err)+": "+Error+LF)
Resume results
End Sub
Un der Walktree + meine kaputter Block
Sub walkTree ( node As NotesDOMNode)
Dim child As NotesDOMNode
Dim elt As NotesDOMNode
Dim attrs As NotesDOMNamedNodeMap
Dim a As NotesDOMAttributeNode
Dim piNode As NotesDOMProcessingInstructionNode
Dim doc As NotesDocument
Dim session As NotesSession
Dim db As NotesDatabase
Set session = New NotesSession
Set db = session.CurrentDatabase
LF = Chr(13)+Chr(10)
If Not node.IsNull Then
Select Case node.NodeType
Case DOMNODETYPE_DOCUMENT_NODE: ' If it is a Document node
domParser.Output( "Document node: "+node.Nodename )
Set child = node.FirstChild ' Get the first node
Dim numChildNodes As Integer
numChildNodes = node.NumberOfChildNodes
domParser.Output(" has "+Cstr(numChildNodes)+" Child Nodes"+LF)
While numChildNodes > 0
Set child = child.NextSibling ' Get next node
numChildNodes = numChildNodes - 1
Call walkTree(child)
Wend
Case DOMNODETYPE_DOCUMENTTYPE_NODE: ' It is a <!DOCTYPE> tag
domParser.Output("Document Type node: "+ node.NodeName+LF)
Case DOMNODETYPE_TEXT_NODE: ' Plain text node
domParser.Output("Text node: "+node.NodeValue+LF)
Case DOMNODETYPE_ELEMENT_NODE: ' Most nodes are Elements
domParser.Output("Element node: "+node.NodeName )
Set elt = node
'XMl Daten in die db schreiben
If node.nodename = "machineID" Then
Set doc = db.CreateDocument
doc.form = "form_machine"
'doc.machineId = Node.Firstchild.Nodevalue
Call doc.ReplaceItemValue("machineID", Node.Firstchild.Nodevalue)
Call doc.Save(true, true)
End If
If node.nodename = "machineManufacturer" Then
doc.form = "form_machine"
Call doc.ReplaceItemValue("machineManufacturer", Node.Firstchild.Nodevalue)
Call doc.Save(True, true)
End If
Dim numAttributes As Integer, numChildren As Integer
numAttributes = elt.attributes.numberofentries
domParser.Output(" has "+Cstr(numAttributes)+" Attributes"+LF)
Set attrs = elt.Attributes ' Get attributes
Dim i As Integer
For i = 1 To numAttributes ' Loop through them
Set a = attrs.GetItem(i)
' Print attr. name & value
domParser.Output("Attribute "+a.NodeName+": "+a.NodeValue+LF)
Next
numChildren = elt.NumberOfChildNodes
Set child = elt.FirstChild ' Get child
While numChildren > 0
Call walkTree(child)
Set child = child.NextSibling ' Get next child
numChildren = numChildren - 1
Wend
domParser.Output( elt.nodeName+LF)
Case DOMNODETYPE_COMMENT_NODE: ' Comments
domParser.Output("Comment node: "+node.NodeValue+LF)
Case DOMNODETYPE_PROCESSINGINSTRUCTION_NODE: ' Handle PI nodes
Set piNode = node
domParser.Output("Processing Instruction node: " )
domParser.Output(" with Target "+piNode.Target+_
" and Data "+piNode.Data+LF)
Case DOMNODETYPE_CDATASECTION_NODE: ' CDATA sections
domParser.Output("CDATA Section node: "+node.NodeName)
domParser.Output(" has value of "+node.NodeValue+LF)
Case DOMNODETYPE_ENTITYREFERENCE_NODE: ' Handle entities
domParser.Output("Entity Reference node: "+node.NodeName+LF)
Case Else:
domParser.Output("Ignoring node: "+Cstr(node.NodeType)+LF)
End Select 'node.NodeType
End If 'Not node.IsNull
End Sub