From the course: D3.js Essential Training for Data Scientists

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Parsing and mapping XML

Parsing and mapping XML - D3.js Tutorial

From the course: D3.js Essential Training for Data Scientists

Start my 1-month free trial

Parsing and mapping XML

- [Instructor] Now we're going to take a look at the data handler for xml. And here's an xml file that I prepared earlier. You can see we have each of the letters of the alphabet A to zed and a numeric value called frequency against each one. You can copy what's on the screen if you don't have access to the files. And bear in mind, you don't need all 26 letters. You can just copy, say five, if you like. As long as you keep the structure exactly the same. So you need to keep the xml declaration, the enclosing data tags, the letter tags, which contain an ID and the frequency tags which contain a number. The data handler for xml works in much the same way as the one for JSON. You use d3.xml to load the file. And my ones called data.xml and then you have .get within which we put function (error, data) and we can shift that down a bit. And I'm just gonna comment out these logs over here like so. So the first thing we're going to do is log our new data variable to the console. And you see…

Contents