Пример обработки XML без LINQ
Этот же фрагмент кода, выполненный на LINQ
359: ...
360: Public Class PaymentProfileBankingCards
361:
362: Property toUser As String = ""
363: Property VISA_Module As String = ""
364: Property VISA_Code As String = ""
365: Property VISA_Comission As Decimal
366: Property VISA_DayLimit As Decimal
367: Property VISA_MounthLimit As Decimal
368: Property MC_Module As String = ""
369: Property MC_Code As String = ""
370: Property MC_Comission As Decimal
371: Property MC_DayLimit As Decimal
372: Property MC_MounthLimit As Decimal
373: Property DCL_Module As String = ""
374: Property DCL_Code As String = ""
375: Property DCL_Comission As Decimal
376: Property DCL_DayLimit As Decimal
377: Property DCL_MounthLimit As Decimal
378: Property JCB_Module As String = ""
379: Property JCB_Code As String = ""
380: Property JCB_Comission As Decimal
381: Property JCB_DayLimit As Decimal
382: Property JCB_MounthLimit As Decimal
383: Property AMEX_Module As String = ""
384: Property AMEX_Code As String = ""
385: Property AMEX_Comission As Decimal
386: Property AMEX_DayLimit As Decimal
387: Property AMEX_MounthLimit As Decimal
388:
389:
390: Public Sub SaveBankingCards()
391: Dim XML1 As New StringBuilder("<?xml version='1.0' encoding='UTF-16' ?>" & vbCrLf & "<BankingCards> " & vbCrLf)
392: XML1.Append("<VISA ")
393: If _VISA_Module <> "" Then XML1.Append("Module='" & _VISA_Module & "' ")
394: If _VISA_Code <> "" Then XML1.Append("Code='" & _VISA_Code & "' ")
395: If _VISA_Comission <> 0 Then XML1.Append("Comission='" & _VISA_Comission & "' ")
396: If _VISA_DayLimit <> 0 Then XML1.Append("DayLimit='" & _VISA_DayLimit & "' ")
397: If _VISA_MounthLimit <> 0 Then XML1.Append("MounthLimit='" & _VISA_MounthLimit & "' ")
398: XML1.AppendLine(" />")
399: XML1.Append("<MC ")
400: If _MC_Module <> "" Then XML1.Append("Module='" & _MC_Module & "' ")
401: If _MC_Code <> "" Then XML1.Append("Code='" & _MC_Code & "' ")
402: If _MC_Comission <> 0 Then XML1.Append("Comission='" & _MC_Comission & "' ")
403: If _MC_DayLimit <> 0 Then XML1.Append("DayLimit='" & _MC_DayLimit & "' ")
404: If _MC_MounthLimit <> 0 Then XML1.Append("MounthLimit='" & _MC_MounthLimit & "' ")
405: XML1.AppendLine(" />")
406: XML1.Append("<DCL ")
407: If _DCL_Module <> "" Then XML1.Append("Module='" & _DCL_Module & "' ")
408: If _DCL_Code <> "" Then XML1.Append("Code='" & _DCL_Code & "' ")
409: If _DCL_Comission <> 0 Then XML1.Append("Comission='" & _DCL_Comission & "' ")
410: If _DCL_DayLimit <> 0 Then XML1.Append("DayLimit='" & _DCL_DayLimit & "' ")
411: If _DCL_MounthLimit <> 0 Then XML1.Append("MounthLimit='" & _DCL_MounthLimit & "' ")
412: XML1.AppendLine(" />")
413: XML1.Append("<JCB ")
414: If _JCB_Module <> "" Then XML1.Append("Module='" & _JCB_Module & "' ")
415: If _JCB_Code <> "" Then XML1.Append("Code='" & _JCB_Code & "' ")
416: If _JCB_Comission <> 0 Then XML1.Append("Comission='" & _JCB_Comission & "' ")
417: If _JCB_DayLimit <> 0 Then XML1.Append("DayLimit='" & _JCB_DayLimit & "' ")
418: If _JCB_MounthLimit <> 0 Then XML1.Append("MounthLimit='" & _JCB_MounthLimit & "' ")
419: XML1.AppendLine(" />")
420: XML1.Append("<AMEX ")
421: If _AMEX_Module <> "" Then XML1.Append("Module='" & _AMEX_Module & "' ")
422: If _AMEX_Code <> "" Then XML1.Append("Code='" & _AMEX_Code & "' ")
423: If _AMEX_Comission <> 0 Then XML1.Append("Comission='" & _AMEX_Comission & "' ")
424: If _AMEX_DayLimit <> 0 Then XML1.Append("DayLimit='" & _AMEX_DayLimit & "' ")
425: If _AMEX_MounthLimit <> 0 Then XML1.Append("MounthLimit='" & _AMEX_MounthLimit & "' ")
426: XML1.AppendLine(" />")
427: XML1.Append("</BankingCards> ")
428: '
429: Dim WriteBankingCards As New VBNET2009.ExecSQL_RDR( _
430: "toUser", _toUser, _
431: "BankingCards", XML1.ToString)
432: WriteBankingCards.ExecSQL("SaveBankingCardsUserProfile", Data.CommandType.StoredProcedure)
433: WriteBankingCards.Close()
434: End Sub
435:
436: Public Sub ReadBankingCardsFromDB(ByVal UserID As String)
437: Dim BankingCardsProfile As New VBNET2009.ExecSQL_RDR("id", UserID)
438: Dim DR1 As Data.SqlClient.SqlDataReader = BankingCardsProfile.ExecSQL("select toUser,BankingCardsProfile from [Airts].[dbo].[UserPaymentProfile] with (nolock) where toUser=@ID", Data.CommandType.Text)
439: Dim Xml1 As New System.Xml.XmlDocument
440: If DR1.Read Then
441: _toUser = DR1("toUser").ToString
442: If Not IsDBNull(DR1("BankingCardsProfile")) Then
443: Xml1.LoadXml(DR1("BankingCardsProfile").Replace("UTF-16", "UTF-8"))
444: _VISA_Module = XMLService.GetTagText("/BankingCards/VISA/@Module", Xml1)
445: _VISA_Code = XMLService.GetTagText("/BankingCards/VISA/@Code", Xml1)
446: If XMLService.GetTagText("/BankingCards/VISA/@Comission", Xml1) <> "" Then
447: _VISA_Comission = CDec(XMLService.GetTagText("/BankingCards/VISA/@Comission", Xml1))
448: End If
449: If XMLService.GetTagText("/BankingCards/VISA/@DayLimit", Xml1) <> "" Then
450: _VISA_DayLimit = CDec(XMLService.GetTagText("/BankingCards/VISA/@DayLimit", Xml1))
451: End If
452: If XMLService.GetTagText("/BankingCards/VISA/@Comission", Xml1) <> "" Then
453: _VISA_MounthLimit = CDec(XMLService.GetTagText("/BankingCards/VISA/@MounthLimit", Xml1))
454: End If
455: _MC_Module = XMLService.GetTagText("/BankingCards/MC/@Module", Xml1)
456: _MC_Code = XMLService.GetTagText("/BankingCards/MC/@Code", Xml1)
457: If XMLService.GetTagText("/BankingCards/MC/@Comission", Xml1) <> "" Then
458: _MC_Comission = CDec(XMLService.GetTagText("/BankingCards/MC/@Comission", Xml1))
459: End If
460: If XMLService.GetTagText("/BankingCards/MC/@DayLimit", Xml1) <> "" Then
461: _MC_DayLimit = CDec(XMLService.GetTagText("/BankingCards/MC/@DayLimit", Xml1))
462: End If
463: If XMLService.GetTagText("/BankingCards/MC/@MounthLimit", Xml1) <> "" Then
464: _MC_MounthLimit = CDec(XMLService.GetTagText("/BankingCards/MC/@MounthLimit", Xml1))
465: End If
466: _DCL_Module = XMLService.GetTagText("/BankingCards/DCL/@Module", Xml1)
467: _DCL_Code = XMLService.GetTagText("/BankingCards/DCL/@Code", Xml1)
468: If XMLService.GetTagText("/BankingCards/DCL/@Comission", Xml1) <> "" Then
469: _DCL_Comission = CDec(XMLService.GetTagText("/BankingCards/DCL/@Comission", Xml1))
470: End If
471: If XMLService.GetTagText("/BankingCards/DCL/@DayLimit", Xml1) <> "" Then
472: _DCL_DayLimit = CDec(XMLService.GetTagText("/BankingCards/DCL/@DayLimit", Xml1))
473: End If
474: If XMLService.GetTagText("/BankingCards/DCL/@MounthLimit", Xml1) <> "" Then
475: _DCL_MounthLimit = CDec(XMLService.GetTagText("/BankingCards/DCL/@MounthLimit", Xml1))
476: End If
477: _JCB_Module = XMLService.GetTagText("/BankingCards/JCB/@Module", Xml1)
478: _JCB_Code = XMLService.GetTagText("/BankingCards/JCB/@Code", Xml1)
479: If XMLService.GetTagText("/BankingCards/JCB/@Comission", Xml1) <> "" Then
480: _JCB_Comission = CDec(XMLService.GetTagText("/BankingCards/JCB/@Comission", Xml1))
481: End If
482: If XMLService.GetTagText("/BankingCards/JCB/@DayLimit", Xml1) <> "" Then
483: _JCB_DayLimit = CDec(XMLService.GetTagText("/BankingCards/JCB/@DayLimit", Xml1))
484: End If
485: If XMLService.GetTagText("/BankingCards/JCB/@MounthLimit", Xml1) <> "" Then
486: _JCB_MounthLimit = CDec(XMLService.GetTagText("/BankingCards/JCB/@MounthLimit", Xml1))
487: End If
488: _AMEX_Module = XMLService.GetTagText("/BankingCards/AMEX/@Module", Xml1)
489: _AMEX_Code = XMLService.GetTagText("/BankingCards/AMEX/@Code", Xml1)
490: If XMLService.GetTagText("/BankingCards/AMEX/@Comission", Xml1) <> "" Then
491: _AMEX_Comission = CDec(XMLService.GetTagText("/BankingCards/AMEX/@Comission", Xml1))
492: End If
493: If XMLService.GetTagText("/BankingCards/AMEX/@DayLimit", Xml1) <> "" Then
494: _AMEX_DayLimit = CDec(XMLService.GetTagText("/BankingCards/AMEX/@DayLimit", Xml1))
495: End If
496: If XMLService.GetTagText("/BankingCards/AMEX/@MounthLimit", Xml1) <> "" Then
497: _AMEX_MounthLimit = CDec(XMLService.GetTagText("/BankingCards/AMEX/@MounthLimit", Xml1))
498: End If
499: End If
500: End If
501: BankingCardsProfile.Close()
502: End Sub
503:
504: End Class
521: ...
522: Public Class XMLService
523: Public Shared Function GetTagText(ByVal XqueryPatch As String, ByVal Node As System.Xml.XmlNode) As String
524: If Node.SelectNodes(XqueryPatch).Count > 0 Then
525: If Node.SelectNodes(XqueryPatch)(0) IsNot Nothing Then
526: Return Node.SelectNodes(XqueryPatch)(0).Value
527: Else
528: Return ("")
529: End If
530: Else
531: Return ("")
532: End If
533: End Function
534:
535: End Class
Comments (
)
Link to this page:
//www.vb-net.com/Linq/nolinq.htm
|