Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Posts: 40
Registered: ‎04-27-2010
My Device: BOLD

read XML from WebService

Hi, I have the next xml that return my webservice


<?xml version="1.0" encoding="utf-8" ?>
- <DataSetGeneral xmlns="...">
- <xs:schema targetNamespace="..." xmlns:mstns="..." xmlns="..." xmlns:xs="..." xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified">
- <xs:element msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
- <xs:complexType>
- <xs:choice minOccurs="0" maxOccurs="unbounded">
- <xs:element>
- <xs:complexType>
- <xs:sequence>
  <xs:element minOccurs="0" />
- <xs:element>
- <xs:complexType>
- <xs:sequence>
  <xs:element minOccurs="0" />
- <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
- <DataSetGeneral xmlns="http://tempuri.org/DataSetGeneral.xsd">
- <CONTENIDO diffgr:id="CONTENIDO1" msdata:rowOrder="0">
- <CONTENIDO diffgr:id="CONTENIDO2" msdata:rowOrder="1">




And I use the next code to try read it:


             var parser = new DOMParser();
             var xmlDoc = parser.parseFromString(xmlHttp.responseText, "text/xml");
             var root = xmlDoc.getElementsByTagName('DataSetGeneral')[1];
             var items = root.getElementsByTagName("CONTENIDO");
             for (var i = 0; i < items.length; i++)
                 // get one item after another
                 var item = items[i];
                 // now we have the item object, time to get the contents
                 // get the name of the item
                 var name = item.getElementsByTagName("name")[0].firstChild.nodeValue;
                 // get the quantity
                 var quantity = item.getElementsByTagName("quantity")[0].firstChild.nodeValue;
                 alert("item #" + i + ": quantity=" + quantity);
             } // end of for


but give me error in line "var items = root.getElementsByTagName("CONTENIDO");"


Do you know why?


Thanks, Oscar

Posts: 482
Registered: ‎10-24-2008
My Device: 9300
My Carrier: AT&T

Re: read XML from WebService

[ Edited ]


var items = root.getElementsByTagName("CONTENIDO");



Edit the above line, try this...


var items = root[0].getElementsByTagName("CONTENIDO");