Breaking larger xml document into smaller ones

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Abhishek

    Breaking larger xml document into smaller ones

    Hi All,
    I have a problem which I think is sure easy enough that it would have been
    solved already. I am looking for some pointers here -

    I have an XML document like this:

    <root>
    <child>
    <element1>value 1</element1>
    <element2>value 2</element2>
    </child>
    <child>
    <element1>value 1</element1>
    <element2>value 2</element2>
    </child>
    ....
    ....
    </root>

    The <childsection like the one above, might repeat for hundreds of
    thousands of times. Since I am going to process this XML later for some
    other thing, I want to break it in smaller chunks, say XML documents of 5000
    child records each.

    Is there a reasonable way to achieve this? I am using C# .Net 2.0 and Visual
    Studio 2005.

    Thanks in advance,
    Abhishek


  • Martin Honnen

    #2
    Re: Breaking larger xml document into smaller ones

    Abhishek wrote:
    The <childsection like the one above, might repeat for hundreds of
    thousands of times. Since I am going to process this XML later for some
    other thing, I want to break it in smaller chunks, say XML documents of 5000
    child records each.
    >
    Is there a reasonable way to achieve this? I am using C# .Net 2.0 and Visual
    Studio 2005.
    Use a combination of XmlReader and XmlWriter where you pull in the input
    XML with XmlReader and create a new document with XmlWriter for each
    chunk of 5000 child records.
    XmlWriter has a method WriteNode that takes an XmlReader
    Copies everything from the source object to the current writer instance.

    so you can simply copy those 'child' elements from the XmlReader to the
    XmlWriter.


    --

    Martin Honnen --- MVP XML

    Comment

    • Abhishek

      #3
      Re: Breaking larger xml document into smaller ones

      Thanks Martin,
      I will try to experiment with these and then come back if I have more
      questions.

      Regards
      Abhishek

      "Martin Honnen" <mahotrash@yaho o.dewrote in message
      news:elryBgH2IH A.3920@TK2MSFTN GP02.phx.gbl...
      Abhishek wrote:
      >
      >The <childsection like the one above, might repeat for hundreds of
      >thousands of times. Since I am going to process this XML later for some
      >other thing, I want to break it in smaller chunks, say XML documents of
      >5000 child records each.
      >>
      >Is there a reasonable way to achieve this? I am using C# .Net 2.0 and
      >Visual Studio 2005.
      >
      Use a combination of XmlReader and XmlWriter where you pull in the input
      XML with XmlReader and create a new document with XmlWriter for each chunk
      of 5000 child records.
      XmlWriter has a method WriteNode that takes an XmlReader
      Copies everything from the source object to the current writer instance.

      so you can simply copy those 'child' elements from the XmlReader to the
      XmlWriter.
      >
      >
      --
      >
      Martin Honnen --- MVP XML
      http://JavaScript.FAQTs.com/

      Comment

      Working...