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.
I have Google and searched a lot but cant seem to find it, basically i would like to learn how do i write an xml file using java,
I have a method that reads a text file and counts the most frequently occuring words
Now i want to write them into xml format and for that im searching for good tutorials aimed at beginner level
for example if the text file has the following;
for-3 now-10 alice-221 wonderland-12
I would then want to write a method that codes the above roughly as;
<word occurence>count</word occurence>
Sorry I just search in google and see all the solutions available and try to learn from them. I hate books lol :P
In the previous example I have just created a file with .xml extension in C:/ and put the string (which contains count variable) in that file.
lol, yes i saw the code and also saw what you attempted to do..but honestly that's the bare basics.
What i'm trying to achieve here is a lil bit different.
Let' say there is a file containing the following text
" Humpty dumpty sat on a wall
Humpty fell down
Dumpty laughed aloud"
The java program is supposed to read the above text file and create groups of words occuring multiple times, so it would be as "humpty-02", "dumpty-01", "wall-01" and so forth...
Now i have managed to write the code for the above text classification.
What now i want to do is, something like this ...
This second part of converting it into well formed XML is what i'm stuck and stumped with....
So here is my complete code now, i would still need to tweak your code later so that i can understand it but for now here is the complete code
So my next exercise in this code is to use DocumentBuilderFactory methods of the javax.xml package library because your code uses append method of StringBuffer class .. its fine but i would like to better it by using the xml library package ... so that's the next goal; to achieve. But still, thanks for the idea.
Also there is one flaw in my code, I'm using a predefined string to search for in the ArrayList, but im sure i will figure out how to fix it.