Тема: NotesDOMParser класс. Проход по XML файлу.
С помощью лотусового класса NotesDOMParser проходим по файлу persons.xml и загоняем в переменную Bart - значение тега name = Bart, в переменную Simps - значение тега sureName = sureName.
Так же получаем в переменные атрибуты atr и asd.
Файл для обработки - persons.xml
<persons>
<pers1 atr="петя">
<name asd="Вася">
Bart
</name>
<sureName>
Simpson
</sureName>
</pers1>
<pers2>
<name>
Jonny
</name>
<sureName>
Bravo
</sureName>
</pers2>
</persons>
Сам лотус скрипт:
Sub Click(Source As Button)
Dim session As NotesSession
Dim db As NotesDatabase
Dim inputStream As NotesStream, outputStream As NotesStream
Dim docNode As NotesDOMDocumentNode
Dim domParser As NotesDOMParser
Dim eNode As NotesDOMElementNode
Dim atr As notesDOMAttributeNode, asd As notesDOMAttributeNode
Dim origXML As String, outputFile As String
origXML = "c:\dxl\persons.xml"
outputFile = "c:\dxl\DOMtree.txt"
Set session = New NotesSession
Set db = session.CurrentDatabase
'create the output file
Set outputStream =session.CreateStream
outputStream.Open (outputFile)
outputStream.Truncate
'write report title
LF = Chr(13)+Chr(10)
outputStream.WriteText ("DOM Parser" )
outputStream.WriteText (LF)
'open the XML file
Set inputStream = session.CreateStream
inputStream.Open (origXML)
'create DOM parser and process
Set domParser=session.CreateDOMParser(inputStream, outputStream)
Call domParser.Serialize( )
domParser.Process
'get the document node
Set docNode = domParser.Document
Dim nDocument As Integer
If docNode.HasChildNodes Then
numChildNodes = docNode.NumberOfChildNodes ' 2 детки - pers1 и pers2
Dim documentList As NotesDOMNodeList
Set documentList = docNode.GetElementsByTagName ("pers1") ' ищем по тегу, а не дереву
nDocument = documentList.NumberOfEntries ' детка
For i = 1 To nDocument
Set eNode = documentList.GetItem(i) 'pers1
Set atr = eNode.GetAttributeNode("atr")
value$ =atr.AttributeValue
outputStream.WriteText(value$)
outputStream.WriteText (LF)
Set documentList = docNode.GetElementsByTagName ("name")
Set eNode = documentList.GetItem(1) 'name
Set asd = eNode.GetAttributeNode("asd")
value$ =asd.AttributeValue
outputStream.WriteText(value$)
outputStream.WriteText (LF)
Bart$ = eNode.lastchild.NodeValue ' содержимое ноды name
outputStream.WriteText(Bart$)
outputStream.WriteText (LF)
Set documentList = docNode.GetElementsByTagName ("sureName")
Set eNode = documentList.GetItem(1) 'sureName
Simps$ = eNode.lastchild.NodeValue ' содержимое ноды sureName
outputStream.WriteText(Simps$)
Next
End If
Call outputStream.Close
End Sub
NotesXMLProcessor - запускает парсер.
NotesDOMNode - корневой класс для работы с нодами, в нем есть подклассы для работы с узлами, атрибутами.