File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes Need to implement Streambased Stax parser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Need to implement Streambased Stax parser" Watch "Need to implement Streambased Stax parser" New topic
Author

Need to implement Streambased Stax parser

yatin baraiya
Ranch Hand

Joined: Jul 17, 2012
Posts: 30
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
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Jul 17, 2012
Posts: 30
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Jul 17, 2012
Posts: 30
Can you guide me the approach of serialization in my case?
Will you provide me the Any reference link,example demo etc...
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Serialization? That's the code you posted right after

As per i had making the Xml file ,check below code
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 512
    
    3
@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

Joined: Jan 18, 2011
Posts: 512
    
    3
[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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need to implement Streambased Stax parser