Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > problem with commas when parsing xml file

Reply
Thread Tools

problem with commas when parsing xml file

 
 
Allan
Guest
Posts: n/a
 
      09-20-2004
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);
 
Reply With Quote
 
 
 
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      09-20-2004
Allan wrote:
> 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;

>
> Response.Write(AddressText);


--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
replace double inverted commas into slash double inverted commas in string AviraM Java 2 09-28-2006 06:19 PM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
Escaping commas within parens in CSV parsing? felciano@gmail.com Python 8 07-04-2005 01:50 AM
Print XML parsing to JspWriter (out) Class org.xml.sax.helpers.NewInstance can not access a member of class javax.xml.parsers.SAXParser with modifiers "protected" Per Magnus L?vold Java 0 11-15-2004 02:27 PM
Perl expression for parsing CSV (ignoring parsing commas when in double quotes) GIMME Perl 2 02-11-2004 05:40 PM



Advertisments