Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need help to create a xml GetCaseInformationResponseMessage message below from objXmlSimpleTypeDoc xml document.

I am trying to find SimpleTypeCompanion/EnumerationValue/@code node that matches the CourtNCIC value.

To get CourtNCIC, I am passing a case number to a method that finds CourtNCIC number.

Here is that method
objXmlMNCISData = Library.v4.Case.GetIxmlForCaseNumber(strCaseNumber, "CourtCaseHeaderGroup", False)
'Get CourtNCIC from the object
strCourtNCIC = objXmlMNCISData.DocumentElement.SelectSingleNode("Case/Court/CourtNCIC").InnerText

XML that I want to create

XML
<GetCaseInformationResponseMessage>
	<CourtLocation>
		<CourtName>McKnight County</CourtName>
		<ORINumber>MN010015J</ORINumber >
		<MNCISNodeID>222</MNCISNodeID>
		<PhoneNumber>800-001-7127</PhoneNumber>
	</CourtLocation>
</GetCaseInformationResponseMessage>


objXmlSimpleTypeDoc xml document
XML
<SimpleTypeCompanion enumerates="CourtLocationTextType">
	<EnumerationValue code="DC27ZAPPY">
		<Text>Zapy County</Text><!--/SimpleTypeCompanion/EnumerationValue[1]/Text-->
		<AssociatedValue type="MNCISNodeID">
			<Text>130</Text>
		</AssociatedValue>
		<AssociatedValue type="CountyName">
			<Text>Zapy</Text>
		</AssociatedValue>
		<AssociatedValue type="JudicialDistrict">
			<Text>40th</Text>
		</AssociatedValue>
	</EnumerationValue>
	<EnumerationValue code="MN010015J"><!--/SimpleTypeCompanion/EnumerationValue[2]/@code-->
		<Text>McKnight County</Text>
		<AssociatedValue type="MNCISNodeID">
			<Text>222</Text>
		</AssociatedValue>
		<AssociatedValue type="CountyName">
			<Text>Passaic</Text>
		</AssociatedValue>
		<AssociatedValue type="JudicialDistrict">
			<Text>11st</Text>
		</AssociatedValue>
		<AssociatedValue type="PhoneNumber">
			<Text>800-001-7127</Text>
		</AssociatedValue>
		<AssociatedValue type="FaxNumber">
			<Text>800-001-5555</Text>
		</AssociatedValue>
		<AssociatedValue type="Street1">
			<Text>234 Stension St</Text>
		</AssociatedValue>
		<AssociatedValue type="City">
			<Text>Spruce</Text>
		</AssociatedValue>
		<AssociatedValue type="State">
			<Text>WY</Text>
		</AssociatedValue>
		<AssociatedValue type="Zip">
			<Text>84327</Text>
		</AssociatedValue>
	</EnumerationValue>
</SimpleTypeCompanion>


What I have tried:

VB.NET code that I have tried
VB
Public Shared Sub ProcessGetCaseInformationRequestMessage(ByRef aobjBroker As ServiceCatalog.Library.v4.Broker, ByRef aobjXmlContentDoc As System.Xml.XmlDocument, ByRef aobjXmlNamespaceManager As System.Xml.XmlNamespaceManager)

    Dim objXmlMNCISData As XmlDocument
    Dim strCaseNumber As String
    Dim strCourtName As String
    Dim objXmlCourtLocationNode As XmlNode
    Dim objXmlResponseDoc As XmlDocument
    Dim strORINumber As String
    Dim strMNCISNodeID As String
    Dim strPhoneNumber As String
    Dim strCourtNCIC As String
    Dim objXmlSimpleTypeDoc As System.Xml.XmlDocument
    strCaseNumber = 
 aobjXmlContentDoc.DocumentElement.SelectSingleNode("m:CourtFileNumber", aobjXmlNamespaceManager).InnerText
    'Create the response message
    objXmlResponseDoc = New XmlDocument
    objXmlResponseDoc.AppendChild(objXmlResponseDoc.CreateElement("GetCaseInformationResponseMessage", aobjXmlNamespaceManager.LookupNamespace("m")))
    Try
      objXmlMNCISData = Library.v4.Case.GetIxmlForCaseNumber(strCaseNumber, "CourtCaseHeaderGroup", False) 'Gets XML with CourtNCIC number
      'CourtNCIC 
      strCourtNCIC = objXmlMNCISData.DocumentElement.SelectSingleNode("Case/Court/CourtNCIC").InnerText
      'Access the CourtLocationTextType simple type. 
      objXmlSimpleTypeDoc = Msc.Integration.CourtXml.Library.v4.SimpleType.GetCompanionFile("CourtLocationTextType")
      'Court location
      objXmlCourtLocationNode = objXmlResponseDoc.CreateElement("CourtLocation", aobjXmlNamespaceManager.LookupNamespace("m"))
	  
      'CourtName
      objXmlCourtLocationNode.AppendChild(objXmlResponseDoc.CreateElement("CourtName", aobjXmlNamespaceManager.LookupNamespace("m")))
      objXmlSimpleTypeDoc.DocumentElement.SelectSingleNode("m:EnumerationValue[@code=" + strCourtNCIC]/Text", aobjXmlNamespaceManager).InnerText = strCourtName
	  
      'ORINumber
      objXmlCourtLocationNode.AppendChild(objXmlResponseDoc.CreateElement("ORINumber", aobjXmlNamespaceManager.LookupNamespace("m")))
      objXmlSimpleTypeDoc.DocumentElement.SelectSingleNode("m:CourtName", aobjXmlNamespaceManager).InnerText = strORINumber
	  
     'MNCISNode ID SimpleTypeCompanion\EnumerationValue\AssociatedValue\Text
     objXmlCourtLocationNode.AppendChild(objXmlResponseDoc.CreateElement("CourtName", aobjXmlNamespaceManager.LookupNamespace("m")))
     objXmlSimpleTypeDoc.DocumentElement.SelectSingleNode("m:CourtName", aobjXmlNamespaceManager).InnerText = strMNCISNodeID
	 
    'PhoneNumber 
    objXmlCourtLocationNode.AppendChild(objXmlResponseDoc.CreateElement("PhoneNumber", aobjXmlNamespaceManager.LookupNamespace("m")))
    objXmlSimpleTypeDoc.DocumentElement,SelectSingleNode("m:CourtName", aobjXmlNamespaceManager).InnerText = PhoneNumber
End Sub
Posted
Updated 20-Aug-19 2:17am
v2
Comments
Maciej Los 30-Jul-19 15:35pm    
You should post this question to provider of "Library"....
Member 11403304 2-Aug-19 11:24am    
I will ask this question in a more simplified manner.

1 solution

Try this:

VB.NET
Public Shared Function GetTargetXmlDoc(objXmlMNCISData As XmlDocument) As XmlDocument

	'create target XmlDocument 
	Dim objTargetDoc As XmlDocument =  New XmlDocument()
	'create root element
	Dim root As XmlElement = objTargetDoc.CreateElement("GetCaseInformationResponseMessage")
	
	'read EnumerationValue nodes
	Dim nodes As XmlNodeList = objXmlMNCISData.SelectNodes("/SimpleTypeCompanion[@*]/EnumerationValue[@*]")
	For Each node As XmlNode In nodes
		'create CourtLocation node
		Dim courtLocation As XmlElement = objTargetDoc.CreateElement("CourtLocation")
		'read court name and create CourtName node
		Dim tmp As String = node.SelectSingleNode("Text").InnerText
		Dim courtname As XmlElement = objTargetDoc.CreateElement("CourtName")
		courtname.InnerText = tmp
		'read code and create ORINumber node
		tmp = node.Attributes("code").Value
		Dim oriNumber As XmlElement = objTargetDoc.CreateElement("ORINumber")
		oriNumber.InnerText = tmp
		'read MNCISNodeID  and create MNCISNodeID node
		tmp = node.SelectSingleNode("AssociatedValue[@type='MNCISNodeID']/Text").InnerText
		Dim nodeID As XmlElement = objTargetDoc.CreateElement("MNCISNodeID")
		nodeID.InnerText = tmp
		'read PhoneNumber and create PhoneNumber node
		Dim phoneNo As XmlElement = objTargetDoc.CreateElement("PhoneNumber")
		'check if PhoneNumber exists
		Try
			tmp = node.SelectSingleNode("AssociatedValue[@type='PhoneNumber']/Text").InnerText
			phoneNo.InnerText = tmp
		Catch ex As Exception 
			'ignore "Object reference not set to an instance of an object."
			'Console.WriteLine(ex.Message) 
			tmp = ""
		End Try
		'add subnodes to courtLocation node
		With courtLocation
			.AppendChild(courtname)
			.AppendChild(oriNumber)
			.AppendChild(nodeID)
			.AppendChild(phoneNo)
		End With
		'add courtLocation node to root node
		root.AppendChild(courtLocation)
	Next
	'add root node to the document
	objTargetDoc.AppendChild(root)

   	Return objTargetDoc
End Sub


Result:
HTML
<GetCaseInformationResponseMessage>
   <CourtLocation>
      <CourtName>Zapy County</CourtName>
      <ORINumber>DC27ZAPPY</ORINumber>
      <MNCISNodeID>130</MNCISNodeID>
      <PhoneNumber />
   </CourtLocation>
   <CourtLocation>
      <CourtName>McKnight County</CourtName>
      <ORINumber>MN010015J</ORINumber>
      <MNCISNodeID>222</MNCISNodeID>
      <PhoneNumber>800-001-7127</PhoneNumber>
   </CourtLocation>
</GetCaseInformationResponseMessage>


For further details, please see: XmlDocument Class (System.Xml) | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900