• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML parse help Needed and advice required.

 
madhup narain
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
madhup narain
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 225
IBM DB2 Eclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic