In my function GetStatutesByChapter, I would like to check if there is a section and or if there is a subdivion in the object aobjXmlGetStatuteRequestNode.
The reason I am checking is that these are optional so they may or may not be present.
I only want to create (add) them in object objXmlRequestMessageDoc only when they exist.
If the section and or subdivision exist, I want to add their value into the Object objXmlRequestMessageDoc.
Object aobjXmlGetStatuteRequestNode has this xml in it.
objXmlRequestMessageDoc object's xml should look like this if both section and subdivion are found in the aobjXmlGetStatuteRequestNode object and after they have been added.Code:<ns:GetStatutesRequest xmlns:ns="http://www.courts.state.mn.us/StatuteService/1.0"> <ns:Statute> <ns:Chapter>169</ns:Chapter> <!--Optional:--> <ns:Section>191</ns:Section> <!--Optional:--> <ns:Subdivision>a</ns:Subdivision> </ns:Statute> </ns:GetStatutesRequest>
If there is no section and or subdivion my objXmlRequestMessageDoc object will only have the chapter in it because chapter is not optional.Code:<ns:BasicSearchQueryRequest xmlns:ns="http://crimnet.state.mn.us/mnjustice/statute/service/4.0"> <ns1:BasicSearchCriteria xmlns:ns1="http://crimnet.state.mn.us/mnjustice/statute/messages/4.0"> <ns2:Chapter xmlns:ns2="http://crimnet.state.mn.us/mnjustice/statute/4.0"/169</ns2:Chapter>> <ns2:Section xmlns:ns2="http://crimnet.state.mn.us/mnjustice/statute/4.0"/>191</ns2:Chapter> <ns2:Subdivision xmlns:ns2="http://crimnet.state.mn.us/mnjustice/statute/4.0"/>a</ns2:Chapter> </ns1:BasicSearchCriteria> </ns:BasicSearchQueryRequest>
xml would look like this
Here is my functionCode:<ns:BasicSearchQueryRequest xmlns:ns="http://crimnet.state.mn.us/mnjustice/statute/service/4.0"> <ns1:BasicSearchCriteria xmlns:ns1="http://crimnet.state.mn.us/mnjustice/statute/messages/4.0"> <ns2:Chapter xmlns:ns2="http://crimnet.state.mn.us/mnjustice/statute/4.0"/169</ns2:Chapter>> </ns1:BasicSearchCriteria> </ns:BasicSearchQueryRequest>
If statement does not work because once it finds the first element (Section) it does not check for the second one (Subdivision) but it should.Code:''' <summary> ''' Process Get Statutes by Chapter ''' </summary> ''' <returns>Returns Chapter string in the objXmlStatutesDoc.</returns> ''' <remarks>Both Section and Subdivision are optional. Check if they exist</remarks> Function GetStatutesByChapter(ByVal aobjXmlGetStatuteRequestNode As XmlNode, ByVal aobjXMLNameSpaceManager As XmlNamespaceManager, ByVal aobjBroker As ServiceCatalog.Library.v4.Broker) As XmlDocument Dim objXmlRequestMessageDoc As XmlDocument Dim objXmlResponseMessageDoc As XmlDocument Dim intCount As Integer aobjBroker.PostMessageWarehouseInformationalMessage("Chapter found.", 1) 'set up the namespace manager objNameTable = New Xml.NameTable objXMLNameSpaceManager = New Xml.XmlNamespaceManager(objNameTable) objXMLNameSpaceManager.AddNamespace("soap", Msc.Integration.Utility.Library.v4.Soap.NamespaceUri(aobjBroker.SoapMessageVersion)) objXMLNameSpaceManager.AddNamespace("wsa", Msc.Integration.Utility.Library.v4.Soap.WsaNamespaceUri(aobjBroker.SoapMessageVersion)) objXMLNameSpaceManager.AddNamespace("ns1", "http://crimnet.state.mn.us/mnjustice/statute/messages/4.0") objXMLNameSpaceManager.AddNamespace("st", "http://crimnet.state.mn.us/mnjustice/statute/4.0") objXMLNameSpaceManager.AddNamespace("ss", "http://www.courts.state.mn.us/StatuteService/1.0") objXMLNameSpaceManager.AddNamespace("ns", "http://crimnet.state.mn.us/mnjustice/statute/service/4.0") objXmlResponseMessageDoc = New XmlDocument 'Add the first element into the document GetStatuteByChapter with its namespace objXmlResponseMessageDoc.AppendChild(objXmlResponseMessageDoc.CreateElement("BasicSearchQueryResponse", "http://crimnet.state.mn.us/mnjustice/statute/service/4.0")) objXmlResponseMessageDoc = New XmlDocument 'Add the first element into the document GetStatutesResponse with its namespace objXmlResponseMessageDoc.AppendChild(objXmlResponseMessageDoc.CreateElement("GetStatutesResponse", "http://www.courts.state.mn.us/StatuteService/1.0")) 'Add a child node to the GetStatutesResponse node objXmlResponseMessageDoc.SelectSingleNode("ss:GetStatutesResponse", aobjXMLNameSpaceManager).AppendChild(objXmlResponseMessageDoc.CreateElement("StatutesXml", "http://www.courts.state.mn.us/StatuteService/1.0")) objXmlResponseMessageDoc.SelectSingleNode("ss:GetStatutesResponse/ss:StatutesXml", aobjXMLNameSpaceManager).AppendChild(objXmlResponseMessageDoc.CreateElement("Statutes", "http://www.courts.state.mn.us/StatuteService/1.0")) 'Convert the node Statutes into an element and set the runType attribute (runType="Request") by adding it's value Request CType(objXmlResponseMessageDoc.SelectSingleNode("ss:GetStatutesResponse/ss:StatutesXml/ss:Statutes", aobjXMLNameSpaceManager), System.Xml.XmlElement).SetAttribute("runType", "Request") 'Convert the node Statutes into an element and set the attribute (runDateTime="2015-03-05T10:29:40") by adding it CType(objXmlResponseMessageDoc.SelectSingleNode("ss:GetStatutesResponse/ss:StatutesXml/ss:Statutes", aobjXMLNameSpaceManager), System.Xml.XmlElement).SetAttribute("runDateTime", Format(Now, "yyyy-MM-ddTHH:mm:ss")) 'check if there is a section and or subdivision if they exist add them and their value to the objXmlRequestMessageDoc If Then 'Add code here to check for Section and Subdivision. If they exist add their value to the objXmlRequestMessageDoc object like the way you added Chapter End If objXmlRequestMessageDoc.SelectSingleNode("ns:BasicSearchQueryRequest/ns1:BasicSearchCriteria", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns2:Subdivision", aobjXMLNameSpaceManager.LookupNamespace("st"))) objXmlRequestMessageDoc.DocumentElement.SelectSingleNode("ns1:BasicSearchCriteria/st:Chapter", aobjXMLNameSpaceManager).InnerText = aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Chapter", aobjXMLNameSpaceManager).InnerText aobjBroker.PostMessageWarehouseSnapshot(objXmlRequestMessageDoc.OuterXml, "Request Message", 1) Return objXmlResponseMessageDoc End Function
What's the best way to do this?


Reply With Quote
