How do I create new xml document from another xml document?

  • Thread starter Thread starter winkimjr2
  • Start date Start date
W

winkimjr2

Guest
I am using C# and need to create a new xml document based on sample original xml document. I have 2 samples of what the new document should look like. I also have an original document that my code will read to get element values to create the new xml document.

aobjXmlInputDoc can represent many different documents which C# have to read and then based on notification at the bottom, create a new xml document.


objPrepHearDoc is an object which has various nodes to be created for new xml message.


Can someone help?

Here is a xml document with Setting Held notification at the bottom which C# should read and create a sample message. This in C# is in aobjXmlInputDoc

<Integration>
<Case>
<CaseNumber>62-CR-16-844</CaseNumber>
<Hearing ID="198305249" Op="E" xmlns:reslib="urn:reslib">
<HearingType Word="ACT">Type Hearing</HearingType>
<HearingComment>Some comment</HearingComment>
<Setting ID="28647874" Date="08/31/2018" Op="E">
<HearingDate>08/31/2018</HearingDate>
<CourtSessionBlock InternalCourtSessionBlockID="1616333655">
<StartTime>1:15 PM</StartTime>
<EndTime>1:15 PM</EndTime>
</CourtSessionBlock>
<CourtroomMinutes Op="A">
<HearingResult Op="E" Word="HELD">Held</HearingResult>
</CourtroomMinutes>
</Setting>
</Hearing>
</Case>
<IntegrationConditions>
<IntegrationCondition Word="HRGTRLSET" Description="HearingTrialSetting">
<NotificationEvent notificationType="PrepareHearingDocument" elementState="Existing" elementName="Setting" elementKey="198305249" subElementKey="28647874">SettingHeld</NotificationEvent>
</IntegrationCondition>
</IntegrationConditions>
</Integration>



This in C# is in aobjXmlInputDoc

Here is second original document with Hearing Scheduled notification at the bottom.

<?xml version="1.0" encoding="UTF-8"?>
<Integration>
<Case>
<CaseNumber>62-VB-19-27</CaseNumber>
<Hearing ID="252919460" Op="A">
<HearingType Op="A" Word="ACT">Hearing Appointment</HearingType>
<HearingComment>Some comment</HearingComment>
<Setting ID="32178675" InternalSettingID="1631575987" Date="01/22/2019" Op="A">
<HearingDate Op="A">01/22/2019</HearingDate>
<CourtSessionBlock InternalCourtSessionBlockID="1617068812">
<StartTime Op="A">9:00 AM</StartTime>
<EndTime Op="A">9:15 AM</EndTime>
</CourtSessionBlock>
</Setting>
</Hearing>
</Case>
<IntegrationConditions>
<IntegrationCondition Word="HRGTRLSET" Description="HearingTrialSetting">
<NotificationEvent notificationType="HearingTrialSettingNotification" elementState="New" elementName="Hearing" elementKey="252919460">HearingScheduled</NotificationEvent>
</IntegrationCondition>
</IntegrationConditions>
</Integration>



When aobjXmlInputDoc has HearingScheduled notification at the bottom, my C# should create the following sample message.

<PrepareHearingDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="PrepareHearingDocument.xsd">
<CaseNumber>70-PR-18-8</CaseNumber>
<MessageEvent>HearingScheduled</MessageEvent>
<Hearing hearingKey="252918946">
<HearingTypeText code="ACT">Account Hearing</HearingTypeText>
<HearingCommentText>Some random thought</HearingCommentText>
<Setting settingKey="32178453">
<HearingDateTimes>
<HearingDatetimeStart>2019-01-07T08:30:00-06:00</HearingDatetimeStart>
<HearingDatetimeEnd>2019-01-07T08:45:00-06:00</HearingDatetimeEnd>
</HearingDateTimes>
<SettingStatus>Scheduled</SettingStatus>
</Setting>
</Hearing>
</PrepareHearingDocument>


Setting Held is another sample message that will be create when aobjXmlInputDoc has SettingHeld notification at the bottom.

<PrepareHearingDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="PrepareHearingDocument.xsd">
<CaseNumber>70-PR-18-8</CaseNumber>
<MessageEvent settingKey="32178454">SettingHeld</MessageEvent>
<Hearing hearingKey="252918946">
<HearingTypeText code="ACT">Account Hearing</HearingTypeText>
<HearingCommentText>Some random thought</HearingCommentText>
<Setting settingKey="32178453">
<HearingDateTimes>
<HearingDatetimeStart>2019-01-07T08:30:00-06:00</HearingDatetimeStart>
<HearingDatetimeEnd>2019-01-07T08:45:00-06:00</HearingDatetimeEnd>
</HearingDateTimes>
<SettingStatus>Cancelled</SettingStatus>
</Setting>
<Setting settingKey="32178454">
<HearingDateTimes>
<HearingDatetimeStart>2019-01-07T08:30:00-06:00</HearingDatetimeStart>
<HearingDatetimeEnd>2019-01-07T08:45:00-06:00</HearingDatetimeEnd>
</HearingDateTimes>
<SettingStatus>Held</SettingStatus>
</Setting>
</Hearing>
</PrepareHearingDocument>


My C# class

using System.Xml;
using System.Security.Cryptography;
namespace Msc.Integration.Mncis.Service.v4
{
class PrepareHearingDocument : CamperUpdates
{
public void ProcessPrepareHearingDocument(ref Msc.Integration.MessageBroker.Library.v4.Broker aobjBroker, ref System.Xml.XmlDocument aobjXmlInputDoc, ref Microsoft.VisualBasic.Collection aobjInstantiatedObjectsCollection, XmlNode aobjxmNotificationEventNode)
{
aobjBroker.PostMessageWarehouseInformationalMessage("Processing an PrepareHearingDocument message", 1);
ConservatorService.PrepareHearingDocument objPrepHearDoc = new ConservatorService.PrepareHearingDocument();



//Connect to MMC webservice
ConservatorService.ConservatorServiceClient objConService = GetServiceClient(ref aobjBroker);

//Get elementKey
string strEventId = aobjxmNotificationEventNode.SelectSingleNode("@elementKey").InnerText;
//Get CaseNumber
objPrepHearDoc.CaseNumber = aobjXmlInputDoc.DocumentElement.SelectSingleNode("Case/CaseNumber").InnerText;
}
}
}






Continue reading...
 
Back
Top