dcsimg
XML Node value by Name..
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Shridhar_N
Posted On:   Tuesday, May 9, 2006 08:29 AM

Hi All,

Can you tell me how to get Node's value using java API..
Ex:

<?xml version="1.0"?>

Mints
Chocolate
Circus Peanuts

Circus Peanuts
Circus Peanuts



Like, If i want Node value ; then it shul return its child node & also any string..

Circus Peanuts
Circus Peanuts


Any help would be highly appreciated..

Thanks in Advance
Shridhar..

Re: XML Node value by Name..

Posted By:   Anonymous  
Posted On:   Tuesday, May 9, 2006 03:48 PM

This is how an xml can be read using a DOM parser:





Node parentNode = document.getElementsByTagName( "candy ")item( 0 );


NodeList childList = parentNode.getChildNodes();



for ( int i = 0; i < childList.getLength(); i++ )

{


Node child = childList.item( i );


// child.hasChildNodes() will avoid NPE
if ( child.hasChildNodes() && child.getNodeName().equals( "mainprod" ) )

{
NodeList stageValues = child.getChildNodes();


List products = new ArrayList();


for ( int j = 0; j < stageValues.getLength(); j++ )
{

Node stageValue = stageValues.item( j );


// stageValue.getFirstChild().getNodeValue(); //stageValue.getNextSibling().getNodeValue();



}

}

}

I hope this is what you are looking for.
About | Sitemap | Contact