How to identify duplicate value in XML file using (c#)? - c#

Hi I have XML file as below. I need to check for duplicate value inside and if any duplicate found then I need to trigger a notification mail of its existence. Inner text of must be unique for the whole XML file.
From the below file I have 2 value(inner text) of are same. So how do I write the code to identify these duplicate and trigger a notification mail using (c#). sample code will be much appreciable.
<?xml version="1.0" encoding="utf-8"?>
<JobsMapper>
<Platform>
<Platform_Data Name="GLP" ServerName="Lydsyd119" Input_Location="\\10.51.226.65\FTK_Production\IO\FileWatcherIO\GLP\GLP\"/>
<External_Delete_Request InstanceName="archive" DestinationFolder="\\10.51.226.65\FTK Production Release\FTK_Production\IO\FabricationIO\ExternalDeleteRequest\ExternalDelete\INPUT\"/>
<Archival InstanceName="archive" DestinationFolder="\\10.51.226.65\FTK_Production\IO\FabricationIO\Archive\BundleArchive\INPUT\"/>
<Job InstanceName="0018" DestinationFolder="\\10.51.226.65\FTK_Production\IO\FabricationIO\0018\MixedContent\INPUT\">
<DPSI>0018</DPSI>
</Job>
<Job InstanceName="0019" DestinationFolder="\\10.51.226.65\FTK_Production\IO\FabricationIO\0019\MixedContent\INPUT\">
<DPSI>0019</DPSI>
</Job>
<Job InstanceName="0CPN" DestinationFolder="\\10.51.226.65\FTK_Production\IO\FabricationIO\0CPN\MixedContent\INPUT\">
<DPSI>0CPN</DPSI>
</Job>
<Job InstanceName="0011" DestinationFolder="\\10.51.226.65\FTK_Production\IO\FabricationIO\0011\MixedContent\INPUT\">
<DPSI>0011</DPSI>
</Job>
<Job InstanceName="0011" DestinationFolder="\\10.51.226.65\FTK_Production\IO\FabricationIO\0011\MixedContent\INPUT\">
<DPSI>0011</DPSI>
</Job>
<Job InstanceName="000S" DestinationFolder="\\10.51.226.65\FTK_Production\IO\FabricationIO\000S\MixedContent\INPUT\">
<DPSI>000S</DPSI>
</Job>
<Job InstanceName="06JW" DestinationFolder="\\10.51.226.65\FTK_Production\IO\FabricationIO\06JW\MixedContent\INPUT\">
<DPSI>06JW</DPSI>
</Job>
<Job InstanceName="0N2Z" DestinationFolder="\\10.51.226.65\FTK_Production\IO\FabricationIO\0N2Z\MixedContent\INPUT\">
<DPSI>0N2Z</DPSI>
</Job>
<Job InstanceName="0HNQ" DestinationFolder="\\10.51.226.65\FTK_Production\IO\FabricationIO\0HNQ\MixedContent\INPUT\">
<DPSI>0HNQ</DPSI>
</Job>
<Job InstanceName="000Z" DestinationFolder="\\10.51.226.65\FTK_Production\IO\FabricationIO\000Z\MixedContent\INPUT\">
<DPSI>000Z</DPSI>
</Job>
<Job InstanceName="000W" DestinationFolder="\\10.51.226.65\FTK_Production\IO\FabricationIO\000W\MixedContent\INPUT\">
<DPSI>000W</DPSI>
</Job>
<Job InstanceName="0014" DestinationFolder="\\10.51.226.65\FTK_Production\IO\FabricationIO\0014\MixedContent\INPUT\">
<DPSI>0014</DPSI>
</Job>
</Platform>
</JobsMapper>

The following code will let you know how many nodes have duplicate values.
var result = XDocument.Parse(xml)
.Descendants("DPSI")
.GroupBy(x => x.Value)
.Where(x => x.Count() > 1);

Related

Removing Attribute value based on value from an XML using VB.Net

I have an XML as below
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope
xmlns="http://com/uhg/uht/uhtSoapMsg_V1"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header>
<uhtHeader
xmlns="http://com/uhg/uht/uhtHeader_V1">
<consumer>COMET</consumer>
<auditId></auditId>
<sendTimestamp>2020-09-03T18:15:40.942-05:00</sendTimestamp>
<environment>P</environment>
<businessService version="24">getClaimHistory</businessService>
<status>success</status>
</uhtHeader>
</env:Header>
<env:Body>
<srvcRspn
xmlns="http://com/uhg/uht/getClaimHistory_V24">
<srvcErrList arrayType="srvcErrOccur[1]" type="Array">
<srvcErrOccur>
<orig>Foundation</orig>
<rtnCd>00</rtnCd>
<explCd>000</explCd>
<desc></desc>
</srvcErrOccur>
</SrvcErrList>
</srvcRspn>
</env:Body>
</env:Envelope>
I want to remove all the attribute values with "http" like below:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope
xmlns=""
xmlns:env="">
<env:Header>
<uhtHeader
xmlns="">
<consumer>COMET</consumer>
<auditId></auditId>
<sendTimestamp>2020-09-03T18:15:40.942-05:00</sendTimestamp>
<environment>P</environment>
<businessService version="24">getClaimHistory</businessService>
<status>success</status>
</uhtHeader>
</env:Header>
<env:Body>
<srvcRspn
xmlns="">
<srvcErrList arrayType="srvcErrOccur[1]" type="Array">
<srvcErrOccur>
<orig>Foundation</orig>
<rtnCd>00</rtnCd>
<explCd>000</explCd>
<desc></desc>
</srvcErrOccur>
</SrvcErrList>
</srvcRspn>
</env:Body>
</env:Envelope>
I have tried several ways but none of them has worked for me. Can anyone suggest what is fastest way to do it in VB.NET/C#.
The actual response is very large (approx 100000 lines of XML minimum) and using for each will consume a good amount of time. Is there any parsing method or LINQ query method which can do it faster.
I got the way to do it using Regex as below:
Return Regex.Replace(xmlDoc, "((?<=<|<\/)|(?<= ))[A-Za-z0-9]+:| xmlns(:[A-Za-z0-9]+)?="".*?""", "")
It serves my purpose completely. Thanks Cleptus for your quick reference.

VS Generated WSDL Namespace Issues

Good Afternoon,
We have been trying to consume a Carrier API, but have hit some issue with the WSDL Generation. The Example XML message the company has provided has ns1-3 and appears that it is important for the address fields. the XML generated from their WSDL seems to generate the same fields but has no name spaces like the original and fails with "Address details are invalid", Is there some setting we are missing so that it generates the correct XML?
This is their Example XML
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns3:CreateLabel xmlns:ns3="http://courier.ck.dx.metafour.com/" xmlns:ns2="http://www.thedx.co.uk/eai/canonical/types/v2.0">
<order>
<ns2:customerID>14337622</ns2:customerID>
<ns2:dates>
<date format="yyyy-MM-dd HH:mm:ss" type="requestedCollectionDate">2018-12-12 17:59:21</date>
</ns2:dates>
<sourceSystemReference xmlns="http://www.thedx.co.uk/eai/canonical/types/v2.0">AMS207554</sourceSystemReference>
<customerReference xmlns="http://www.thedx.co.uk/eai/canonical/types/v2.0">286956</customerReference>
<orderAttributes xmlns="http://www.thedx.co.uk/eai/canonical/types/v2.0" xsi:nil="true" />
<ns2:orderLines>
<ns2:consignment>
<pieces>
<dimensions>
<value>1.0</value>
<type>cdlWeight</type>
<UOM>KG</UOM>
</dimensions>
<barcode xsi:nil="true" />
<trackingNumber xsi:nil="true" />
</pieces>
<qty>1</qty>
<legacyService>
<name>serviceLevel</name>
<partyId>0</partyId>
<partyType>HITS</partyType>
</legacyService>
<legacyService>
<name>serviceType</name>
<partyId>2</partyId>
<partyType>HITS</partyType>
</legacyService>
<deliverTo>
<ns2:address primary="true">
<organisationName>Argos</organisationName>
<addressLine1>Argos</addressLine1>
<addressLine2>Argos Ltd</addressLine2>
<addressLine3>11 Canning Street</addressLine3>
<city>BURNLEY</city>
<postalCode>BB12 0AD</postalCode>
<country>
<countryCode>GB</countryCode>
<description>GB</description>
</country>
</ns2:address>
<contact />
</deliverTo>
</ns2:consignment>
</ns2:orderLines>
<labelType>ZPL</labelType>
</order>
<serviceHeader>
<password>test</password>
<userId>test</userId>
</serviceHeader>
</ns3:CreateLabel>
</s:Body>
</s:Envelope>
This is our Generated XML
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<CreateLabel xmlns="http://courier.ck.dx.metafour.com/">
<order xmlns="">
<customerID xmlns="http://www.thedx.co.uk/eai/canonical/types/v2.0">14337622</customerID>
<dates xmlns="http://www.thedx.co.uk/eai/canonical/types/v2.0">
<date xmlns="" format="yyyy-MM-dd HH:mm:ss" type="requestedCollectionDate">2019-01-25 10:17:33</date>
</dates>
<sourceSystemReference xmlns="http://www.thedx.co.uk/eai/canonical/types/v2.0">AMS207554</sourceSystemReference>
<customerReference xmlns="http://www.thedx.co.uk/eai/canonical/types/v2.0">286956</customerReference>
<orderAttributes xmlns="http://www.thedx.co.uk/eai/canonical/types/v2.0" xsi:nil="true" />
<orderLines xmlns="http://www.thedx.co.uk/eai/canonical/types/v2.0">
<consignment>
<pieces xmlns="">
<dimensions>
<value>1.0</value>
<type>cdlWeight</type>
<UOM>KG</UOM>
</dimensions>
<barcode xsi:nil="true" />
<trackingNumber xsi:nil="true" />
</pieces>
<qty>1</qty>
<legacyService xmlns="">
<name>serviceLevel</name>
<partyId>0</partyId>
<partyType>HITS</partyType>
</legacyService>
<legacyService xmlns="">
<name>serviceType</name>
<partyId>2</partyId>
<partyType>HITS</partyType>
</legacyService>
<deliverTo xmlns="">
<address xmlns="http://www.thedx.co.uk/eai/canonical/types/v2.0">
<organisationName xmlns="">Argos</organisationName>
<addressLine1 xmlns="">Argos</addressLine1>
<addressLine2 xmlns="">Argos Ltd</addressLine2>
<addressLine3 xmlns="">11 Canning Street</addressLine3>
<city xmlns="">BURNLEY</city>
<postalCode xmlns="">BB12 0AD</postalCode>
<country xmlns="">
<countryCode>GB</countryCode>
<description>GB</description>
</country>
</address>
<contact xmlns="http://www.thedx.co.uk/eai/canonical/types/v2.0" />
</deliverTo>
</consignment>
</orderLines>
<labelType>ZPL</labelType>
</order>
<serviceHeader xmlns="">
<password>test</password>
<userId>test</userId>
</serviceHeader>
</CreateLabel>
</s:Body>
</s:Envelope>
Any help would be greatly appreciated!
This is resolved,
I could not figure out a way to change or add additional namespace to the generated references.cs file, and ended up sending the SOAP to their server manually with an XML string serialized using a httpWebRequest and XmlSerializer

Quartz.Net How to use XML to configure several jobs

This is my XML file, it's not working at all.I want to configure multiple jobs using XML file, i searched for this and got no answer, so could anyone help me about this?
<schedule>
<job>
<name>employee</name>
<group>SampleGroup</group>
<description>My job</description>
<job-type>Quartz.Server.Interface_manip, Quartz.Server</job-type>
<durable>true</durable>
<recover>false</recover>
</job>
<trigger>
<cron>
<name>employeeTrigger</name>
<group>SampleGroup</group>
<description>Simple trigger to simply fire sample job</description>
<job-name>employee</job-name>
<job-group>SampleGroup</job-group>
<misfire-instruction>SmartPolicy</misfire-instruction>
<cron-expression>0 13 10 * * ?</cron-expression>
</cron>
</trigger>
<job>
<name>SampleJob</name>
<group>SampleGroup</group>
<description>My job</description>
<job-type>Quartz.Server.Next_Year_Quota, Quartz.Server</job-type>
<durable>true</durable>
<recover>false</recover>
</job>
<trigger>
<cron>
<name>SampleTrigger</name>
<group>SampleGroup</group>
<description>Simple trigger to simply fire sample job</description>
<job-name>SampleJob</job-name>
<job-group>SamplerGroup</job-group>
<misfire-instruction>SmartPolicy</misfire-instruction>
<cron-expression>0 31 10 * * ?</cron-expression>
</cron>
</trigger>
</schedule>
</job-scheduling-data>
it executed perfectly if there's only the first job, and it did nothing when i added the second one, but i really need it to execute multiple jobs, and it will be convenient to use XML.Thank you very much.
From what I can see your issue is due to the fact that you are grouping your job and trigger together. Try grouping your jobs together, and your triggers together.
Also, I don't know if you intended to exclude your xml and job-scheduling-data tags, but you need those.
As an extra, I find this tool helpful.
Cron Expression Generator & Explainer - Quartz
Try this:
<?xml version="1.0" encoding="utf-8" ?>
<job-scheduling-data xmlns="http://quartznet.sourceforge.net/JobSchedulingData">
<schedule>
<job>
<name>employee</name>
<group>SampleGroup</group>
<description>My job</description>
<job-type>Quartz.Server.Interface_manip, Quartz.Server</job-type>
<durable>true</durable>
<recover>false</recover>
</job>
<job>
<name>SampleJob</name>
<group>SampleGroup</group>
<description>My job</description>
<job-type>Quartz.Server.Next_Year_Quota, Quartz.Server</job-type>
<durable>true</durable>
<recover>false</recover>
</job>
<trigger>
<cron>
<name>employeeTrigger</name>
<group>SampleGroup</group>
<description>Simple trigger to simply fire sample job</description>
<job-name>employee</job-name>
<job-group>SampleGroup</job-group>
<misfire-instruction>SmartPolicy</misfire-instruction>
<cron-expression>0 13 10 * * ?</cron-expression>
</cron>
</trigger>
<trigger>
<cron>
<name>SampleTrigger</name>
<group>SampleGroup</group>
<description>Simple trigger to simply fire sample job</description>
<job-name>SampleJob</job-name>
<job-group>SamplerGroup</job-group>
<misfire-instruction>SmartPolicy</misfire-instruction>
<cron-expression>0 31 10 * * ?</cron-expression>
</cron>
</trigger>
</schedule>
</job-scheduling-data>

Convert XML Dom Structure while deserialization

I have to transform the XML DOM structure into another XML DOM structure, How can I perform it using custom serialization implemented via IXmlSerialization. The source and target XML structure are mentioned as below
Source XML
<?xml version="1.0"?>
<ConfigFileRoot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<DeviceConnectionParams>
<DeviceConnectionParam>
<UserId>administrator</UserId>
<Password>B670AAB84F449BF3953C5ABE947DEF0C</Password>
<IsManual>True</IsManual>
</DeviceConnectionParam>
</DeviceConnectionParams>
<AlarmMappings>
<Enabled>true</Enabled>
<AlarmA>
<Events>
<EventId>
<PanelId>1</PanelId>
<PanelName>TestAccess</PanelName>
<DeviceId>65</DeviceId>
<DeviceName>TestPanel</DeviceName>
</EventId>
<EventId>
<PanelId>1</PanelId>
<PanelName>TestAccess</PanelName>
<DeviceId>65</DeviceId>
<DeviceName>TestPanel</DeviceName>
</EventId>
</Events>
</AlarmA>
<AlarmB>
<AlarmId>0a103f2b3ce7498c4fcaafb965c742cca66a221027054490eab5459689303bbea1f81898380c</AlarmId>
<NvrUuid>0a1027054490eab5459689303bbea1f818983801</NvrUuid>
</AlarmB>
</AlarmMappings>
</ConfigFileRoot>
Target XML
<?xml version="1.0"?>
<ConfigFileRoot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<DeviceConnectionParams>
<DeviceConnectionParam>
<UserId>administrator</UserId>
<Password>B670AAB84F449BF3953C5ABE947DEF0C</Password>
<IsManual>True</IsManual>
</DeviceConnectionParam>
</DeviceConnectionParams>
<AlarmMappings>
<Enabled>true</Enabled>
<AlarmA>
<Events>
<EventId>
<PanelId>1</PanelId>
<PanelName>TestAccess</PanelName>
<DeviceId>65</DeviceId>
<DeviceName>TestPanel</DeviceName>
</EventId>
</Events>
</AlarmA>
<AlarmB> <AlarmId>0a103f2b3ce7498c4fcaafb965c742cca66a221027054490eab5459689303bbea1f81898380c</AlarmId>
<NvrUuid>0a1027054490eab5459689303bbea1f818983801</NvrUuid>
</AlarmB>
</AlarmMappings>
<AlarmMappings>
<Enabled>true</Enabled>
<AlarmA>
<Events>
<EventId>
<PanelId>1</PanelId>
<PanelName>TestAccess</PanelName>
<DeviceId>65</DeviceId>
<DeviceName>TestPanel</DeviceName>
</EventId>
</Events>
</AlarmA>
<AlarmB>
<AlarmId>0a103f2b3ce7498c4fcaafb965c742cca66a221027054490eab5459689303bbea1f81898380c</AlarmId>
<NvrUuid>0a1027054490eab5459689303bbea1f818983801</NvrUuid>
</AlarmB>
</AlarmMappings>
</ConfigFileRoot>

Quartz.net Configure several jobs in XML

How to configure correctly the XML for several jobs in Quartz.Net? Is there any tutorials on that?
I found tutorials for one job in the XML. It is working. But I am not sure for several jobs how to configure the quartz_jobs.xml.
I agree with you that a "jobs" (plural) xml-tag would be more intuitive. But basically you put in multiple "job" (singular) xml elements. And just ignore the fact there is no <jobs> (plural) element.
Note that the
<job><name>
needs to match the
<trigger><simple><job-name>
value, to get the job to map to the correct trigger.
But here is my xml for 2 jobs.
<?xml version="1.0" encoding="UTF-8"?>
<job-scheduling-data xmlns="http://quartznet.sourceforge.net/JobSchedulingData"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0">
<!-- This value wipes out existing jobs...be very careful with it being "true" -->
<processing-directives>
<overwrite-existing-data>true</overwrite-existing-data>
</processing-directives>
<schedule>
<!-- First Job -->
<job>
<name>LogStuffJobJobName</name>
<group>LogStuffJobGroupName</group>
<description>LogStuffJobNonConcurrentJob Description</description>
<job-type>MyCompany.Apps.QuartzPOC.BAL.Jobs.LogStuffJobNonConcurrentJob, MyCompany.Apps.QuartzPOC.BAL</job-type>
<durable>true</durable>
<recover>false</recover>
<job-data-map>
<!--Parameters for the job-->
<entry>
<key>JobDetailParameter001</key>
<value>Value001_Set_In_Quartz_Jobs_001_xml</value>
</entry>
<entry>
<key>DefinedInJobDetailAndTriggerKey</key>
<value>DefinedInJobDetailAndTriggerKeyValue_JobElement_Set_In_Quartz_Jobs_001_xml</value>
</entry>
</job-data-map>
</job>
<trigger>
<simple>
<name>LogStuffJobTriggerName</name>
<group>LogStuffJobTriggerGroup</group>
<description>LogStuffJobTriggerName Description</description>
<job-name>LogStuffJobJobName</job-name>
<job-group>LogStuffJobGroupName</job-group>
<job-data-map>
<entry>
<key>TriggerParameter001Key</key>
<value>TriggerParameter001Value_Set_In_Quartz_Jobs_001_xml</value>
</entry>
<entry>
<key>TriggerParameter002Key</key>
<value>TriggerParameter002Value_Set_In_Quartz_Jobs_001_xml</value>
</entry>
<entry>
<key>DefinedInJobDetailAndTriggerKey</key>
<value>DefinedInJobDetailAndTriggerKeyValue_TriggerElement_Set_In_Quartz_Jobs_001_xml</value>
</entry>
</job-data-map>
<!--<start-time>1982-06-28T18:15:00.0Z</start-time>-->
<!--<end-time>2020-05-04T18:13:51.0Z</end-time>-->
<misfire-instruction>SmartPolicy</misfire-instruction>
<!-- repeat indefinitely every 5 seconds -->
<repeat-count>-1</repeat-count>
<repeat-interval>5000</repeat-interval>
</simple>
</trigger>
<!-- Second Job -->
<job>
<name>TextFilePoppingJobJobName</name>
<group>TextFilePoppingJobGroupName</group>
<description>TextFilePoppingJob Desription</description>
<job-type>MyCompany.Apps.QuartzPOC.BAL.Jobs.TextFilePoppingJob, MyCompany.Apps.QuartzPOC.BAL</job-type>
<durable>true</durable>
<recover>false</recover>
<job-data-map>
<entry>
<key>FavoriteActor</key>
<value>Harrison Ford</value>
</entry>
<entry>
<key>FavoriteColor</key>
<value>Green</value>
</entry>
</job-data-map>
</job>
<trigger>
<simple>
<name>TextFilePoppingJobTriggerName</name>
<group>TextFilePoppingJobTriggerGroup</group>
<description>TextFilePoppingJobTriggerName Description</description>
<job-name>TextFilePoppingJobJobName</job-name>
<job-group>TextFilePoppingJobGroupName</job-group>
<job-data-map>
<entry>
<key>FavoriteCity</key>
<value>Chicago</value>
</entry>
</job-data-map>
<misfire-instruction>SmartPolicy</misfire-instruction>
<repeat-count>-1</repeat-count>
<repeat-interval>10000</repeat-interval>
</simple>
</trigger>
</schedule>
</job-scheduling-data>

Categories