Ben wrote:
Quote:
I have a web service that returns the following xml:
>
<?xml version="1.0" encoding="utf-8" ?>
<NewDataSet>
<Addresses>
<XML_F52E2B61-18A1-11d1-B105-00805F49916B>
<CustomerAddressBase
CustomerAddressId="259DA89E-3B3F-DB11-90EA-0016353D15C7"
AddrName="PRIMARY" />
<CustomerAddressBase
CustomerAddressId="269DA89E-3B3F-DB11-90EA-0016353D15C7" />
<CustomerAddressBase
CustomerAddressId="9778EE83-3B70-DB11-B20C-0016353D15C7" AddrName="test
address" />
</XML_F52E2B61-18A1-11d1-B105-00805F49916B>
</Addresses>
</NewDataSet>
>
I want to loop through each CustomerAddressBase tag and pull out the
CustomerAddressId and AddrName. I can use getElementsByTagName on tag
XML_F52E2B61-18A1-11d1-B105-00805F49916B with no problems, but when I
try to use it to pull CustomerAddressBase I get an empty set and no
length. Here's the code I've been using to test this:
>
// Instantiate at connection to the Web service and call the get
method.
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
var objXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
>
// crmForm.all.salutation.DataValue =
"http://bert:5555/webservices/clientaddress.asmx/SRReturnAddr?AccountGUID="
+ s
>
xmlhttp.open("get",
^^^
Quote:
"http://bert:5555/webservices/clientaddress.asmx/SRReturnAddr?AccountGUID="
+ s, false);
Should be "GET".
Quote:
xmlhttp.send();
>
//crmForm.all.emailaddress1.DataValue = xmlhttp.responseText;
objXmlDoc.loadXML(xmlhttp.responseText);
//var noOfCustomerAddressTags =
>
objXmlDoc.getElementsByTagName("XML_F52E2B61-18A1-11d1-B105-00805F49916B").length;
objXmlDoc.getElementsByTagName("XML_F52E2B61-18A1-11d1-B105-00805F49916B");
Quote:
>
var CustomerAddressTags=
xmltag[0].getElementsByTagName("CustomerAddressBase");
>
var noOfCustomerAddressTags =
xmltag[0].getElementsByTagName("CustomerAddressBase").lengt h;
>
crmForm.all.emailaddress1.DataValue =
CustomerAddressTags[0].firstChild.nodeValue;
>
for (var x = 0; x < noOfCustomerAddressTags; x++)
{
crmForm.all.emailaddress1.DataValue = "test";
}
Let's clean this up at first, making it easily legible:
var xmltags = objXmlDoc.getElementsByTagName(
"XML_F52E2B61-18A1-11d1-B105-00805F49916B");
/* var noOfCustomerAddressTags = xmltags.length; */
var customerAddressTags =
xmltag[0].getElementsByTagName("CustomerAddressBase");
var noOfCustomerAddressTags = customerAddressTags.length;
crmForm.all.emailaddress1.DataValue =
customerAddressTags[0].firstChild.nodeValue;
// this loop does not make sense,
// especially since noOfCustomerAddressTags was not defined above
for (var x = 0; x < noOfCustomerAddressTags; x++)
{
crmForm.all.emailaddress1.DataValue = "test";
}
Quote:
Does anyone have any idea why I can't pull the CustomerAddressBase?
Probably you are making too many assumptions without testing any of them.
Proper coding would include feature tests such as
var o = ..., o2, o3;
if (o && o.getElementsByTagName
&& (o2 = o.getElementsByTagName(...))
&& (o3 = o2[0])
&& ...)
{
...
}
And you should use a debugger; links are in the FAQ:
http://jibbering.com/faq/
PointedEars
--
Indiana Jones: The Name of God. Jehovah.
Professor Henry Jones: But in the Latin alphabet,
"Jehovah" begins with an "I".
Indiana Jones: J-...