• 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

Need to implement Streambased Stax parser

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hy everyone

Right now i have implement the Staxbased xml parsing , which take as input as inputstream and OutputStream. and generate the file.
But now i wan to implementation it in another stream-based concept.,

Current Implementation:
===============
Right now i had create the xml using the following code


Above code generate element for the xml using the Document object
and i will generate the xml file using the testdata object , and make the fileinputstrem object and pass it to my staxparser method , which give me the appropriate file.

But now i do not want to not generate the xml file , and giving whatever write in the dom element pass it to staxbased parser ,
so it will increase the my performance, but i don't know any idea how do i start it?How to start that implementation for it? if any body having know this concept/approach /reference link/solution , please share it with me.


thanks & regards
Yatin Baraiya
 
Marshal
Posts: 28226
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
In the example you posted, you are creating a DOM element in your code. There is no parsing being done at all. So there wouldn't be any point in using a StAX parser, because you aren't doing any parsing.

Perhaps you could explain your actual requirement in a bit more detail?
 
yatin baraiya
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Paul Clapham

First of thanks for the reply

As per i had making the Xml file ,check below code

While above code making the xml file
Now i have created one StaxbasedParser java file which have one method ,which take fileinputstream and outputstream, and this method give me all the attribute value of the given xml based fileinputstream , but now i want to not making any xml file and give the dom object directly to my method
i want solution like below



at this stage my dom element have making the below part


at this stage i want to parse the above partial xml part using staxbased parsing

Now dom is still running for the next element generating


now above code again making the below xml portion



now again i need to parse the above portion .

.......
........
.........
..........element added in xml is still going on..

Now you getting my requirement or not

Still let me know if you want to other information?

Thanks & Regards
Yatin Baraiya
 
Paul Clapham
Marshal
Posts: 28226
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
If I understand all of that, what you're saying is that you have a DOM and you want to "parse" that DOM using StAX.

And as I already said, that doesn't make sense. That's because parsing converts the external form -- the actual XML document which is text -- into an internal form, which could be a DOM document or a sequence of StAX events. But here you already have an internal form, so parsing is unnecessary. And not even possible.

If you really wanted to parse that DOM using StAX, then you would have to convert it to the external form (that's called "serialization" by the way, it helps in these discussions if you use the right names for things) and then parse that external form using StAX.
 
yatin baraiya
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you guide me the approach of serialization in my case?
Will you provide me the Any reference link,example demo etc...
 
Paul Clapham
Marshal
Posts: 28226
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
Serialization? That's the code you posted right after

As per i had making the Xml file ,check below code

 
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
@op
The StAX input factory has method(s) basically taking on InputStream in general. FileInputStream is just a subclass of it. You are free to use some memory stream such as ByteArrayInputStream to feed to the input factory to create your XMLStreamReader or XMLEventReader. The latter depends on your existing implementation of StAX parsing class.

This is how you can do it without passing the step of making a physical file --- which, if there is no need of it, it would ridiculous to do that and reload it with that kind of power support of the platform available. I make it as an inline integration to you existing code. You should obviously better isolate it in order not to disrupt too much the flow of logic and for the repetitive use of the same functionality.
 
g tsuji
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
[amendment-typo]
I have the chance to re-read my above post, there is a typo which should be obvious in the context. Sorry!

t.transform(new DOMSource(doc), new StreamResult(baos));


should be read:

That's the idea that I wanted to convey: feed the subtree with the root colwidth for StAX parsing.
 
Heroic work plunger man. Please allow me to introduce you to this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic