petrus

petrus


  • Name: [not set]
  • Favorite Languages: [not set]
  • Website: [not set]
  • Location: [not set]
  • About Me: [not set]

Recent Comments

  • XML Parsing with jQuery
    01/26/2010 - 05:02

    Hi, thanks for this tutorial it has been illuminating.

    I'v just one problem - it takes about 6-12 seconds to parse.. :( please help, here is my situation:

    XML example: (XML is dynamically created)

    <?xml version="1.0" encoding="utf-8"?>
    <RESPONSE xsi:noNamespaceSchemaLocation="http://192.168.xxx.xx:10000/rest/schemas/contacts_response.xsd">

    <PARAMETERS>
    <Ret_Data>
    <contact url="http://192.168.xxx.xx:10000/rest/contact/1">
      <CNT_ID>1</CNT_ID>
      <CNT_LASTNAME>Marko</CNT_LASTNAME>
      <CNT_FIRSTNAME>Matic</CNT_FIRSTNAME>
      <CNT_ORGANIZATIONNAME>IT Business Soft</CNT_ORGANIZATIONNAME>
      <CNT_TYPE>1</CNT_TYPE>
      <CNT_NAME>Marko Matic</CNT_NAME>
      </contact>

      <contact url="http://192.168.xxx.xx:10000/rest/contact/14044">
       ...
      </contact>
       ...
       ... etc (about 1500 CONTACT elements)
     
       </Ret_Data>
    </PARAMETERS>

    (there are about 1500 'contact' nodes) -> IS IT POSSIBLE THAT IT'S SLOW BECAUSE EACH WILL ITERATE TROUGH EVERY CHILD - CAN I RESTRICT SOMEHOW SOMETHING?)

     
    $(document).ready(function()
    {
     $.ajax({                  
       type: "GET",
       url: "http://192.168.xxx.xx:10000/rest/contacts/",
       dataType: "xml",
       success: parseXML,
       error: err    
            });              
    });    
    function err(xhr, reason, ex)
    {
      $('#output').append(reason);
    }
    function parseXML(xml)
    {
    $(xml).find("contact").each(function()
    {
     $("#content").append($(this).find("CNT_NAME").text());
    $("#content").append(": "+
    $(this).find("CNT_ORGANIZATIONNAME").text() +" <br />");       
    });      
    }

    <body> 

       <div id="title">
         <h3>Printing: Contact Name followed by organization</h3>
       </div>
           
       <div id="content">
           
       </div>

    </body>

    BUGS:

    1) WORKS IN SAFARI/IE - DOES NOT WORK IN FIREFOX (ParseError - it doesn't even call the ParseXML function, just err)

    2) Why so slow?? Why cca 10 seconds?

    PLEASE HELP THX

    ps.

    would it be faster if i used NATIVE DOM METHODS? I really really like jQuery, it's so programmer friendly...

Sponsors