problem with commas when parsing xml file

Discussion in 'ASP General' started by Allan, Sep 20, 2004.

  1. Allan

    Allan Guest

    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);
    Allan, Sep 20, 2004
    #1
    1. Advertising

  2. 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"
    Bob Barrows [MVP], Sep 21, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GIMME
    Replies:
    2
    Views:
    869
    GIMME
    Feb 11, 2004
  2. Replies:
    8
    Views:
    610
    William Park
    Jul 4, 2005
  3. AviraM
    Replies:
    2
    Views:
    6,333
    Manish Pandit
    Sep 28, 2006
  4. John Kopanas
    Replies:
    2
    Views:
    267
    Gregory Brown
    Jan 29, 2007
  5. Erik Wasser
    Replies:
    5
    Views:
    437
    Peter J. Holzer
    Mar 5, 2006
Loading...

Share This Page