jQuery in Action, 2nd edition*
The moose likes Web Services and the fly likes Hi..help required Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Hi..help required" Watch "Hi..help required" New topic
Author

Hi..help required

raghav srinivasan
Greenhorn

Joined: Oct 18, 2009
Posts: 16
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

Joined: Oct 04, 2006
Posts: 2198
    
    1
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

Joined: Oct 18, 2009
Posts: 16
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

Joined: Jan 10, 2002
Posts: 61092
    
  66

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

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
raghav srinivasan
Greenhorn

Joined: Oct 18, 2009
Posts: 16
Hi Bear,

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

Cheers,
Raghav.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

No need to apologize -- but you can go back and fix them!
raghav srinivasan
Greenhorn

Joined: Oct 18, 2009
Posts: 16
Hope am done...
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
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

Joined: Oct 18, 2009
Posts: 16
Hi Ivan, the tutorial pages are very good..thanks for sharing it..:
raghav srinivasan
Greenhorn

Joined: Oct 18, 2009
Posts: 16
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Hi..help required