smart_str_free(&nstype);
}
+static xmlNsPtr xmlSearchNsPrefixByHref(xmlDocPtr doc, xmlNodePtr node, const xmlChar * href)
+{
+ xmlNsPtr cur;
+ xmlNodePtr orig = node;
+
+ while (node) {
+ if (node->type == XML_ENTITY_REF_NODE ||
+ node->type == XML_ENTITY_NODE ||
+ node->type == XML_ENTITY_DECL) {
+ return NULL;
+ }
+ if (node->type == XML_ELEMENT_NODE) {
+ cur = node->nsDef;
+ while (cur != NULL) {
+ if (cur->prefix && cur->href && xmlStrEqual(cur->href, href)) {
+ if (xmlSearchNs(doc, node, cur->prefix) == cur) {
+ return cur;
+ }
+ }
+ cur = cur->next;
+ }
+ if (orig != node) {
+ cur = node->ns;
+ if (cur != NULL) {
+ if (cur->prefix && cur->href && xmlStrEqual(cur->href, href)) {
+ if (xmlSearchNs(doc, node, cur->prefix) == cur) {
+ return cur;
+ }
+ }
+ }
+ }
+ }
+ node = node->parent;
+ }
+ return NULL;
+}
+
xmlNsPtr encode_add_ns(xmlNodePtr node, const char* ns)
{
xmlNsPtr xmlns;
}
xmlns = xmlSearchNsByHref(node->doc, node, BAD_CAST(ns));
+ if (xmlns != NULL && xmlns->prefix == NULL) {
+ xmlns = xmlSearchNsPrefixByHref(node->doc, node, BAD_CAST(ns));
+ }
if (xmlns == NULL) {
xmlChar* prefix;
TSRMLS_FETCH();
smart_str prefix = {0};
int num = ++SOAP_GLOBAL(cur_uniq_ns);
- smart_str_appendl(&prefix, "ns", 2);
- smart_str_append_long(&prefix, num);
- smart_str_0(&prefix);
+ while (1) {
+ smart_str_appendl(&prefix, "ns", 2);
+ smart_str_append_long(&prefix, num);
+ smart_str_0(&prefix);
+ if (xmlSearchNs(node->doc, node, BAD_CAST(prefix.c)) == NULL) {
+ break;
+ }
+ smart_str_free(&prefix);
+ prefix.c = NULL;
+ prefix.len = 0;
+ num = ++SOAP_GLOBAL(cur_uniq_ns);
+ }
+
xmlns = xmlNewNs(node->doc->children, BAD_CAST(ns), BAD_CAST(prefix.c));
smart_str_free(&prefix);
}
--- /dev/null
+--TEST--
+SOAP typemap 13: SoapServer support for typemap's to_xml() with default ns
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+$GLOBALS['HTTP_RAW_POST_DATA']="
+<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"
+ xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
+ xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
+ xmlns:enc=\"http://schemas.xmlsoap.org/soap/encoding/\"
+ xmlns:ns1=\"http://schemas.nothing.com\"
+>
+ <env:Body>
+<ns1:dotest2>
+<dotest2 xsi:type=\"xsd:string\">???</dotest2>
+</ns1:dotest2>
+ </env:Body>
+<env:Header/>
+</env:Envelope>";
+
+function book_to_xml($book) {
+ return '<book xmlns="http://schemas.nothing.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><a xsi:type="xsd:string">'.$book->a.'!</a><b xsi:type="xsd:string">'.$book->b.'!</b></book>';
+}
+
+class test{
+ function dotest2($str){
+ $book = new book;
+ $book->a = "foo";
+ $book->b = "bar";
+ return $book;
+ }
+}
+
+class book{
+ public $a="a";
+ public $b="c";
+
+}
+
+$options=Array(
+ 'actor' =>'http://schemas.nothing.com',
+ 'typemap' => array(array("type_ns" => "http://schemas.nothing.com",
+ "type_name" => "book",
+ "to_xml" => "book_to_xml"))
+ );
+
+$server = new SoapServer(dirname(__FILE__)."/classmap.wsdl",$options);
+$server->setClass("test");
+$server->handle();
+echo "ok\n";
+?>
+--EXPECT--
+<?xml version="1.0" encoding="UTF-8"?>
+<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.nothing.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:dotest2Response><book xmlns="http://schemas.nothing.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns1:book"><a xsi:type="xsd:string">foo!</a><b xsi:type="xsd:string">bar!</b></book></ns1:dotest2Response></SOAP-ENV:Body></SOAP-ENV:Envelope>
+ok