how to convert XML document to several XML documents in a new format

Discussion in 'XML' started by enyetor@gmail.com, Apr 21, 2005.

  1. Guest

    I'm migrating data into a content management system and in order to use
    the import tool provided I need to change the format of a large xml
    file and convert each entry to a seperate xml file.

    This is what I have now:


    <?xml version="1.0" encoding="UTF-8" ?>

    <dataroot xmlns:eek:d="urn:schemas-microsoft-com:eek:fficedata"
    generated="2005-04-18T12:05:51">
    <Checklist>
    <ID>1</ID>
    <Category>stuff</Category>
    <Type>stuff</Type>
    <Item>stuff</Item>
    <Steps>stuff</Steps>
    </Checklist>
    <Checklist>
    <ID>2</ID>
    <Category>stuff</Category>
    <Type>stuff</Type>
    <Item>stuff</Item>
    <Steps>stuff</Steps>
    </Checklist>
    <Checklist>
    <ID>3</ID>
    <Category>stuff</Category>
    <Type>stuff</Type>
    <Item>stuff</Item>
    <Steps>stuff</Steps>
    </Checklist>
    <Checklist>
    <ID>4</ID>
    <Category>stuff</Category>
    <Type>stuff</Type>
    <Item>stuff</Item>
    <Steps>stuff</Steps>
    </Checklist>
    </dataroot>



    This is what I need each entry to be as a single file:

    <?xml version="1.0" ?>
    <file DocType="TypeName" DocTitle="TITLE:testing 123"
    DocDesc="TITLE:testing 123">
    <section name="Category">
    <![CDATA[
    stuff
    ]]>
    </section>
    <section name="Type">
    <![CDATA[
    stuff
    ]]>
    </section>
    <section name="Item">
    <![CDATA[
    stuff
    ]]>
    </section>
    <section name="SLA">
    <![CDATA[
    stuff
    ]]>
    </section>
    <section name="Troubleshooting Steps">
    <![CDATA[
    stuff
    ]]>
    </section>
    </file>

    I need some direction on how to accomplish this task...
     
    , Apr 21, 2005
    #1
    1. Advertising

  2. ajm Guest

    hi,

    you could also consider writing a simple SAX parser for this
    sort of thing. SAX is event driven so you might have something
    like create/open file handle on receipt of opening Category
    element and close/flush file stream on closing Step element
    (with everything else in between being written to the file and
    possibly a few other details depending on the exact output
    requirements)

    your handler is likely to be pretty small and very fast
    (depending on your choice of processor the XSLT solution
    already mentioned is like to be fast too provided that the
    stylesheet can be compiled in some efficient manner).

    hth,
    ajm.

    wrote in message news:<>...
    > I'm migrating data into a content management system and in order to use
    > the import tool provided I need to change the format of a large xml
    > file and convert each entry to a seperate xml file.
    >
    > This is what I have now:
    >
    >
    > <?xml version="1.0" encoding="UTF-8" ?>
    >
    > <dataroot xmlns:eek:d="urn:schemas-microsoft-com:eek:fficedata"
    > generated="2005-04-18T12:05:51">
    > <Checklist>
    > <ID>1</ID>
    > <Category>stuff</Category>
    > <Type>stuff</Type>
    > <Item>stuff</Item>
    > <Steps>stuff</Steps>
    > </Checklist>
    > <Checklist>
    > <ID>2</ID>
    > <Category>stuff</Category>
    > <Type>stuff</Type>
    > <Item>stuff</Item>
    > <Steps>stuff</Steps>
    > </Checklist>
    > <Checklist>
    > <ID>3</ID>
    > <Category>stuff</Category>
    > <Type>stuff</Type>
    > <Item>stuff</Item>
    > <Steps>stuff</Steps>
    > </Checklist>
    > <Checklist>
    > <ID>4</ID>
    > <Category>stuff</Category>
    > <Type>stuff</Type>
    > <Item>stuff</Item>
    > <Steps>stuff</Steps>
    > </Checklist>
    > </dataroot>
    >
    >
    >
    > This is what I need each entry to be as a single file:
    >
    > <?xml version="1.0" ?>
    > <file DocType="TypeName" DocTitle="TITLE:testing 123"
    > DocDesc="TITLE:testing 123">
    > <section name="Category">
    > <![CDATA[
    > stuff
    > ]]>
    > </section>
    > <section name="Type">
    > <![CDATA[
    > stuff
    > ]]>
    > </section>
    > <section name="Item">
    > <![CDATA[
    > stuff
    > ]]>
    > </section>
    > <section name="SLA">
    > <![CDATA[
    > stuff
    > ]]>
    > </section>
    > <section name="Troubleshooting Steps">
    > <![CDATA[
    > stuff
    > ]]>
    > </section>
    > </file>
    >
    > I need some direction on how to accomplish this task...
     
    ajm, Apr 26, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    449
    TextDoctor
    May 7, 2005
  2. Timothy Grant
    Replies:
    6
    Views:
    3,377
  3. Replies:
    1
    Views:
    518
    Juan T. Llibre
    Oct 18, 2006
  4. Ralph Amissah
    Replies:
    0
    Views:
    207
    Ralph Amissah
    Nov 20, 2005
  5. Victor \Zverok\ Shepelev

    RDOC: several related modules in several C files

    Victor \Zverok\ Shepelev, Mar 6, 2007, in forum: Ruby
    Replies:
    3
    Views:
    197
    Max Lapshin
    Mar 16, 2007
Loading...

Share This Page