我有xml文檔,我想在調試模式下使用vb 2010閱讀是否存在PetitionerNotification元素。 如何在Visual Studio中執行此操作? 這裏是我的XML代碼如何使用visual studio 2010代碼輸出xml節點元素
<IntegrationCondition Word="BCAPO" Description="BCA PO Notification">
<NotificationEvent notificationType="ProtectionOrderService" internalProtectionOrderID="218" protectionOrderNumber="1400218" servedByWord="FD0450002" servedByText="Argyle City Attorney" dateServed="10/29/2014" timeServed="" howServedWord="INPERSON" howServedText="In Person" whoWasServedInternalId="704461574" whoWasServed="Guardian" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">ServiceToSend</NotificationEvent>
<NotificationEvent notificationType="ProtectionOrderService" internalProtectionOrderID="218" protectionOrderNumber="1400218" servedByWord="ABBOTT" servedByText="Abbott House" dateServed="10/27/2014" timeServed="" howServedWord="INPERSON" howServedText="In Person" whoWasServedInternalId="672281003" whoWasServed="Respondent" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">ServiceToSend</NotificationEvent>
<NotificationEvent notificationType="PetitionerNotification" internalProtectionOrderID="218" protectionOrderNumber="1400218" petitionerEmailAddress="[email protected]" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">PetitionerNotification</NotificationEvent>
</IntegrationCondition>
這裏是我需要添加,如果檢查語句,如果XML已經petitionernotification元素我的Visual Studio代碼。
Option Strict On
Option Explicit On
Imports System.Xml
Public Class myUpdates
Shared Sub Main()
Dim objMessageProcessor As New MessageProcessor
Dim objSchemasCollection As New Msc.Integration.MessageBroker.Library.v4.SchemasCollection
Dim objTransformsCollection As New Msc.Integration.MessageBroker.Library.v4.TransformsCollection
objMessageProcessor.ProcessInputQueue(False, False, objSchemasCollection, objTransformsCollection)
End Sub
Private Class MessageProcessor
Inherits Msc.Integration.MessageBroker.Library.v4.XmlMessageProcessor
Protected Overrides Sub ProcessMessage(ByRef aobjBroker As MessageBroker.Library.v4.Broker, _
ByRef aobjXmlInputDoc As System.Xml.XmlDocument, ByRef aobjInstantiatedObjectsCollection As Microsoft.VisualBasic.Collection)
MyBase.ProcessMessage(aobjBroker, aobjXmlInputDoc, aobjInstantiatedObjectsCollection)
Dim strCaseNumber As String
Dim strProtectionOrderNumber As String
Dim objNameTable As NameTable
Dim objXMLNameSpaceManager As XmlNamespaceManager
Dim objXmlServiceNode As XmlNode
Dim objProtectionOrder As Msc.Integration.Dccis.Library.v4.ProtectionOrder
Dim objXmlCrossReferenceNode As XmlNode
Dim objCrossReferenceNumber As Msc.Integration.Dccis.Library.v4.ProtectionOrderCrossReferenceNumber
Dim intServedPartyID As Integer
Dim objCaseParties As List(Of Msc.Integration.Dccis.Library.v4.CaseParty)
Dim dtmDateServed As Date
Dim blnIncludesTime As Boolean
Dim objCaseEvent As Msc.Integration.Dccis.Library.v4.CaseEvent
Dim blnServiceFound As Boolean = False
Dim objUpdatesList As New List(Of Msc.Integration.Dccis.Library.v4.IApiObject)
'Validate the message
aobjBroker.ValidateXmlDocument(aobjXmlInputDoc, "ProtectionOrderLawEnforcementDataExchange_1_0.xsd", "NiemExchanges\ProtectionOrders\Exchange", , True)
'create a namespace manager used for queries into inputmessage (because of namespace)
objNameTable = New NameTable
objXMLNameSpaceManager = New XmlNamespaceManager(objNameTable)
objXMLNameSpaceManager.AddNamespace("ext", "http://www.courts.state.dc.us/ProtectionOrderExtension/1.0")
objXMLNameSpaceManager.AddNamespace("nc", "http://niem.gov/niem/niem-core/2.0")
strCaseNumber = aobjXmlInputDoc.DocumentElement.SelectSingleNode("ext:CourtFileNumber", objXMLNameSpaceManager).InnerText
strProtectionOrderNumber = aobjXmlInputDoc.DocumentElement.SelectSingleNode("ext:ProtectionOrderID", objXMLNameSpaceManager).InnerText
objProtectionOrder = Msc.Integration.Dccis.Library.v4.ProtectionOrder.Get(strCaseNumber, CInt(strProtectionOrderNumber), False)
objUpdatesList.Add(objProtectionOrder)
'Process service
For Each objXmlServiceNode In aobjXmlInputDoc.DocumentElement.SelectNodes("ext:ProtectionOrderService", objXMLNameSpaceManager)
If objXmlServiceNode.SelectSingleNode("ext:ProtectionOrderServiceTime", objXMLNameSpaceManager) Is Nothing Then
blnIncludesTime = False
dtmDateServed = CDate(objXmlServiceNode.SelectSingleNode("ext:ProtectionOrderServiceDate", objXMLNameSpaceManager).InnerText)
Else
blnIncludesTime = True
dtmDateServed = CDate(objXmlServiceNode.SelectSingleNode("ext:ProtectionOrderServiceDate", _
objXMLNameSpaceManager).InnerText + " " + objXmlServiceNode.SelectSingleNode("ext:ProtectionOrderServiceTime", objXMLNameSpaceManager).InnerText)
End If
intServedPartyID = 0
If objXmlServiceNode.SelectSingleNode("ext:ProtectionOrderServiceToCode", objXMLNameSpaceManager).InnerText = "Respondent" Then
'This must be the respondent
intServedPartyID = objProtectionOrder.RespondentInternalPartyID
objProtectionOrder.AddService(objXmlServiceNode.SelectSingleNode("ext:ProtectionOrderServiceAgency/nc:OrganizationIdentification/nc:IdentificationID", _
objXMLNameSpaceManager).InnerText, dtmDateServed, blnIncludesTime, objXmlServiceNode.SelectSingleNode("ext:ProtectionOrderServiceTypeCode", objXMLNameSpaceManager).InnerText, intServedPartyID)
blnServiceFound = True
Else
'This must be the Guardian
objCaseParties = Msc.Integration.DCcis.Library.v4.CaseParty.Get("GRD", strCaseNumber)
If objCaseParties.Count = 0 Then
aobjBroker.PostMessageWarehouseInformationalMessage("No active guardian found on the case – this service was not added to the protection order.", 1)
Else
intServedPartyID = objCaseParties.First.Party.InternalID
End If
If intServedPartyID <> 0 Then
objProtectionOrder.AddService(objXmlServiceNode.SelectSingleNode("ext:ProtectionOrderServiceAgency/nc:OrganizationIdentification/nc:IdentificationID", _
objXMLNameSpaceManager).InnerText, dtmDateServed, blnIncludesTime, objXmlServiceNode.SelectSingleNode("ext:ProtectionOrderServiceTypeCode", objXMLNameSpaceManager).InnerText, intServedPartyID)
blnServiceFound = True
End If
End If
Next
If blnServiceFound Then
objCaseEvent = New Msc.Integration.DCcis.Library.v4.CaseEvent("IBSERVNOT", Now, False, , strCaseNumber)
objUpdatesList.Add(objCaseEvent)
End If
'Process other identification
objXmlCrossReferenceNode = aobjXmlInputDoc.DocumentElement.SelectSingleNode("ext:ProtectionOrderOtherIdentification", objXMLNameSpaceManager)
If Not objXmlCrossReferenceNode Is Nothing Then
'Check if this ID is already in the protection order
For Each objCrossReferenceNumber In objProtectionOrder.CrossReferenceNumbers
If Not objCrossReferenceNumber.Number = objXmlCrossReferenceNode.SelectSingleNode("nc:IdentificationID", objXMLNameSpaceManager).InnerText And _
objCrossReferenceNumber.TypeCodeWord = objXmlCrossReferenceNode.SelectSingleNode("ext:ProtectionOrderOtherIdentificationTypeCode", _
objXMLNameSpaceManager).InnerText Then
'Throw New System.Exception("Protection Order " + strProtectionOrderNumber + " already has " + objCrossReferenceNumber.TypeText + " " + objCrossReferenceNumber.Number + " associated with it.")
Throw New System.Exception("This Protection Order already has an NCIC Number associated with it.")
End If
Next
'Add the cross reference
objProtectionOrder.AddCrossReferenceNumber(objXmlCrossReferenceNode.SelectSingleNode("ext:ProtectionOrderOtherIdentificationTypeCode", _
objXMLNameSpaceManager).InnerText, objXmlCrossReferenceNode.SelectSingleNode("nc:IdentificationID", objXMLNameSpaceManager).InnerText)
End If
'Save updates
Msc.Integration.DCcis.Library.v4.Odyssey.SaveUpdates(objUpdatesList)
End Sub
End Class
End Class
短語「PetitionerNotification」出現在您的示例XML文檔的兩個不同位置,但在任何地方都不能用作元素的名稱。在一個地方,它被用作'notificationType'屬性的值。在另一個地方,它被用作'NotificationEvent'元素的值。那麼,你打算尋找哪種條件?您是否想要查找具有等於「PetitionerNotification」的「notificationType」屬性的NotificationEvent元素,還是要查找具有「PetitionerNotification」值的「NotificationEvent」元素,還是兩者都需要? – 2014-10-29 18:42:01
我想找到NotificationEvent元素,它的notificationType屬性等於「PetitionerNotification」 – user3781064 2014-10-29 18:49:19