Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <style>
- p { font-size:30px; }
- </style>
- <script type="text/javascript">
- var xmlDoc;
- var pozycja=0; // wskazuje numer aktualnie wyświetlanego elementu pliku XML
- // Funkcja czytająca --plik-- XML
- function loadXML()
- {
- var xml = document.getElementById('xml').innerHTML;
- xmlDoc = new DOMParser().parseFromString(xml, 'text/xml');
- showXML();
- }
- function showXML() //Funkcja uruchamiana przy wczytywaniu pliku XML i przy naciskaniu przycisków
- {
- // Do elementów dokumentu XML można się odwoływać poprzez funkcję getElementsByTagName() która zwraza kolekcję elementów
- // Długość kolekcji sprawdza się korzystając z własności length np. xmlDoc.getElementsByTagName("cd") .length zwraca ilość elementów "cd"
- // w pliku podpiętym do obiektu xmlDoc
- document.getElementById("intro").innerHTML="My collection of " + xmlDoc.getElementsByTagName("catalog")[0].attributes[0].value;
- document.getElementById("artist").innerHTML=xmlDoc.getElementsByTagName("artist")[pozycja].childNodes[0].nodeValue;
- document.getElementById("title").innerHTML=xmlDoc.getElementsByTagName("title")[pozycja].childNodes[0].nodeValue;
- document.getElementById("year").innerHTML=xmlDoc.getElementsByTagName("year")[pozycja].childNodes[0].nodeValue;
- //xmlDoc.getElementsByTagName("cd")[pozycja].attributes zwraca kolekcję atrybutów elementu "cd" o numerze kolejnym pozycja
- if (xmlDoc.getElementsByTagName("cd")[pozycja].attributes.length>0)
- {
- if (xmlDoc.getElementsByTagName("cd")[pozycja].attributes.getNamedItem("cool").value=="cool")
- {
- document.getElementById("comm").innerHTML="It is cool!!!"
- }
- }
- else
- {
- document.getElementById("comm").innerHTML=" ";
- }
- }
- function nextXML()
- {
- pozycja++;
- if (pozycja>=xmlDoc.getElementsByTagName("cd").length) pozycja=0;
- showXML();
- }
- function previousXML()
- {
- pozycja--;
- if (pozycja<0) pozycja=xmlDoc.getElementsByTagName("cd").length-1;
- showXML();
- }
- </script>
- </head>
- <body onload="loadXML()">
- <h1 id="intro"></h1>
- <br/>
- <br/>
- <button name="Next" onclick="nextXML()">Next record</button>
- <button name="Previous" onclick="previousXML()">Previous record</button>
- <p><b>Artist:</b> <span id="artist"></span></p>
- <p><b>Title:</b> <span id="title"></span></p>
- <p><b>Year:</b> <span id="year"></span></p>
- <p><span id="comm"></span></p>
- <script id="xml" type="text/xml">
- <catalog type="Cool Music">
- <cd cool="cool">
- <title>Empire Burlesque</title>
- <artist>Bob Dylan</artist>
- <country>USA</country>
- <company>Columbia</company>
- <price>10.90</price>
- <year>1985</year>
- </cd>
- <cd>
- <title>King's Burlesque</title>
- <artist>Bob Dylan</artist>
- <country>USA</country>
- <company>Columbia</company>
- <price>10.90</price>
- <year>1987</year>
- </cd>
- <cd cool="cool">
- <title>Prince's Burlesque</title>
- <artist>Bob Dylan</artist>
- <country>USA</country>
- <company>Columbia</company>
- <price>10.90</price>
- <year>1990</year>
- </cd>
- <cd>
- <title>Hide your heart</title>
- <artist>Bonnie Tyler</artist>
- <country>UK</country>
- <company>CBS Records</company>
- <price>9.90</price>
- <year>1988</year>
- </cd>
- <cd>
- <title>Show your heart</title>
- <artist>Bonnie Tyler</artist>
- <country>UK</country>
- <company>CBS Records</company>
- <price>10.90</price>
- <year>1989</year>
- </cd>
- <cd>
- <title>Hide your stomach</title>
- <artist>Bonnie Tyler</artist>
- <country>UK</country>
- <company>CBS Records</company>
- <price>11.90</price>
- <year>1990</year>
- </cd>
- <cd cool="cool">
- <title>Greatest Hits</title>
- <artist>DollyParton</artist>
- <country>USA</country>
- <company>RCA</company>
- <price>9.90</price>
- <year>1982</year>
- </cd>
- <cd cool="cool">
- <title>Poorest Hits</title>
- <artist>DollyParton</artist>
- <country>USA</country>
- <company>RCA</company>
- <price>9.90</price>
- <year>1986</year>
- </cd>
- <cd>
- <title>Still got the blues</title>
- <artist>Gary Moore</artist>
- <country>UK</country>
- <company>Virgin records</company>
- <price>10.20</price>
- <year>1990</year>
- </cd>
- <cd>
- <title>Still got the saltzesson</title>
- <artist>Gary Moore</artist>
- <country>UK</country>
- <company>Virgin records</company>
- <price>10.20</price>
- <year>1995</year>
- </cd>
- <cd>
- <title>Still got the caschancka</title>
- <artist>Gary Moore</artist>
- <country>UK</country>
- <company>Virgin records</company>
- <price>10.20</price>
- <year>1997</year>
- </cd>
- <cd>
- <title>Still got the smalletz</title>
- <artist>Gary Moore</artist>
- <country>UK</country>
- <company>Virgin records</company>
- <price>10.20</price>
- <year>2000</year>
- </cd>
- <cd>
- <title>Eros</title>
- <artist>Eros Ramazzotti</artist>
- <country>EU</country>
- <company>BMG</company>
- <price>9.90</price>
- <year>1997</year>
- </cd>
- <cd>
- <title>Mars</title>
- <artist>Eros Ramazzotti</artist>
- <country>EU</country>
- <company>BMG</company>
- <price>9.90</price>
- <year>1998</year>
- </cd>
- <cd>
- <title>Venera</title>
- <artist>Eros Ramazzotti</artist>
- <country>EU</country>
- <company>BMG</company>
- <price>9.90</price>
- <year>2000</year>
- </cd>
- <cd>
- <title>One night only</title>
- <artist>Bee Gees</artist>
- <country>UK</country>
- <company>Polydor</company>
- <price>10.90</price>
- <year>1998</year>
- </cd>
- <cd>
- <title>One way only</title>
- <artist>Bee Gees</artist>
- <country>UK</country>
- <company>Polydor</company>
- <price>10.90</price>
- <year>1999</year>
- </cd>
- <cd>
- <title>Last night only</title>
- <artist>Bee Gees</artist>
- <country>UK</country>
- <company>Polydor</company>
- <price>10.90</price>
- <year>2000</year>
- </cd>
- <cd>
- <title>Sylvias Mother</title>
- <artist>Dr.Hook</artist>
- <country>UK</country>
- <company>CBS</company>
- <price>8.10</price>
- <year>1973</year>
- </cd>
- <cd>
- <title>Sylvias Father</title>
- <artist>Dr.Hook</artist>
- <country>UK</country>
- <company>CBS</company>
- <price>8.10</price>
- <year>1975</year>
- </cd>
- <cd>
- <title>Sylvias Little Pet</title>
- <artist>Dr.Hook</artist>
- <country>UK</country>
- <company>CBS</company>
- <price>8.10</price>
- <year>1978</year>
- </cd>
- <cd>
- <title>Maggie May</title>
- <artist>Rod Stewart</artist>
- <country>UK</country>
- <company>Pickwick</company>
- <price>8.50</price>
- <year>1990</year>
- </cd>
- <cd>
- <title>Maggie the Cashaloth</title>
- <artist>Rod Stewart</artist>
- <country>UK</country>
- <company>Pickwick</company>
- <price>8.50</price>
- <year>1990</year>
- </cd>
- <cd cool="cool">
- <title>Romanza</title>
- <artist>Andrea Bocelli</artist>
- <country>EU</country>
- <company>Polydor</company>
- <price>10.80</price>
- <year>1996</year>
- </cd>
- <cd cool="cool">
- <title>Randevoux</title>
- <artist>Andrea Bocelli</artist>
- <country>EU</country>
- <company>Polydor</company>
- <price>10.80</price>
- <year>1998</year>
- </cd>
- <cd>
- <title>When a man loves a woman</title>
- <artist>Percy Sledge</artist>
- <country>USA</country>
- <company>Atlantic</company>
- <price>8.70</price>
- <year>1987</year>
- </cd>
- <cd>
- <title>When a man loves a man</title>
- <artist>Percy Sledge</artist>
- <country>USA</country>
- <company>Atlantic</company>
- <price>8.70</price>
- <year>1988</year>
- </cd>
- <cd>
- <title>When a woman loves a woman</title>
- <artist>Percy Sledge</artist>
- <country>USA</country>
- <company>Atlantic</company>
- <price>8.70</price>
- <year>1989</year>
- </cd>
- <cd>
- <title>Black angel</title>
- <artist>Savage Rose</artist>
- <country>EU</country>
- <company>Mega</company>
- <price>10.90</price>
- <year>1995</year>
- </cd>
- <cd>
- <title>Blue angel</title>
- <artist>Savage Rose</artist>
- <country>EU</country>
- <company>Mega</company>
- <price>10.90</price>
- <year>1997</year>
- </cd>
- <cd>
- <title>RGB(20,130,80) angel</title>
- <artist>Savage Rose</artist>
- <country>EU</country>
- <company>Mega</company>
- <price>10.90</price>
- <year>1999</year>
- </cd>
- <cd>
- <title>1999 Grammy Nominees</title>
- <artist>Many</artist>
- <country>USA</country>
- <company>Grammy</company>
- <price>10.20</price>
- <year>1999</year>
- </cd>
- <cd cool="cool">
- <title>For the good times</title>
- <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>
- <artist>Will Smith</artist>
- <country>USA</country>
- <company>Columbia</company>
- <price>9.90</price>
- <year>1997</year>
- </cd>
- <cd>
- <title>Tupelo Honey</title>
- <artist>Van Morrison</artist>
- <country>UK</country>
- <company>Polydor</company>
- <price>8.20</price>
- <year>1971</year>
- </cd>
- <cd>
- <title>Soulsville</title>
- <artist>JBiorn Hoel</artist>
- <country>Norway</country>
- <company>WEA</company>
- <price>7.90</price>
- <year>1996</year>
- </cd>
- <cd>
- <title>The very best of</title>
- <artist>Cat Stevens</artist>
- <country>UK</country>
- <company>Island</company>
- <price>8.90</price>
- <year>1990</year>
- </cd>
- <cd>
- <title>Stop</title>
- <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>
- <artist>T`Pau</artist>
- <country>UK</country>
- <company>Siren</company>
- <price>7.90</price>
- <year>1987</year>
- </cd>
- <cd>
- <title>Private Dancer</title>
- <artist>Tina Turner</artist>
- <country>UK</country>
- <company>Capitol</company>
- <price>8.90</price>
- <year>1983</year>
- </cd>
- <cd>
- <title>Midt om natten</title>
- <artist>Kim Larsen</artist>
- <country>EU</country>
- <company>Medley</company>
- <price>7.80</price>
- <year>1983</year>
- </cd>
- <cd>
- <title>Pavarotti Gala Concert</title>
- <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>
- <artist>Otis Redding</artist>
- <country>USA</country>
- <company>Atlantic</company>
- <price>7.90</price>
- <year>1987</year>
- </cd>
- <cd>
- <title>Picture book</title>
- <artist>Simply Red</artist>
- <country>EU</country>
- <company>Elektra</company>
- <price>7.20</price>
- <year>1985</year>
- </cd>
- <cd>
- <title>Red</title>
- <artist>The Communards</artist>
- <country>UK</country>
- <company>London</company>
- <price>7.80</price>
- <year>1987</year>
- </cd>
- <cd>
- <title>Unchain my heart</title>
- <artist>Joe Cocker</artist>
- <country>USA</country>
- <company>EMI</company>
- <price>8.20</price>
- <year>1987</year>
- </cd>
- </catalog>
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement