Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hi..help required

 
raghav srinivasan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I want to parse an XML file which contains the following content.

<myHeader xmlns:ns="http://ws.apache.org/axis2">

<headerValue1>value1</ns:headerValue1>
<headerValue2>value2</ns:headerValue2>
</myHeader>


I managed to extract the above as XML from the SOAP headers so that I can extract the attribute values and do computations.

I have found XML parsing tutorials where the value of an attribute is retrieved using Xpath for complex XML files. If somebody could post a simple code snippet for the above requirement using Xpath or DOM,it would be great.

Thanks for the help.

Cheers,
Raghav.
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Take a look at the JavaEE 5 Tutorial, chapter 19 contains at least examples on how to use DOM:
http://docs.sun.com/app/docs/doc/819-3669/bnbhf?a=view
Note that DOM uses more memory than, for instance StAX and SAX so if your XML data is large you may want to consider these other APIs.
Best wishes!
 
raghav srinivasan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ivan,

Thanks a lot for the tutorial page,I just had a glance and its all good..!

I am trying a round about way in Axis2 to receive the SOAP headers in the server side.i.e receiving the SOAP header block,assigning it to an variable and storing it as an XML file and then trying to get the header attributes from that. Is there a better way of doing it...?

the best suggestion made is a handler code to extract the header values but no tutorials explain it with a very simple example...

Please help me with this requirement.

Thanks in advance.

Cheers,
Raghav.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use real words when posting to the forums. Abbreviations such as "reqd" in place of "required" and "Pl" in place of "Please" only serve to make your posts more difficult to read and less likely to generate useful responses.

Please read this for more information.

thanks,
bear
JavaRanch sheriff
 
raghav srinivasan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,

Sorry for the usages. I will use the real complete words from this time.!

Cheers,
Raghav.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No need to apologize -- but you can go back and fix them!
 
raghav srinivasan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hope am done...
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Handlers is one way of doing what you want to do. However, you do not say anything about what kind of web service you have.
A web service which endpoint implementation class implements javax.xml.ws.Provider can be implemented to be able to access the entire SOAP message required.
If your web service endpoint implementation class does not implement the Provider interface, then I would suggest using a handler and putting the data extracted from headers in the MessageContext accessible to the handler. The MessageContext is also accessible from the endpoint implementation class.
If you are new to handlers, then you may find section 9.5 in a document I have written on web services interesting. It describes step-by-step how to write a handler.
Download it at: http://www.javaforum.se/jforum/posts/list/549.page
Best wishes!
 
raghav srinivasan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ivan, the tutorial pages are very good..thanks for sharing it..:
 
raghav srinivasan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ivan,

I had posted a new query on

http://www.coderanch.com/t/468807/Web-Services/java/AXIS-Inclusion-Headers-into-SOAP#2097105

Request you to please help me if its possible.

Cheers,
Raghav.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic