This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.,
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.
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?
Joined: Jul 17, 2012
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?
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.
Joined: Jul 17, 2012
Can you guide me the approach of serialization in my case?
Will you provide me the Any reference link,example demo etc...
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.
Joined: Jan 18, 2011
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.