wood burning stoves 2.0*
The moose likes Java in General and the fly likes XML parse help Needed and advice required. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "XML parse help Needed and advice required." Watch "XML parse help Needed and advice required." New topic
Author

XML parse help Needed and advice required.

madhup narain
Ranch Hand

Joined: Dec 14, 2004
Posts: 148
Hi there!!!

Have bben going through some posts but havent ben able to find an answer to solve my problem.

My problem..
i need to parse an XML string . Is there any available parser that can parser strings. Am currently using the XML parsing API avilable in Java 1.4.
Have been able to parse documents but have noot been able to get what i want.

Requirements.. My XML File

<DATA>
<HEADER>
<USERNAME>abc</USERNAME>
<PASSWORD>pqr</PASSWORD>
</HEADER>
<AVAILABILITY>
<ORIGINCITY>AUS</ORIGINCITY>
<DESTINATIONCITY>NY</DESTINATIONCITY>
<NOOFADULT>2</NOOFADULT>
<NOOFCHILD>1</NOOFCHILD>
<RETURNDATE>15 12 2005</RETURNDATE>
</AVAILABILITY>
</DATA>


i require my data like

USERNAME=abc
PASSWORD=pqr
DESTINATIONCITY=NY
TRIPTYPE=NY
NOOFADULT=2
NOOFCHILD=1
RETURNDATE=15 12 2005

the program should be able to parse any kind of file and retrieve me the values as shown above.

Advice required ...
Now this file comes form some other source over the internet.How do i proceed to process the file. There was some mention of SOAP.. i have no idea how to retrieve the content and go ahead to process, the request.

Someone please help me..


Money for nothing and Java for Free
SCJP, SCWCD
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Google for "Java XML Tutorial" to get a handle on the APIs in Java. One choice you'll have to make is whether to parse into a "DOM" or Document Object Model tree of objects or to use a SAX style parser to handle one tag at a time. I'm not a fan of the DOM and find SAX easier to deal with even if it might take more code.

If you're getting this "over the internet" you might have to use HttpURLConnection or sockets or maybe a servlet with XML as a data payload. Let us know what you can learn about this part ... who is sending you XML? Are you doing a query to get it or is it "pushed" to you? You might wind up parsing from a stream of data rather than a string.

Finally, SOAP is a standard wrapper - more XML before and after your real message, and before and after any response you send back. Google for more details on SOAP envelopes and payloads.

Let us know how you do with this ... get a little ways and tell us where you are. And there is an XML forum down the page where you can get much better examples than I can make up.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
madhup narain
Ranch Hand

Joined: Dec 14, 2004
Posts: 148
yea!!
thanks for the reply ... one thing that i know is data is going to be queried... meaning ill ask for the data and the reply will be sent to me as XML..

Ill see if i can come up with a refinement of my problem and probably discuss with you all.

thanks..
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Ok, given that you are the requester, parts of my first post had your role and the other end reversed. Google for SOAP and web services. There should be tons of help out there. And there are some tools like Glue (now part of WebLogic) that automate the whole thing so you never even see XML. I, for one, would be delighted never to look at XML again.
Ganesh Gowtham
Ranch Hand

Joined: Mar 30, 2005
Posts: 225

Originally posted by madhup narain:
Hi there!!!

Have bben going through some posts but havent ben able to find an answer to solve my problem.

My problem..
i need to parse an XML string . Is there any available parser that can parser strings. Am currently using the XML parsing API avilable in Java 1.4.
Have been able to parse documents but have noot been able to get what i want.

Requirements.. My XML File

<DATA>
<HEADER>
<USERNAME>abc</USERNAME>
<PASSWORD>pqr</PASSWORD>
</HEADER>
<AVAILABILITY>
<ORIGINCITY>AUS</ORIGINCITY>
<DESTINATIONCITY>NY</DESTINATIONCITY>
<NOOFADULT>2</NOOFADULT>
<NOOFCHILD>1</NOOFCHILD>
<RETURNDATE>15 12 2005</RETURNDATE>
</AVAILABILITY>
</DATA>


i require my data like

USERNAME=abc
PASSWORD=pqr
DESTINATIONCITY=NY
TRIPTYPE=NY
NOOFADULT=2
NOOFCHILD=1
RETURNDATE=15 12 2005

the program should be able to parse any kind of file and retrieve me the values as shown above.

Advice required ...
Now this file comes form some other source over the internet.How do i proceed to process the file. There was some mention of SOAP.. i have no idea how to retrieve the content and go ahead to process, the request.

Someone please help me..



Pls find the code to parse the XML DOc








for this Xml data



Thanks,
Gowtham
grgowtham_cse@yahoo.com


Thanks, Ganesh Gowtham
http://ganesh.gowtham.googlepages.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML parse help Needed and advice required.
 
Similar Threads
Java-Xml file not getting Connected to DataBase
Looking for some opinions on how to write effective XML
Servlet to read XML tags from Client
XML Property File
xmlns ="" is added after changing the value of an element