StaxMate: Accessing plain XML

216 Views Asked by At

I got following (in reality huge) XML to process:

<root>
  <item attr="hello world">
    <subitem></subitem>
    <subitem></subitem>
    <subitem></subitem>
    <subitem></subitem>
  </item>
  <item attr="hello world">
    <subitem></subitem>
    <subitem></subitem>
    <subitem></subitem>
    <subitem></subitem>
  </item>
  .
  .
  .
</root>

With StaxMate this is pretty easy. But how on earth do I tell StaxMate to "record" e.g. the plain XML for each item (see XML above). So that after processing the an item I have done my processing on it + I have the String

  <item attr="hello world">
    <subitem></subitem>
    <subitem></subitem>
    <subitem></subitem>
    <subitem></subitem>
  </item>

somewhere.

Thank you very very much, Fabian

1

There are 1 best solutions below

0
On

You need to write entries; XMLStreamWriter2 has nice method, XMLStreamWriter2.copyEventFromReader(...) which can be used to make exact copy of the token.

But why are you creating Strings at all? Wouldn't it make sense to either directly write XML fragments, or process them? Strings are inefficient things to use with XML; take up memory, need to be encoded when written out, parsed when they contain XML. So about the only reason to do this is if they must be passed as Strings to another library.