Member 11403304 Ответов: 1

Как создать новый документ со значениями элементов?


Мне нужна помощь, чтобы создать сообщение xml GetCaseInformationResponseMessage ниже из XML-документа objXmlSimpleTypeDoc.

Я пытаюсь найти узел SimpleTypeCompanion/EnumerationValue/@code, который соответствует значению CourtNCIC.

Чтобы получить CourtNCIC, я передаю номер дела методу, который находит номер CourtNCIC.

Вот этот метод
objXmlMNCISData = Library.v4.Case.GetIxmlForCaseNumber(strCaseNumber, "CourtCaseHeaderGroup", False)
- Уберите Кортнсика с объекта
strCourtNCIC = objXmlMNCISData.Функцию documentelement.SelectSingleNode("Case/Court/CourtNCIC").Через свойство innerText

XML, который я хочу создать

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


XML-документ objXmlSimpleTypeDoc
<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>


Что я уже пробовал:

VB.NET код, который я пробовал
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

Maciej Los

Вы должны отправить этот вопрос поставщику "библиотеки"....

Member 11403304

Я задам этот вопрос в более упрощенном виде.

1 Ответов

Рейтинг:
1

Maciej Los

Попробовать это:

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


Результат:
<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>


Для получения более подробной информации, пожалуйста, смотрите: Класс XmlDocument (System.Xml) | Microsoft Docs[^]