Skip to content

Instantly share code, notes, and snippets.

@milkbread
Created September 9, 2013 09:10
Show Gist options
  • Select an option

  • Save milkbread/6493277 to your computer and use it in GitHub Desktop.

Select an option

Save milkbread/6493277 to your computer and use it in GitHub Desktop.
XML: WPS-requests

Simple test on d3.xml()

...how to make request the WebGen-WPS and list the corresponding elements

Thank you Mike, for the good help!

####!!!Attention - NOT applicable because in most browsers is...

Cross-origin not allowed!!!

You have to build a test-environment ... needs a local version of WebGen-WPS

    1. Start Tomcat
    • start Eclipse: Workspace = /home/klammer/Software/WebGen-WPS/wps-eclipse-workspace
    • start Tomcat
    • (login on server with browser: username="tomcat" password="s3cret")
    1. Throw this file on local 'server'
    • goto: /usr/local/tomcat/webapps
    • goto OR make: /html_stuff
    • make sure there is a simple 'index.html' inside, containing a link on this file
    • copy this file into '/usr/local/tomcat/webapps/html_stuff'
    1. Start it
<!DOCTYPE html>
<html>
<head>
<title>'DescribeProcess' - request</title>
<script src="http://d3js.org/d3.v3.min.js"></script>
<link rel="stylesheet" href="styles.css"></link>
<style>
</style>
</head>
<body>
<h3>Testing a 'DescribeProcess' - request</h3>
</body>
<script>
var url = 'http://localhost:8080/wps-origin/wps?service=WPS&Request=GetCapabilities&AcceptVersions=1.0.0&language=en-GB';
url = 'http://localhost:8080/wps-origin/wps?service=WPS&Request=DescribeProcess&version=1.0.0&language=en-GB&Identifier=ch.unizh.geo.webgen.service.LineSmoothing';
d3.xml(url)
.on("progress", function() {
console.log('hey')
})
.get(function(error, xml) {
//console.log(xml)
//console.log(xml.documentElement.getElementsByTagName("Input"))
//console.log(d3.select(xml).selectAll('Input')[0])
var inputs = d3.select(xml).selectAll('Input')[0]
//console.dir(inputs[0])
var input_text = d3.select('body').selectAll('div').data(inputs).enter().append('div');
input_text.append('p')
.attr('class','main')
.text(function(d,i){
return d.nodeName +' '+ i + ': ' + d3.select(d).selectAll('Identifier')[0][0].textContent})
input_text.selectAll('.values')
.data(function(d){return d.childNodes}).enter().append('p')
.attr('class',function(d){
if(d.localName!=null) return 'values';
else return 'trash';})
d3.selectAll('.values')
.text(function(d){
//console.dir(d);
return d.localName + ': ' + d.textContent;
})
d3.selectAll('.trash').remove();
});
</script>
</html>
<!DOCTYPE html>
<html>
<head>
<title>'DescribeProcess' - request</title>
<script src="http://d3js.org/d3.v3.min.js"></script>
<link rel="stylesheet" href="styles.css"></link>
<style>
</style>
</head>
<body>
</body>
<script>
var url = 'http://localhost:8080/wps-origin/wps?service=WPS&Request=GetCapabilities&AcceptVersions=1.0.0&language=en-GB';
//url = 'http://localhost:8080/wps-origin/wps?service=WPS&Request=DescribeProcess&version=1.0.0&language=en-GB&Identifier=ch.unizh.geo.webgen.service.LineSmoothing';
d3.xml(url)
.on("progress", function() {
console.log('hey')
})
.get(function(error, xml) {
//console.log(xml)
//console.log(xml.documentElement.getElementsByTagName("Input"))
//console.log(d3.select(xml).selectAll('Input')[0])
var processes = d3.select(xml).selectAll('Process')[0]
console.dir(processes)
var input_text = d3.select('body').selectAll('div').data(processes).enter().append('div');
input_text.append('p').attr('class','main')
.text(function(d,i){
var identifier = d.childNodes[1].textContent;
var ident = identifier;
var cache = ident.split('.');
ident = cache[cache.length-1];
return d.localName +' '+ i + ': '+ ident})
input_text.selectAll('.values')
.data(function(d){return d.childNodes}).enter().append('p')
.attr('class',function(d){
if(d.localName!=null) return 'values';
else return 'trash';})
d3.selectAll('.values')
.text(function(d){
//console.dir(d);
return d.localName + ': ' + d.textContent;
})
d3.selectAll('.trash').remove();
});
</script>
</html>
.values{
margin-left:30px;
background-color:#ccc;
}
.main{
background-color:#444;
color:#fff;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment