-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added functionality to convert and display response data to html list
- Loading branch information
1 parent
6f15385
commit 7ba6705
Showing
3 changed files
with
25 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const jobList = html => `<ul>${html}</ul>`; | ||
const listItem = job => `<li><a href="${job.link}">${job.title}</a></li>`; | ||
|
||
const textToXml = text => new DOMParser().parseFromString(text, 'text/xml'); | ||
const xmlToHtml = (xml) => { | ||
const allJobs = [...xml.getElementsByTagName('entry')]; | ||
|
||
const html = allJobs.map((job) => { | ||
const title = job.getElementsByTagName('title')[0].childNodes[0].nodeValue; | ||
const link = job.getElementsByTagName('link')[0].getAttribute('href'); | ||
|
||
return listItem({ link, title }); | ||
}); | ||
|
||
return jobList(html.join('')); | ||
}; | ||
const appendData = (html) => { document.querySelector('.page-content').innerHTML = html; }; | ||
|
||
export { textToXml, xmlToHtml, appendData }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters