zwalex

zwalex


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

Recent Comments

  • XML Parsing with jQuery
    08/01/2010 - 17:21

    Oops - posted too early and after staring at it 10 minutes more I found the easy, stupid thing ...
    The iteration in the each loop obviously _is_ an object and not [yet ?] a valid [X]HTML snippet that could be inserted as is into the html (although in my case it could ...).

    I needed to pick out the attributes [$(this).attr("xxxx")] or the inner text of the element [$(this).text()] to produces results.

    I hope that somebody else can profit from that mistake ...
    alex

  • XML Parsing with jQuery
    08/01/2010 - 16:55

    The Reddest,
    I am only getting [object Object] returned as what should be parsed xml parts (see below). I want to do something very similar like you described in your article - inserting a list of customers from an xml file into my html (as list elements).
    I obviously have something wrong somewhere in my code that I am unable to find after staring at it for hours ...
    I am running jQuery 1.4.2 on Mac OS X 10.6.4. Same in Safari 5 and Firefox.
    Any help appreciated.
    alex

    <?xml version="1.0" encoding="utf-8"?>
    <custList>
    <customer type="IB" grade="A" ID="1111">ACME, Inc.</customer>
    <customer type="IB" grade="A" ID="2222">Customer LLC</customer>
    <customer type="Prospect" grade="A" ID="3333">Prospect, Inc.</customer>
    </custList>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
            <head>
                    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
                    <title>Customer List</title>
                <script type="text/javascript" src="lib/jquery/jquery-1.4.2.js"></script>
                    <script type="text/javascript" src="customer.js"></script>             
            </head>
            <body>
                    <ul id="custList">
                    </ul>
                    <div id="output"/>
            </body>
    </html>

    $(document).ready(function(){
            $.ajax({
        type: "GET",
        url: "customer.xml",
        dataType: "xml",
            error: function(XMLHttpRequest, textStatus, errorThrown) {
            $("#output").append(XMLHttpRequest.responseText + "<br />TextStatus: " + textStatus + "<br />ErrorThrown: " + errorThrown);
            },
        success: function(xml) {
                    $(xml).find("customer").each(function()
                            {
                    $("#custList").append("<li>" + $(this) + "</li>");
                            });            
                    }
            });
    });