Menu
support@nursinghomework.org
+1 714-215-3097

(Solved) : Use Following Code Get Xml File Data Html File Use Jquery Api Automatically Add Document E Q35577133

USE FOLLOWING CODE TO GET THE XML FILE DATA INTO HTMLFILE. USE JQUERY API TO AUTOMATICALLY ADD DOCUMENT ELEMENTS TO THEBODY OF THE HTML FILE AND SET THEIR CONTENTS BASED N INFORMATIONPROVIDED IN XML FILE BELOW. (USE RANDOM IMAGE FOR THIS PROGRAM)MAKE IT RESPONSIVE TO BOTH SMALL AND BIG SCREEN (SMALL SCREEN 1IMAGE PER ROW AND BIG SCREEN 2 IMAGE PER ROW)

HTML CODE:

<!DOCTYPE html>
<html>
<head>
<scriptsrc=”https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js”></script>
</head>
<body id=”body1″>
<div id=”samplediv”style=”padding-left:5%;padding-right:5%;
  padding-top:20px;padding-bottom:20px;
  display:flex;flex-flow:row;
  align-items:center;justify-content:center;”>
<figure style=”align:center;font-family:’Roboto’;
  font-size:20px;padding:10px;”
   id=”fig1″>
  <img src=”” id=”img1″style=”height:200px;”/>
  <figcaptionid=”caption1″></figcaption>
</figure>
<figure style=”align:center;font-family:’Roboto’;
  font-size:20px;padding:10px;”
   id=”fig2″>
  <img src=”” id=”img2″style=”height:200px;”/>
  <figcaptionid=”caption2″></figcaption>
</figure>
</div>
<script>
<!– <TITLE>Empire Burlesque</TITLE> –>
<!– <PICUTRE>cd-image-1.png</PICTURE> –>
<!– <ARTIST>Bob Dylan</ARTIST> –>
<!– <COUNTRY>USA</COUNTRY> –>
<!– <COMPANY>Columbia</COMPANY> –>
<!– <PRICE>10.90</PRICE> –>
<!– <YEAR>1985</YEAR> –>
var titles, pcitures, artists;
var picindex = 1;
$.ajax({
  type: “GET”,
  url: ‘cd_catalog.xml’,
  dataType: “xml”,
  success: function(xml) {
    $(xml).find(‘CD’).each(function(){
    var $entry = $(this);
    var title =$entry.find(“TITLE”).text();
    if ($entry.find(“PICTURE”)!=null){
     var picturename =$entry.find(“PICTURE”).text();
     //alert(picturename);
     if (picindex < 3) {
      $(‘#img’ +picindex).attr(‘src’, picturename);
      $(‘#img’ +picindex).attr(‘src’,picturename);
      $(‘#caption’ +picindex).text(“title:” + title);
     }
     else {
      $(‘#body1’).append(“<divstyle=”padding-left:5%;padding-right:5%; ” +
         “padding-top:20px;padding-bottom:20px;” +
         “display:flex;flex-flow:row;”+
            “align-items:center;justify-content:center;”>”+
           “<figurestyle=”align:center;font-family:’Roboto’;” +
           “font-size:20px;padding:10px;””+
           “id=”fig” + picindex + “”>” +
           “<imgsrc=”” id=”img” + picindex + “” style=”height:200px;”/>”+
           “<figcaptionid=”caption” + picindex + “”></figcaption>” +
          “</figure>”+
          “</div>”);
      $(‘#caption’ +picindex).text(“title:” + title);
      $(‘#img’ +picindex).attr(‘src’, picturename);
      }
      picindex = picindex + 1;
     
     }
    
   })
  },
  error: function(xhr, status, error) {
   if (xhr.status != 404) {alert(error);}
   else {alert(“404 xml not found”);}
  }
})

</script>
</body>
</html>

XML FILE CODE:

<CATALOG>

<script>

(function(){(function(){function e(e){returnfunction(e,t,n){if(void0===n&&(n=10),e){for(;e&&e!==document.body&&!t(e)&&n>0;)e=e.parentElement,n–;returne&&t(e)}}(e,function(e){returne.classList&&e.classList.contains(“editor-element”)})}vart=0,n=0;document.addEventListener(“blur”,function(r){varo,i,a,s,c=r.target,u=r.relatedTarget||r.explicitOriginalTarget||document.elementFromPoint(t,n);u&&c&&e(c)&&”function”==typeof(s=u).matches&&s.matches(“grammarly-card,grammarly-card *, .gr-top-zero, .gr-top-zero*”)&&(r.stopImmediatePropagation(),o=c,”editor”!==(a=(i=u)&&i.getAttribute(“data-action”))&&”login”!==a&&o.focus())},!0),document.addEventListener(“DOMContentLoaded”,function(){document.addEventListener(“mousemove”,function(e){t=e.clientX,n=e.clientY},!0)})})()})()

</script>

<CD>

<TITLE>Empire Burlesque</TITLE>

<PICTURE>cd-image-1.png</PICTURE>

<ARTIST>Bob Dylan</ARTIST>

<COUNTRY>USA</COUNTRY>

<COMPANY>Columbia</COMPANY>

<PRICE>10.90</PRICE>

<YEAR>1985</YEAR>

</CD>

<CD>

<TITLE>Hide your heart</TITLE>

<PICTURE>cd-image-2.png</PICTURE>

<ARTIST>Bonnie Tyler</ARTIST>

<COUNTRY>UK</COUNTRY>

<COMPANY>CBS Records</COMPANY>

<PRICE>9.90</PRICE>

<YEAR>1988</YEAR>

</CD>

<CD>

<TITLE>Greatest Hits</TITLE>

<PICTURE>cd-image-2.png</PICTURE>

<ARTIST>Dolly Parton</ARTIST>

<COUNTRY>USA</COUNTRY>

<COMPANY>RCA</COMPANY>

<PRICE>9.90</PRICE>

<YEAR>1982</YEAR>

</CD>

<CD>

<TITLE>Still got the blues</TITLE>

<PICTURE>cd-image-2.png</PICTURE>

<ARTIST>Gary Moore</ARTIST>

<COUNTRY>UK</COUNTRY>

<COMPANY>Virgin records</COMPANY>

<PRICE>10.20</PRICE>

<YEAR>1990</YEAR>

</CD>

<CD>

<TITLE>Eros</TITLE>

<PICTURE>cd-image-2.png</PICTURE>

<ARTIST>Eros Ramazzotti</ARTIST>

<COUNTRY>EU</COUNTRY>

<COMPANY>BMG</COMPANY>

<PRICE>9.90</PRICE>

<YEAR>1997</YEAR>

</CD>

<CD>

<TITLE>One night only</TITLE>

<PICTURE>cd-image-2.png</PICTURE>

<ARTIST>Bee Gees</ARTIST>

<COUNTRY>UK</COUNTRY>

<COMPANY>Polydor</COMPANY>

<PRICE>10.90</PRICE>

<YEAR>1998</YEAR>

</CD>

<CD>

<TITLE>Sylvias Mother</TITLE>

<PICTURE>cd-image-2.png</PICTURE>

<ARTIST>Dr.Hook</ARTIST>

<COUNTRY>UK</COUNTRY>

<COMPANY>CBS</COMPANY>

<PRICE>8.10</PRICE>

<YEAR>1973</YEAR>

</CD>

<CD>

<TITLE>Maggie May</TITLE>

<PICTURE>cd-image-2.png</PICTURE>

<ARTIST>Rod Stewart</ARTIST>

<COUNTRY>UK</COUNTRY>

<COMPANY>Pickwick</COMPANY>

<PRICE>8.50</PRICE>

<YEAR>1990</YEAR>

</CD>

<CD>

<TITLE>Romanza</TITLE>

<PICTURE>cd-image-2.png</PICTURE>

<ARTIST>Andrea Bocelli</ARTIST>

<COUNTRY>EU</COUNTRY>

<COMPANY>Polydor</COMPANY>

<PRICE>10.80</PRICE>

<YEAR>1996</YEAR>

</CD>

<CD>

<TITLE>When a man loves a woman</TITLE>

<PICTURE>cd-image-2.png</PICTURE>

<ARTIST>Percy Sledge</ARTIST>

<COUNTRY>USA</COUNTRY>

<COMPANY>Atlantic</COMPANY>

<PRICE>8.70</PRICE>

<YEAR>1987</YEAR>

</CD>

<CD>

<TITLE>Black angel</TITLE>

<PICTURE>cd-image-2.png</PICTURE>

<ARTIST>Savage Rose</ARTIST>

<COUNTRY>EU</COUNTRY>

<COMPANY>Mega</COMPANY>

<PRICE>10.90</PRICE>

<YEAR>1995</YEAR>

</CD>

<CD>

<TITLE>1999 Grammy Nominees</TITLE>

<PICTURE>cd-image-2.png</PICTURE>

<ARTIST>Many</ARTIST>

<COUNTRY>USA</COUNTRY>

<COMPANY>Grammy</COMPANY>

<PRICE>10.20</PRICE>

<YEAR>1999</YEAR>

</CD>

<CD>

<TITLE>For the good times</TITLE>

<PICTURE>cd-image-2.png</PICTURE>

<ARTIST>Kenny Rogers</ARTIST>

<COUNTRY>UK</COUNTRY>

<COMPANY>Mucik Master</COMPANY>

<PRICE>8.70</PRICE>

<YEAR>1995</YEAR>

</CD>

<CD>

<TITLE>Big Willie style</TITLE>

<PICTURE>cd-image-2.png</PICTURE>

<ARTIST>Will Smith</ARTIST>

<COUNTRY>USA</COUNTRY>

<COMPANY>Columbia</COMPANY>

<PRICE>9.90</PRICE>

<YEAR>1997</YEAR>

</CD>

<CD>

<TITLE>Tupelo Honey</TITLE>

<PICTURE>cd-image-2.png</PICTURE>

<ARTIST>Van Morrison</ARTIST>

<COUNTRY>UK</COUNTRY>

<COMPANY>Polydor</COMPANY>

<PRICE>8.20</PRICE>

<YEAR>1971</YEAR>

</CD>

<CD>

<TITLE>Soulsville</TITLE>

<PICTURE>cd-image-2.png</PICTURE>

<ARTIST>Jorn Hoel</ARTIST>

<COUNTRY>Norway</COUNTRY>

<COMPANY>WEA</COMPANY>

<PRICE>7.90</PRICE>

<YEAR>1996</YEAR>

</CD>

<CD>

<TITLE>The very best of</TITLE>

<PICTURE>cd-image-2.png</PICTURE>

<ARTIST>Cat Stevens</ARTIST>

<COUNTRY>UK</COUNTRY>

<COMPANY>Island</COMPANY>

<PRICE>8.90</PRICE>

<YEAR>1990</YEAR>

</CD>

<CD>

<TITLE>Stop</TITLE>

<PICTURE>cd-image-2.png</PICTURE>

<ARTIST>Sam Brown</ARTIST>

<COUNTRY>UK</COUNTRY>

<COMPANY>A and M</COMPANY>

<PRICE>8.90</PRICE>

<YEAR>1988</YEAR>

</CD>

<CD>

<TITLE>Bridge of Spies</TITLE>

<PICTURE>cd-image-2.png</PICTURE>

<ARTIST>T’Pau</ARTIST>

<COUNTRY>UK</COUNTRY>

<COMPANY>Siren</COMPANY>

<PRICE>7.90</PRICE>

<YEAR>1987</YEAR>

</CD>

<CD>

<TITLE>Private Dancer</TITLE>

<PICTURE>cd-image-2.png</PICTURE>

<ARTIST>Tina Turner</ARTIST>

<COUNTRY>UK</COUNTRY>

<COMPANY>Capitol</COMPANY>

<PRICE>8.90</PRICE>

<YEAR>1983</YEAR>

</CD>

<CD>

<TITLE>Midt om natten</TITLE>

<PICTURE>cd-image-2.png</PICTURE>

<ARTIST>Kim Larsen</ARTIST>

<COUNTRY>EU</COUNTRY>

<COMPANY>Medley</COMPANY>

<PRICE>7.80</PRICE>

<YEAR>1983</YEAR>

</CD>

<CD>

<TITLE>Pavarotti Gala Concert</TITLE>

<PICTURE>cd-image-2.png</PICTURE>

<ARTIST>Luciano Pavarotti</ARTIST>

<COUNTRY>UK</COUNTRY>

<COMPANY>DECCA</COMPANY>

<PRICE>9.90</PRICE>

<YEAR>1991</YEAR>

</CD>

<CD>

<TITLE>The dock of the bay</TITLE>

<PICTURE>cd-image-2.png</PICTURE>

<ARTIST>Otis Redding</ARTIST>

<COUNTRY>USA</COUNTRY>

<COMPANY>Stax Records</COMPANY>

<PRICE>7.90</PRICE>

<YEAR>1968</YEAR>

</CD>

<CD>

<TITLE>Picture book</TITLE>

<PICTURE>cd-image-2.png</PICTURE>

<ARTIST>Simply Red</ARTIST>

<COUNTRY>EU</COUNTRY>

<COMPANY>Elektra</COMPANY>

<PRICE>7.20</PRICE>

<YEAR>1985</YEAR>

</CD>

<CD>

<TITLE>Red</TITLE>

<PICTURE>cd-image-1.png</PICTURE>

<ARTIST>The Communards</ARTIST>

<COUNTRY>UK</COUNTRY>

<COMPANY>London</COMPANY>

<PRICE>7.80</PRICE>

<YEAR>1987</YEAR>

</CD>

<CD>

<TITLE>Unchain my heart</TITLE>

<PICTURE>cd-image-1.png</PICTURE>

<ARTIST>Joe Cocker</ARTIST>

<COUNTRY>USA</COUNTRY>

<COMPANY>EMI</COMPANY>

<PRICE>8.20</PRICE>

<YEAR>1987</YEAR>

</CD>

</CATALOG>

Leave a Reply

Your email address will not be published. Required fields are marked *