Link to home
Start Free TrialLog in
Avatar of pothireddysunil
pothireddysunil

asked on

Read an XML file between a repetative nodes and create new xml files from it

I have an xml file. Here I need to read the elements between ImportDocument starting and ending nodes and create a new xml document with those elements and its values. So, for the below xml file, I need to create 3 new xml files.

But before creating a new xml document I need to get values from database for Pernsr and SubmittingPernr element values.

Can anyone has any sample code for this task?

<?xml version="1.0" encoding="UTF-8"?>
-<DmHrImport xsi:noNamespaceSchemaLocation="http://dm-corp.swna.wdpr.disney.com/ImportSchemas/DmHrImport.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-<Feed>
      <Interface>000001</Interface>
      <Version>001</Version>
</Feed>
-<Options>
      <Test>N</Test>
      <BatchName>00000120140528502</BatchName>
</Options>
-<ImportDocument>
      <Pernr>00895722</Pernr>
      <SubmittingPernr>00895722</SubmittingPernr>
      <Type>APPLMAT</Type>
      <Application>ACROBAT</Application>
      <FilePath>\files\0000\00895722_1_Emergency Contact Information.pdf</FilePath>
      <DocumentDate>2014-05-15</DocumentDate>
      <Notes/>
</ImportDocument>
-<ImportDocument>
      <Pernr>00895722</Pernr>
      <SubmittingPernr>00895722</SubmittingPernr>
      <Type>APPLMAT</Type>
      <Application>ACROBAT</Application>
      <FilePath>\files\0000\00895722_2_Release of Info & Documentation(College).pdf</FilePath>
      <DocumentDate>2014-05-15</DocumentDate>
      <Notes/>
</ImportDocument>
-<ImportDocument>
      <Pernr>00891102</Pernr>
      <SubmittingPernr>00891102</SubmittingPernr>
      <Type>APPLMAT</Type>
      <Application>ACROBAT</Application>
      <FilePath>\files\0000\00891102_3_Emergency Contact Information.pdf</FilePath>
      <DocumentDate>2014-05-11</DocumentDate>
      <Notes/>
</ImportDocument>
</DmHrImport>
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I suspect this is some kind of batch process and importdocument tags would be in good numbers.
Pernr and SubmittingPernr are look up values

My approach would be -
1. Query database and spit out an xml which will server as lookup xml.
2. Use XSLT to break batch xml file into multiple xml files.

Below url's should help you in achieving #2.
http://stackoverflow.com/questions/4181496/xslt-output-into-multiple-xml-files-based-on-grouping
http://stackoverflow.com/questions/19021205/merging-two-xml-files-using-xslt

thanks
Avatar of pothireddysunil
pothireddysunil

ASKER

Thanks
Not a problem, glad I was able to help.