Xml парсер в Bcb6
(пробовал ковыряться с классом TXMLDocument, XML парсит, а как извлечь из него элементы, списки нод), экземпляры класса TXMLDocument должны создаваться на лету (типа TXMLDocument *xmldoc;) (я ранее писал Jabber сервер на VB все отлично работало, и сообщения слал, и все основные JEP-сы поддерживал (кроме мультичата), теперь хочу переложить на BCB) .... мне нужен конкретный пример использования XMLDocument, IXMLDOMElement, IXMLDOMNode.
Кусок кода на VB (для примера, выполняет обработку запросов типа get)
Private Sub ProcessGet(lSocket As Long, xmlNode As MSXML2.IXMLDOMElement)
Dim a As MSXML2.IXMLDOMElement
Dim b As MSXML2.IXMLDOMElement
Dim c As MSXML2.IXMLDOMNode
Dim d As MSXML2.IXMLDOMNode
Dim e As MSXML2.IXMLDOMElement
Set b = xmlNode.firstChild
Set c = xmlNode.firstChild
If b.tagName = "vCard" Then
If b.getAttribute("xmlns") = "vcard-temp" Then
tos$ = CTS(xmlNode.getAttribute("to"))
If tos$ = "" Then Exit Sub
If GetHost(tos$) = ServerName Then
mdlDB.SendVcard lSocket, GetID(tos$)
End If
End If
End If
If b.tagName = "offline" Then
If b.getAttribute("xmlns") = "http://jabber.org/protocol/offline" Then
For z = 0 To b.childNodes.length - 1
Set d = b.childNodes(z)
If CTS(e.nodeName) = "fetch" Then
mdlDB.Fetch lSocket, CTS(xmlNode.getAttribute("id"))
End If
If CTS(e.nodeName) = "item" Then
If CTS(e.getAttribute("action")) = "view" Then
mdlDB.SendOfflineMessage lSocket, CTS(xmlNode.getAttribute("id")), CTS(b.getAttribute("node"))
End If
End If
Next
End If
End If
If b.tagName = "query" Then
If b.getAttribute("xmlns") = "jabber:iq:auth" Then
For z = 0 To b.childNodes.length - 1
Set d = b.childNodes.Item(z)
If d.nodeName = "username" Then sUser$ = CTS(d.Text): su = 1
If d.nodeName = "password" Then sPass$ = CTS(d.Text): sp = 1
If d.nodeName = "resource" Then sRes$ = CTS(d.Text): ss = 1
Next
If su = 1 And sp = 1 Then
mdlManager.jabber_iq_auth lSocket, xmlNode.getAttribute("id"), sUser$, sPass$, sRes$
Else
If Dir$(App.Path + "\spool\users\" + sUser$) <> "" Then
Send lSocket, "<iq type='error' id='" + xmlNode.getAttribute("id") + "'>"
Send lSocket, "<query xmlns='jabber:iq:auth'>"
Send lSocket, "<username>" + sUser$ + "</username>"
Send lSocket, "</query>"
Send lSocket, "<error code='401'>Unauthorized</error>"
Send lSocket, "</iq>"
Else
Send lSocket, "<iq type='result' id='" + xmlNode.getAttribute("id") + "'><query xmlns='jabber:iq:auth'><username>cvb</username><digest/><password/><resource/></query></iq>"
End If
End If
frmMain.RefreshList
End If
If b.getAttribute("xmlns") = "jabber:iq:register" Then
'Send lSocket, "<iq type='result' id='" + xmlNode.getAttribute("id") + "' from='" + Cons(lSocket).Jid + "/" + Cons(lSocket).Resource + "'><query xmlns='jabber:iq:private'>" + sRes$ + "</query></iq>"
Send lSocket, "<iq type='result' id='" + xmlNode.getAttribute("id") + "'><query xmlns='jabber:iq:register'><password/><password/>" + vbCrLf
Send lSocket, "<instructions>Choose a username and password to register with this server.</instructions>" + vbCrLf
Send lSocket, "<name/>" + vbCrLf
Send lSocket, "<email/>" + vbCrLf
Send lSocket, "<username/></query></iq>"
End If
If b.getAttribute("xmlns") = "jabber:iq:private" Then
For z = 0 To b.childNodes.length - 1
Set d = b.childNodes(z)
sRes$ = sRes$ + d.xml
Next
sRes$ = ""
Send lSocket, "<iq type='result' id='" + xmlNode.getAttribute("id") + "' from='" + Cons(lSocket).Jid + "@" + ServerName + "/" + Cons(lSocket).Resource + "'><query xmlns='jabber:iq:private'>" + sRes$ + "</query></iq>"
End If
If b.getAttribute("xmlns") = "jabber:iq:roster" Then
'àâòîðèçàöèÿ
If CTS(xmlNode.getAttribute("id")) = "" Then
Send lSocket, "<iq type='result' from='" + Cons(lSocket).Jid + "@" + ServerName + "/" + Cons(lSocket).Resource + "'><query xmlns='jabber:iq:roster'/></iq>"
Else
Send lSocket, "<iq type='result' id='" + CTS(xmlNode.getAttribute("id")) + "' from='" + Cons(lSocket).Jid + "@" + ServerName + "/" + Cons(lSocket).Resource + "'><query xmlns='jabber:iq:roster'></query></iq>"
End If
End If
If b.getAttribute("xmlns") = "jabber:iq:browse" Then
Send lSocket, "<iq type='result' to='" + Cons(lSocket).Jid + "@" + ServerName + "/" + Cons(lSocket).Resource + "' from='" + ServerName + "'>"
Send lSocket, "<service xmlns='jabber:iq:browse' type='jabber' jid='" + ServerName + "' name='Jabber Server'>"
Send lSocket, "<service type='jud' jid='jud." + ServerName + "' name='Jabber User Directory'>"
Send lSocket, "<ns>jabber:iq:search</ns><ns>jabber:iq:register</ns>"
Send lSocket, "</service>"
Send lSocket, "<item category='conference' type='public' jid='conference." + ServerName + "' name='Public Conferencing' version='" + Trim$(Str$(App.Major)) + "." + Trim$(Str$(App.Minor)) + "." + Trim$(Str$(App.Revision)) + "'>"
Send lSocket, "<ns>jabber:iq:register</ns><ns>http://jabber.org/protocol/muc</ns>"
Send lSocket, "</item></service></iq>"
End If
If b.getAttribute("xmlns") = "jabber:iq:search" Then
Send lSocket, "<iq type='result' to='" + Cons(lSocket).Jid + "@" + ServerName + "/" + Cons(lSocket).Resource + "' id='" + CTS(xmlNode.getAttribute("id")) + "' from='jud." + ServerName + "'>"
Send lSocket, "<query xmlns='jabber:iq:search'>"
Send lSocket, "<instructions>Fill in a field to search for any matching Jabber User</instructions>"
Send lSocket, "<name/><first/><last/><nick/><email/></query>"
Send lSocket, "</iq>"
End If
If b.getAttribute("xmlns") = "http://jabber.org/protocol/disco#info" Then
If CTS(xmlNode.getAttribute("to")) = ServerName Then
Send lSocket, "<iq type='result' from='" + ServerName + "' to='" + Cons(lSocket).Jid + "@" + ServerName + "/" + Cons(lSocket).Resource + "' id='" + CTS(xmlNode.getAttribute("id")) + "'>"
Send lSocket, "<query xmlns='http://jabber.org/protocol/disco#info'/>"
Send lSocket, "<feature var='http://jabber.org/protocol/offline'/>"
Send lSocket, "<identity category='conference' name='Multi User Conference' type='text'/>"
Send lSocket, "<feature var='http://jabber.org/protocol/muc'/>"
Send lSocket, "</iq>"
End If
If CTS(xmlNode.getAttribute("to")) = ServerName Then
End If
End If
If CTS(b.getAttribute("xmlns")) = "http://jabber.org/protocol/disco#items" Then
If CTS(b.getAttribute("node")) = "http://jabber.org/protocol/offline" Then
mdlDB.SendOfflineHeaders lSocket, CTS(xmlNode.getAttribute("id"))
End If
If CTS(b.getAttribute("node")) = "http://jabber.org/protocol/offline" Then
mdlDB.SendOfflineHeaders lSocket, CTS(xmlNode.getAttribute("id"))
End If
End If
End If
End Sub