Domino 9 und frühere Versionen > ND6: Entwicklung
[erledigt] XML Datei in die NSF importieren
Fedaykin:
Hallo Ozan
Damit kann Notes so nichts anfangen. Es kann ja nicht wissen was und wie Du was aufbauen willst. Da kommst Du nicht drum herum das XML zu parsen und dann das zu machen was Du willst.
Die Beispiele in der Hilfe zu den Klassen
NotesDOMParser oder NotesSAXParser
könnten dabei hilfreich sein.
Mir ist NotesDOMParser sympatischer, ist aber vielleicht auch etwas Geschmackssache.
Gruss
Remo
pram:
Das geht so nicht.
Mit dem DXLimporter kannst du nur Domino-XML (DXL) konforme Dokumente importieren.
Du könntest jetzt mittels XSLT-Transformation dein XML in DXL transformieren (schwierig) oder mittels DOM/SaxParser dein XML parsen und dann auf herkömmliche Art Dokumente anlegen und die Felder entsprechend befüllen. (einfacher)
Gruß
Roland
edit: zu langsam :)
Ozan:
Verstehe, ich habe das entsprechen gesucht und gefunden, habe das so:
(Declarations)
Dim domParser As NotesDOMParser
Dim LF As String
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
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
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
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
eingesetzt, lief auch fehlerfrei. Jetzt hat der mir eine Datei erzeugt: DOMtree.txt
Jetzt müsste ich die gefilterte Infos daraus nehmen und in die DB schreiben? Oder kann man das so einstellen dass der gleich in der DB die Documente anlegt?
Gruss
Ozan
Fedaykin:
Hallo Ozan
Das kann man nun so programmieren, dass er die Dokumente direkt erzeugt.
Gruss
Remo
Ozan:
Hallo Remo,
diese Baumstruktur macht mir viel Bauch schmerzen, kannst du mir das beispielweise zeigen wie das funktioniert?
hier ein teil der OutputXML:
DOM Parser Report - Walk Tree agent
Document node: #document has 2 Child Nodes
Element node: obexim has 0 Attributes
Text node:
Element node: node has 3 Attributes
Attribute id: 3
Attribute title: Technisches
Attribute branches: 24
Text node:
Element node: node has 3 Attributes
Attribute id: 23
Attribute title: Mac
Attribute branches: 24
Text node:
Element node: node has 3 Attributes
Attribute id: 124
Attribute title: Anschluss
Attribute branches: 24
Text node:
Element node: text has 3 Attributes
Attribute id: 848
Attribute title: IRQ
Attribute branches: 24
CDATA Section node: #cdata-section has value of <UL>
<LI>......
</P></A>
***
Bis hier hin währe z.b eine Seite bzw. eine Document weil ich die Baumstruktur auch behalten will
***
text
Text node:
Element node: text has 3 Attributes
Attribute id: 1167
Attribute title: Teil2
Attribute branches: 24
CDATA Section node: #cdata-section has value of <P><A
text
Text node:
Element node: text has 3 Attributes
Attribute id: 1564
Attribute title: Teil3
.....
Eine Ansicht wie in der XML-Editor( + und - ) währe auch machbar? Also im Notes dann mit Katalogiesierung.
Gruss
Ozan
Navigation
[0] Themen-Index
[#] Nächste Seite
[*] Vorherige Sete
Zur normalen Ansicht wechseln