Question: this is my first question on stack overflow, I hope you guys can help me.

here is my xml

```
<?xml version="1.0"?>
<RecentPhotoUploads>
<PHOTO><SOURCE>6171.jpg</SOURCE></PHOTO>
<PHOTO><SOURCE>6173.jpg</SOURCE></PHOTO>
<PHOTO><SOURCE>6895.jpg</SOURCE></PHOTO>
<PHOTO><SOURCE>Tulips.jpg</SOURCE></PHOTO>
</RecentPhotoUploads>

```

here is my javascript code

```
    var xml=loadXMLDoc("../upload.xml");
    var source="/RecentPhotoUploads/PHOTO/SOURCE"

    var nodes=xml.evaluate(source, xml, null, XPathResult.ANY_TYPE, null);
    var result=nodes.iterateNext();

                while (result)
                {
                document.write("<h2>" + result.childNodes[0].nodeValue + "</h2>");
                document.write("<a href='../pics/" + result.childNodes[0].nodeValue + "</a>");
                result=nodes.iterateNext();
                }

```

How would I loop through this xpathresult backwards?

Answer: 
Why you would navigate backwards? You can just print backwards ...

```
var xml=loadXMLDoc("../upload.xml");
var source="/RecentPhotoUploads/PHOTO/SOURCE"

var nodes=xml.evaluate(source, xml, null, XPathResult.ANY_TYPE, null);
var result=nodes.iterateNext();

var buffer = "";
while (result) {
    buffer = "<h2>" + result.childNodes[0].nodeValue + "</h2>"
           + "<a href='../pics/" + result.childNodes[0].nodeValue + "'>"
           + result.childNodes[0].nodeValue + "</a>"
           + buffer;
    result=nodes.iterateNext();
}
document.write(buffer);

```

without resorting to documentFragment and similar modern tools ;)
First change the settings for your XPathResult. You want an ordered snapshot type. iterateNext() won't work because it doesn't have numeric keys.

```
var result = document.evaluate(source, xml, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);

```

Then loop backwards like so.

```
for (var i = result.snapshotLength - 1; i >= 0; i--){
    document.write("<h2>" + result.snapshotItem(i).textContent + "</h2>");
    document.write("<a href='../pics/" + result.snapshotItem(i).textContent + "'>" 
    + result.snapshotItem(i).textContent + "</a>");

}

```

PS: you're missing a '>' in your code for the `<a>` tag. Not sure what output you're aiming for so I took a guess.