This week's book giveaway is in the Java in General forum.
We're giving away four copies of Helidon Revealed: A Practical Guide to Oracle’s Microservices Framework and have Michael Redlich on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

selectNodeIterator() problem

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ....
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Prashanth reddy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

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

Pramod Reddy
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic