how works php soap server with attributes or is there a library that understands attributes?

I was trying to make a soap server in PHP and that works good, only the wsdl requires a attribute OptIn like:

<EmailAdresses>
    <Email OptIn="true">email@domain.com</Email>
</EmailAdresses>

Is there a good php library/classes that works with attributes? so that the Web service can return an array or something like that in a certain way and that those revenues to xml with attributes.

or how it works with the standard soap server from php ? because good documentation is hard to find.

thanks in advance

Answers


I've worked with SOAP services written in a number of languages, and I've never yet seen one which uses XML attributes -- they always simply use XML elements with a value inside the element (either a string or further elements).

I'm not saying you can't use attributes, but it seems that simple name-value pairs are a better fit for the kinds of data structures that most programming languages want to work with (ie simple variables or array trees).

But your question piqued my curiosity, so I've done a bit of digging for you.

As you say, the PHP manual really doesn't seem to be particularly forthcoming on the subject (which is unusual - it's generally quite a good resource), but if you really want to create attributes in your SOAP XML, I did find a few snippets which might help.

One suggestion which came up a few times was to use underscore as an array element in your data structure, and this would then become the value for the element, and other array keys would would become the attributes. Something like this:

$mydata = array('EmailAdresses' => array(
                    'Email' => array(
                         '_' => 'email@domain.com',
                         'OptIn' => 'true')
                     )
                );

The other suggestion I found was to create it as an object rather than as an array, using PHP's SimpleXML library, since this obviously explicitly allows the creation of XML attributes.

Sorry I don't have time to test those suggestions right now, but I hope that helps.


Need Your Help

C/C++ private array initialization in the header file

c++ arrays header initialization

I have a class called Cal and it's .cpp and .h counterpart

SQL Server Concatenate Rows Using Many-To-Many Related Tables

sql sql-server many-to-many string-concatenation

I've already searched for my problem, but most of the examples (if not all), have to deal with only one or two tables with a one-to-many relationship between them.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.