• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

StaX: Transformer.transform does next() automatically, how to controll it?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using XMLStreamReader to achieve my goal(splitting xml file). It looks good, but still does not give the desired result. My aim is to split every node "nextTag" from an input file:


The outcome should look like this:


Referring to http://stackoverflow.com/questions/5169978/split-1gb-xml-file-using-java I achieved my goal with this code:


Actually very simple. But, my input file is in form from a single line:


My Java code does not produce the desired output anymore, instead just this result:

After spending hours, I am pretty sure to already find out the reason:


It is because, after the transform method being executed, the cursor will automatically moved forward to the next event. And in the code, I have this fraction:


After the first transform, the streamReader gets directly 2 times next():

1. from the transform method
2. from the next method in the while loop

So, in case of this specific line XML, the cursor can never achive the second open tag <nextTag>.
In opposite, if the input XML has a pretty print form, the second <nextTag> can be reached from the cursor because there is a space-event after the first closing tag </nextTag>

Unfortunately, I could not find anything how to do settings, so that the transformator does not automatically spring to next event after performing the transform method. This is so frustating.

Does anybody have any idea how I can deal with it? Also semantically is very welcome. Thank you so much.

Regards,

Ratna

PS. I can surely write a workaround for this problem(pretty print the xml document before transforming it, but this would mean that the input xml was being modified before, this is not allowed).
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ratna Lein wrote:The outcome should look like this:



Surely not. That isn't a valid XML document, it's two of them concatenated together. It isn't even an external parsed entity because it isn't valid to have an XML prolog in the middle of such a thing.

So perhaps you were expecting to receive the prolog as the result of your first call to "next"? The prolog isn't part of the document so you aren't going to get that.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to the Ranch!
 
Ranch Hand
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Unfortunately, I could not find anything how to do settings, so that the transformator does not automatically spring to next event after performing the transform method.


I think you are asking the wrong class to bend to your need...

Does anybody have any idea how I can deal with it?


Instead, you should ask your own application to accommodate the proper behavior of the Transformer. The cursor api is equipped with all the necessary methods to deal with it...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic