• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to write text parser in java  RSS feed

 
neha priya
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

I have an assignment where i need to take input from the user in text form in a text area.Collect that data from the text area and build an xml file by parsing the entered text.Kindly help as how do i go about it?

Regards,
Neha
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does "parsing" involve in this scenario? Can you describe the input and the desired output?
 
neha priya
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks ulf for the quick reply.The user will enter some text like:-


The text parser should parse the above text,raise error if the above syntax is not followed.Then it should generate an xml file based on the parsed text :-

 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If these are fixed strings that include variable parts, then using regexps like these may work well:

"Connect to ([a-zA-Z0-9]+) having IP ([0-9\\.]+)"

"Create a view ([a-zA-Z0-9]+) for device IP ([0-9\\.]+) and output result to ([a-zA-Z0-9]+)"

For creating XML you could use a library like XOM, JDOM or dom4j.
 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf,
Do we not need to put the constraint to restrict the IP to 4 octets ?
I am not sure as I am not regex expert hence wanted to clarify.
I think "([0-9\\.]{4})" will do the trick. Will it?

Regards,
amit
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you try it?
 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Wouter,
The question was initiated by someone else and while browsing the threads I felt like clearing my regex question about the same. Hence raised the question.
Anyway trying it out it always a good idea.

Thanks,
amit
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI think "([0-9\\.]{4})" will do the trick. Will it?

No, it won't. But you're on the right track, and some experimentation will lead you to the solution.
 
Rob Spoor
Sheriff
Posts: 21131
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:For creating XML you could use a library like XOM, JDOM or dom4j.

The core API has support for creating XML all by itself, through XMLOutputFactory + XMLStreamWriter or XMLOutputFactory + XMLEventWriter + XMLEventFactory. But yeah, one of those libraries make life a little bit easier for you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!