-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.php
More file actions
199 lines (195 loc) · 8.17 KB
/
Copy pathserver.php
File metadata and controls
199 lines (195 loc) · 8.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
include_once("nusoap-0.9.5/lib/nusoap.php");
function open_file($file=null){
if($file!==null){
$myfile = fopen(utf8_decode($file), "r") or die("Unable to open file!");
$data = "";
while ($line = fgets($myfile)) {
$data.=$line;
}
fclose($myfile);
/*
echo "<pre>";
echo htmlspecialchars($xmldata);
echo "</pre>";
*/
return $data;
}
}
function get_xmlt($file,$xmlt_name=null,$xpath=null){
if($xmlt_name!==null){
$xslt = new xsltProcessor;
$xslt->importStyleSheet(DomDocument::load($xmlt_name));
if($xpath===null){
$xslt_data = $xslt->transformToXML(DomDocument::loadXML($file));
}else{
$string = $xslt->transformToXML(DomDocument::loadXML($file));
$string = "<estados>".str_replace('<?xml version="1.0" encoding="UTF-8"?>',"",$string)."</estados>";
$xslt_data = new SimpleXMLElement( $string );
$xslt_data = $xslt_data->xpath($xpath)[0];
}
return $xslt_data;
}
}
/***********************************WS************************************/
$server = new nusoap_server();
$metodos = array(
'get_paises' => "metodo_get_paises",
'get_estados' => "metodo_get_estados",
'get_estado' => "metodo_get_estado_municipios"
);
$urn = array(
'url1' => "mi_ws1"
);
$ns = 'urn:'.$urn['url1'];
$endpoint = 'http://127.0.0.1/ws/index.php';
$server->configureWSDL('Web servicie de Eduardo',$ns);
$server->wsdl->schemaTargetNamespace = $ns;
// Parametros de entrada
/*
$server->wsdl->addComplexType( 'type_entrada_get_estados',
'complexType',
'struct',
'all',
'',
array(
'pais' => array(
'name' => 'pais',
'type' => 'xsd: string'
),
)
);
// Parametros de Salida
$server->wsdl->addComplexType( 'type_salida_get_estados',
'complexType',
'struct',
'all',
'',
array(
'mensaje' => array(
'name' => 'mensaje',
'type' => 'xsd:string'
)
)
);
*/
$server->register(
$metodos['get_paises'], // nombre del metodo o funcion
array(), // Estructura de parámetros de entrada
array('return' => 'xsd:string'), // Estructura de parámetros de salida
$ns // namespace
/*
$ns.'#'.$metodos['get_estados'], // soapaction debe ir asociado al nombre del metodo 'Acción soap'
'rpc', // style
'encoded', // use
'Devuelve los nombres de los países disponibles para el método metodo_get_estados' // documentation
*/
);
$server->register(
$metodos['get_estados'], // nombre del metodo o funcion
array('pais' => 'xsd:string'), // Estructura de parámetros de entrada
array('return' => 'xsd:string'), // Estructura de parámetros de salida
$ns // namespace
/*
$ns.'#'.$metodos['get_estados'], // soapaction debe ir asociado al nombre del metodo 'Acción soap'
'rpc', // style
'encoded', // use
'Este método recibe el nombre del país del que quiera los estados' // documentation
*/
);
$server->register(
$metodos['get_estado'], // nombre del metodo o funcion
array('estado' => 'xsd:string'), // Estructura de parámetros de entrada
array('return' => 'xsd:string'), // Estructura de parámetros de salida
$ns // namespace
/*
$ns.'#'.$metodos['get_estados'], // soapaction debe ir asociado al nombre del metodo 'Acción soap'
'rpc', // style
'encoded', // use
'Este método recibe el nombre del país del que quiera los estados' // documentation
*/
);
//$server->register(
//"MiFuncion",
//array(
// 'num1' => 'xsd:integer',
// 'num2' => 'xsd:integer'
//),array(
// 'return' => 'xsd:string'
//),
//$ns
//);
function metodo_get_paises(){
$url = "xml/paises/";
$xml = open_file($url."estados.xml");
$paises = get_xmlt($xml,$url.'get_paises.xsl');
return $paises;
}
function metodo_get_estados($pais=null){
if($pais!==null){
$url = "xml/estados/";
$xml = open_file($url."estados.xml");
$estados = get_xmlt($xml,$url."get_estados.xsl");
return $estados;
}
}
/**
* optiene todos los c_mnpio;
*
* @param [type] $estado
* @return void
*/
function xpath($data,$xpath){
$xslt_data = new SimpleXMLElement($data);
return $xslt_data->xpath($xpath)[0];
}
function metodo_get_estado_municipios($estado=null){
if($estado!==null){
$url1 = "xml/estados/";
$xml = open_file($url1."estados.xml");
$estados = get_xmlt($xml,$url1."get_all.xsl",'//*[@id="'.$estado.'"]/file');
$url2 = "xml/municipios/";
$xml_municipios = open_file($url2.$estados);
$municipios = get_xmlt($xml_municipios,$url2."get_municipios.xsl");
/*
libxml_use_internal_errors(true);
$DOMDocument = new DOMDocument();
$DOMDocument->loadXML($xml_estado); // the variable $ads contains the HTML code above
$saveXML = $DOMDocument->saveXML();
$xslt_data = xpath((string)$saveXML,"//NewDataSet");
$xml_string = "";
foreach ($xslt_data->children() as $value) {
$xml_string.= $value->asXML();
}
$xml_string = "<estados>".$xml_string."</estados>";
$xslt_data = xpath($xml_string,"//estados");
$tag_value = array();
foreach ($xslt_data->children() as $value) {
array_push($tag_value,$value->$tag->asXML() );
}
$tag_value = array_unique($tag_value);
$tag_value_xml = "";
foreach ($tag_value as $value2) {
$tag_value_xml.="<$tag>".$value2."</$tag>";
}
$tag_value_xml = "<".$tag."s>".$tag_value_xml."</".$tag."s>";
echo "<pre>";
print_r($tag_value_xml);
echo "</pre>";
*/
//print_r($municipios);
//die();
return $municipios;
}
}
//function MiFuncion($num1, $num2){
//$resultadoSuma = $num1 + $num2;
//$resultado = "El resultado de la suma de " . $num1 . "+" .$num2 . " es: " . $resultadoSuma;
//return $resultado;
//}
//echo metodo_get_estados('mexico');
//echo metodo_get_estado_municipios("22",'c_mnpio');
//metodo_get_estado('01');
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>