The moose likes Web Services and the fly likes selectNodeIterator()       problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "selectNodeIterator()       problem" Watch "selectNodeIterator()       problem" New topic

selectNodeIterator() problem

Prashanth reddy

Joined: Aug 17, 2005
Posts: 18
Hi I have a SOAP file.... i converted into string.
i would like to search the value of a perticular node.

The soap String is:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><GetQuoteRequest xmlns="http://schemas.vanguard.com/StockQuote"><symbol xmlns="">wqw</symbol><company xmlns="">qwq</company></GetQuoteRequest></soapenv:Body></soapenv:Envelope>

the program to look for perticular node is
public XPathNavigator(String xmlSource) throws TransformerException{
if ( xmlSource!=null) {
Debug.println("XPath xml=" + xmlSource);
String xpath = "/Envelope/Body/GetQuoteRequest/symbol";
InputSource inputSource = new InputSource(new ByteArrayInputStream(xmlSource.getBytes()));
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
try {
root = dfactory.newDocumentBuilder().parse(inputSource);
NodeIterator nodeIterator = XPathAPI.selectNodeIterator(root, xpath);
Node node = nodeIterator.nextNode();
System.out.println("the node u r searching is : " + node.getNodeName());
System.out.println("value of the node : " + node.getNodeValue());

catch (ParserConfigurationException pce) {
throw new TransformerException(pce.getMessage());
catch (IOException ioe) {
throw new TransformerException(ioe.getMessage());
catch (SAXException se){
throw new TransformerException(se.getMessage());


I am getting the node.But the value of the node am getting is null

PLZ help me ....
Peer Reynders

Joined: Aug 19, 2005
Posts: 2906
If you check the table of the API documentation org.w3c.dom Interface Node you will find that for an Element getNodeValue() will always return null. So either use the Node's getTextContent() method instead or append "/child::text()" to your XPath expression.

Parsing an XML Document with XPath
Parsing a Namespace node with JDK 5.0

"Don't succumb to the false authority of a tool or model. There is no substitute for thinking."
Andy Hunt, Pragmatic Thinking & Learning: Refactor Your Wetware p.41
Prashanth reddy

Joined: Aug 17, 2005
Posts: 18

It is simply SUPERB....u r the man....
Thanks alot

Pramod Reddy
I agree. Here's the link: http://aspose.com/file-tools
subject: selectNodeIterator() problem
Similar Threads
sendind SOAP request
WSDL2Java Question
How to make XML file from WebService responses?
Adding payload to SOAP body
AXIS and DOM exception