Click here to Skip to main content
15,894,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've got a program that loads the XML time of 1 hour from the site
I have to catch the response from the server, and at its base to launch an alert. Unfortunately the program can not add / expand. The only way that I can see is the capture.
But how to do it - I do not know.
Posted

1 solution

XML
<books>
    <book>
        <title>JavaScript, the Definitive Guide</title>
        <publisher>O'Reilly</publisher>
        <author>David Flanagan</author>
        <cover src="/images/cover_defguide.jpg" />
        <blurb>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</blurb>
    </book>
    <book>
        <title>DOM Scripting</title>
        <publisher>Friends of Ed</publisher>
        <author>Jeremy Keith</author>
        <cover src="/images/cover_domscripting.jpg" />
        <blurb>Praesent et diam a ligula facilisis venenatis.</blurb>
    </book>
    <book>
        <title>DHTML Utopia: Modern Web Design using JavaScript &amp; DOM</title>
        <publisher>Sitepoint</publisher>
        <author>Stuart Langridge</author>
        <cover src="/images/cover_utopia.jpg" />
        <blurb>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</blurb>
    </book>
</books>


C#
function setDataXML(req)
{
    var books = req.responseXML.getElementsByTagName('book');
    for (var i=0;i<books.length;i++)
    {
        var x = document.createElement('div');
        x.className = 'book';
        var y = document.createElement('h3');
        y.appendChild(document.createTextNode(getNodeValue(books[i],'title')));
        x.appendChild(y);
        var z = document.createElement('p');
        z.className = 'moreInfo';
        z.appendChild(document.createTextNode('By ' + getNodeValue(books[i],'author') + ', ' + getNodeValue(books[i],'publisher')));
        x.appendChild(z);
        var a = document.createElement('img');
        a.src = books[i].getElementsByTagName('cover')[0].getAttribute('src');
        x.appendChild(a);
        var b = document.createElement('p');
        b.appendChild(document.createTextNode(getNodeValue(books[i],'blurb')));
        x.appendChild(b);
        document.getElementById('writeroot').appendChild(x);
    }
}

function getNodeValue(obj,tag)
{
    return obj.getElementsByTagName(tag)[0].firstChild.nodeValue;
}
 
Share this answer
 
Comments
[no name] 10-Jan-13 10:29am    
What is it ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900