Reputation: 3608
in my GWT
web application, i am to retrieve XML data from the SOAP
server. i haven't encountered any difficulties parsing this xml data in the client until i have this xml structure to parse:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<data>
<list row="0">
<product_name>A</product_name>
<desc>product A</desc>
<promo>
<?xml version="1.0" encoding="UTF-8"?>
<root>
<data/>
</root>
</promo>
</list>
<list row="1">
<product_name>B</product_name>
<desc>product B</desc>
<promo>
<?xml version="1.0" encoding="UTF-8"?>
<root>
<data>
<list row="0">
<pname>Test</pname>
<pdesc>Test promo only</pdesc>
</list>
</data>
</root>
</promo>
</list>
</data>
<return_code>0</return_code>
</root>
having this xml, i have retrieved the product_name and desc of every list with NodeList
and Element
. but i also have to retrieve the promo of each product.
i have tried getting the promo by:
Document d = XMLParser.parse( xml ); // xml - xml data retrieved from server
Element element = d.getDocumentElement();
NodeList nlist = element.getElementsByTagName( "list" );
final int count = nlist.getLength();
for( int i = 0; i < count; ++i ) {
final Element list = ( Element ) nlist.item( i );
String product_name = ( (Text)list.getElementsByTagName( "fproductid" )
.item(0).getFirstChild()).getData()
...
// get promo
String promo = d.getElementsByTagName( "promo" ).item(0).
getFirstChild().getNodeValue();
Document dpromo = XMLParser.parse( promo );
...
}
when i check what's the value of each promo, i have the same output:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<data/>
</root>
any idea how to get the fields/element inside the promo node (i.e. pname, pdesc)?
Upvotes: 0
Views: 4128
Reputation: 8671
String promo = d.getElementsByTagName("promo").item(0).getFirstChild().getNodeValue();
You are looking at the same promo
element in each iteration of the loop.
Replace d
with list
:
String promo = list.getElementsByTagName("promo").item(0).getFirstChild().getNodeValue();
and you will get the full text for each promo
element.
Upvotes: 1