Project

General

Profile

1 1 wheeler
<?php
2
#############################################################################
3
# Builds the xml body to be sent to Tapir service.  Only put in a
4
# seperate file because there is a lot of code-invarient text that would
5
# just make other parts of the script difficult to read.
6
#############################################################################
7
8
require_once('configurableParams.php');
9
10
function buildStructure($supportedConcepts) {
11
  $structureStr = '';
12
  foreach(array_keys($supportedConcepts) as $key){
13
    $structureStr .=
14
      "              <xs:element name=\"$key\" type=\"xs:string\" minOccurs=\"0\"/>\n";
15
  }
16
  return $structureStr;
17
}
18
19
function buildMap($supportedConcepts) {
20
  $mapStr = '';
21
  foreach(array_keys($supportedConcepts) as $key){
22
    $mapStr .=
23
      "        <node path=\"/records/record/$key\">\n".
24
      "          <concept id=\"$supportedConcepts[$key]\"/>\n".
25
      "        </node>\n";
26
  }
27
  return $mapStr;
28
}
29
30
function buildRequest($start,$limit,$supportedConcepts) {
31
32
  $xmlRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n".
33
  "<request \n".
34
  "    xmlns=\"http://rs.tdwg.org/tapir/1.0\"\n".
35
  "    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n".
36
  "    xsi:schemaLocation=\"http://rs.tdwg.org/tapir/1.0 \n".
37
  "                        http://rs.tdwg.org/tapir/1.0/schema/tapir.xsd\">\n".
38
  "  <header>\n".
39
  "  </header>\n".
40
  "  <search count=\"true\" start=\"$start\" limit=\"$limit\" envelope=\"true\">\n".
41
  "    <outputModel>\n".
42
  "      <structure>\n".
43
  "        <xs:schema targetNamespace=\"http://example.net/simple_specimen\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xsi:schemaLocation=\"http://www.w3.org/2001/XMLSchema http://www.w3.org/2001/XMLSchema.xsd\">\n".
44
  "          <xs:element name=\"records\">\n".
45
  "            <xs:complexType>\n".
46
  "              <xs:sequence>\n".
47
  "                <xs:element name=\"record\" minOccurs=\"0\" maxOccurs=\"unbounded\" type=\"unitType\">\n".
48
  "                </xs:element>\n".
49
  "              </xs:sequence>\n".
50
  "            </xs:complexType>\n".
51
  "          </xs:element>\n".
52
  "          <xs:complexType name=\"unitType\">\n".
53
  "            <xs:sequence>\n".
54
               buildStructure($supportedConcepts).
55
  "            </xs:sequence>\n".
56
  "          </xs:complexType>\n".
57
  "        </xs:schema>\n".
58
  "      </structure>\n".
59
  "      <indexingElement path=\"/records/record\"/>\n".
60
  "      <mapping>\n".
61
         buildMap($supportedConcepts).
62
  "      </mapping>\n".
63
  "    </outputModel>\n".
64
  "    <filter>\n".
65
         buildFilter().
66
  "    </filter>\n".
67
  "  </search>\n".
68
  "</request>\n";
69
70
  return $xmlRequest;
71
}
72
73
function buildCapabilitiesRequest() {
74
  $xmlRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n".
75
  "<request \n".
76
  "    xmlns=\"http://rs.tdwg.org/tapir/1.0\"\n".
77
  "    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n".
78
  "    xsi:schemaLocation=\"http://rs.tdwg.org/tapir/1.0 \n".
79
  "                        http://rs.tdwg.org/tapir/1.0/schema/tapir.xsd\">\n".
80
  "  <header>\n".
81
  "  </header>\n".
82
  "  <capabilities />\n".
83
  "</request>\n";
84
85
  return $xmlRequest;
86
}
87
88
?>