problem with commas when parsing xml file

A

Allan

Hi All,

I am having a problem parsing an xml file I am getting from another server.

This is the portion of the xml I am getting I am interested in:

<DestinationAddress>
<City>Leawood</City>
<StateOrProvinceCode>KS</StateOrProvinceCode>
<PostalCode>66209</PostalCode>
<CountryCode>US</CountryCode>
</DestinationAddress>


I am trying to write the above result in an html page as follow:

Leawood, KS, 662009, US

However my code keeps producing the following omitting the commas:

, LeawoodKS662009US



This is my code (I am using jscript!!)

....
var objXMLDOM = Server.CreateObject("MSXML2.DOMDocument");
objXMLDOM.loadXML(objXMLHttp.responseText);
objXMLDOM.async = false;

var Address = objXMLDOM.getElementsByTagName("DestinationAddress");

var AddressText = "";

for (var i = 0; i < Address.length; i++)
{
AddressText = AddressText + ", " + Address.item(i).text }

Response.Write(AddressText);
 
B

Bob Barrows [MVP]

Allan said:
Hi All,

I am having a problem parsing an xml file I am getting from another
server.

This is the portion of the xml I am getting I am interested in:

<DestinationAddress>
<City>Leawood</City>
<StateOrProvinceCode>KS</StateOrProvinceCode>
<PostalCode>66209</PostalCode>
<CountryCode>US</CountryCode>
</DestinationAddress>


I am trying to write the above result in an html page as follow:

Leawood, KS, 662009, US

However my code keeps producing the following omitting the commas:

, LeawoodKS662009US



This is my code (I am using jscript!!)

...
var objXMLDOM = Server.CreateObject("MSXML2.DOMDocument");
objXMLDOM.loadXML(objXMLHttp.responseText);

I prefer
objXMLDOM.load(objXMLHttp.responseXML);
objXMLDOM.async = false;

var Address = objXMLDOM.getElementsByTagName("DestinationAddress");

No:

var Address = objXMLDOM.selectSingleNode("//DestinationAddress");
var AddressText = "";

for (var i = 0; i < Address.length; i++)

for (var=0;var<Address.childNodes.length; i++)
{
AddressText = AddressText + ", " + Address.item(i).text }

AddressText += (AddressText.length==0)?Address.childNodes(i).text : ", " +
Address.childNodes(i).text;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top