Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7517039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:19:13+00:00 2026-05-30T01:19:13+00:00

I have an XML file with this structure: <?xml version=1.0 encoding=utf-8 ?> <Photobank> <Landowner

  • 0

I have an XML file with this structure:

<?xml version="1.0" encoding="utf-8" ?>
<Photobank>
 <Landowner Name="Arnoldo"> 
  <Photo>
   <Animal>Jaguar</Animal>
   <Category>Cat</Category>
   <Image>Charlie_20111120_010500.JPG</Image>
  </Photo>
  <Photo>
   <Animal>Tapir</Animal>
   <Category>Prey</Category>
   <Image>Charlie_20111120_010500.JPG</Image>
  </Photo>
 </Landowner>
 <Landowner Name="Charlie">
  <Photo>
   <Animal>Margay</Animal>
   <Category>Cat</Category>
   <Image>Charlie_20111120_010500.JPG</Image>
  </Photo>
  <Photo>
   <Animal>Tayra</Animal>
   <Category>Prey</Category>
   <Image>Charlie_20111120_010500.JPG</Image>
  </Photo>
 </Landowner>
</Photobank>

And I would like for my page to parse and format all the photos for one landowner on the initial page load, and then empty the div and fill it with a different landowner’s photos when hitting buttons. So far, I am able to parse the XML and get the proper landowner’s photos on initial load, but I’m having trouble writing the function so that I can also use it to show the photos of other landowners.

Here is the jQuery Ajax:

$.ajax({
    type: "GET",
    url: "xml/photobank.xml",
    dataType: "xml",
    success: xmlParser
});


function xmlParser(xml) {
    $('#photo_container').empty();
    console.log('1');
    $(xml).find('Landowner').each(function(){
        console.log('2');
        var landownerName = $(this).attr('Name');
        if (landownerName==="Charlie") {
            $(this).find('Photo').each(function(){
                $("#photo_container").append('<div class="photo ' + $(this).find("Category").text().toLowerCase() + '"><p>' + $(this).find("Animal").text() + '</p>'+ '<img class="photobank" src="images/' + $(this).find("Image").text() + '" />' + '</div>');
            })
        }
    });
}

I would like to replace ==="Charlie" in xmlParser with a variable that the function uses as an argument, but every time I try to add arguments to the function declaration, the initial Ajax load stops working. Any hints?

The code on my development page below attempts to use the “Arnoldo” button to switch the content, but I couldn’t get too far. I am also open to using different methods to achieve this (non-Ajax, JSON?) if that would be better. I just want it to be easy for others to add photo information in the future.

Live example:
HTML: http://lamanai.org/catmap/index.html

JS: http://lamanai.org/catmap/js/cameramap.js

XML: http://lamanai.org/catmap/xml/photobank.xml


Update: ShankarSangoli below has helped me form the function the way I would like to, but now my initial Ajax call does not work. I get Uncaught Error: Invalid XML: [object Document] in the console. I imagine I am calling the Ajax at the wrong time (currently on document ready). Any ideas? See live page linked above.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T01:19:14+00:00Added an answer on May 30, 2026 at 1:19 am

    You should parse the xml using $.parseXML before using it. You can have an anonymous success handler and then call xmlParser passing the xml data and another parameter.

    $.ajax({
        type: "GET",
        url: "xml/photobank.xml",
        dataType: "xml",
        success: function(xml){
            xmlParser(xml, "Arnoldo");
        }
    });
    
    function xmlParser(xml, landOwner) {
    
        xml = $.parseXML(xml);
    
        $('#photo_container').empty();
        console.log('1');
        $(xml).find('Landowner').each(function(){
            console.log('2');
            var landownerName = $(this).attr('Name');
            if (landownerName === landOwner) {
                $(this).find('Photo').each(function(){
                    $("#photo_container").append('<div class="photo ' + $(this).find("Category").text().toLowerCase() + '"><p>' + $(this).find("Animal").text() + '</p>'+ '<img class="photobank" src="images/' + $(this).find("Image").text() + '" />' + '</div>');
                })
            }
        });
    }
    

    Reference: http://api.jquery.com/jQuery.parseXML/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this xml file <?xml version=1.0 encoding=UTF-8?> <bo:C837ClaimParent xsi:type=bo:C837ClaimParent xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:bo=http://somelongpathHere/process/bo> <claimAux> ...
I have an XML file looks like this: <?xml version=1.0 encoding=utf-8 ?> <PathMasks> <Mask
I have xml file whose structure is defined with following xsd: <?xml version=1.0 encoding=utf-8?>
I have this XML structure: <?xml version=1.0 encoding=utf-8?> <Request> <RequestHeader requestType=CreateUserRequest dateTime=2011-08-01T16:50:25.9387377+10:00 /> <RequestBody>
I have an XML file that looks like this: <?xml version=1.0? encoding=UTF-8 standalone=no?> <dir
I have the following XML file: <xml version=1.0 encoding=utf-8?> <Data> <Parameter1>1</Parameter1> </Data> I want
I have an xml file that contains in products. File's structure this: <?xml version=1.0
I have an XML file with this structure: <?xml version=1.0> <person> <element att1=value1 att2=value2>Anonymous</element>
I have the following XML structure: <?xml version=1.0 encoding=utf-8?> <xml> <root> <Item> <taxids> <string>330</string>
I have the following xml structure : <?xml version=1.0 encoding=utf-8 ?> <nws> <url>http://cpa.hypotheses.org/feed</url> <url>http://news.ycombinator.com/rss</url>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.