I want to bind data from and XML document into and HTML using d3.js. Currently I have XML like this:
<data>
<fields>Unique Terms</fields>
<term>Roof</term>
<term>Snow</term>
<term>Chains</term>
<term>Bars</term>
<term>Seat</term>
<fields>Clicks</fields>
<clicks>135</clicks>
<clicks>09</clicks>
<clicks>4379</clicks>
<clicks>39</clicks>
<clicks>466</clicks>
<fields>Impressions</fields>
</data>
And my d3.js script like this:
d3.xml("values.xml", "application/xml", function(xml) {
var fieldNames = d3.select(xml).selectAll("fields")[0];
var termNames = d3.select(xml).selectAll("term")[0];
d3.select('.container')
.selectAll('div')
.data(fieldNames)
.enter()
.append('div')
.text(function(d) {
return d.textContent;
})
d3.select('.container')
.selectAll('div')
.data(termNames)
.enter()
.append('div')
.text(function(d) {
return d.textContent;
})
});
Frustratingly it shows the fields textcontent but not the nested 'term' content. Anybody know what's up?
No comments:
Post a Comment