I am developing a xml-rpc server module and i have come to the point where i need to let user (developer using my module) validate XML against XSD. That is well documented and no problem, but i came to trouble when i try to check if XSD file is a valid XSD. I need to accomplish this internally in php, that excludes any online validators and other languages. External Modules, libraries or remote procedure calls are allowed, or maybe if this could be done by a xsd file that would check the validity of xsd itself, that would also be ok.
So here is the question:
How can i check if XML file is a valid XSD
There is an .xsd for XSD, as well as an DTD - see https://www.w3.org/XML/Schema#resources
XSD: http://www.w3.org/2001/XMLSchema.xsd
DTD: http://www.w3.org/2001/XMLSchema.dtd
Verification can be done with xmllint:
$ xmllint --schema=/path/to/XMLSchema.xsd file.xsd
Related
I want to build XSD files for my webservice, so other developers can easily work with it and generate their model classes from my XSD files.
I only find tools to generate PHP from XSD, but nothing to inverse.
How I can serialize my php model classes to XSD programmatically?
Thanks for the hint with the SDK XML Data Access Service ...
Got an idea while reading the manual :-)
I now write a XML File saving each Request and Response XML in a XML File.
Then I generate a XSD File from the XML File via xsd.exe delivered by Microsoft Visual Studio.
Then I edit the Datatype Properties in each XSD files ...
A bit of work, but better than writing the XSD files by hand
I don't know much about Delphi / ClientDataSets but I'm willing to look into it. I have a question before I pursue it though, to determine if what I want to achieve is feasible.
I want to use a PHP script to save a dozen subsets of my MYSQL database to CDS files once weekly. Is there a File specification that I can follow to create a CDS file? I'll be running the script on a shared web host using Linux, so I don't think running Delphi scripts on the server is viable.
Thanks!
There is a related question on Stackoverflow which includes a partial XSD:
Anyone that has a partial XSD that describes the METADATA section of Delphi TClientDataSet XML files?
You can use this XSD and an XML library to create XML files from your data which are compatible with TCLientDataSet, so they can be opened in a Delphi application.
I don't know PHP XML libraries, but in many languages XML libraries are able to create mapping code based on the XSD, which then can be used to read and write XML files based on the schema definition.
I have quite complex (authentication, logs, ...) SOAP server (standard PHP extension). Everything is working fine but I want to know if there is any tool for creating / generating WSDL file? All changes I do manually and there are two problems:
localhost
I have for testing reasons the same SOAP server on localhost - I need the same WSDL file and only difference is in url addresses which point to localhost. I copy & paste lines from one (localhost) file to other (production) file and this is good way to do mistake.
new function
When I want to add function to WSDL it takes me "long" time to understand again wsdl because it has more that 1000 lines.
I'm quite new to SOAP and also WSDL - I'm looking for good (and free) WSDL editor or tool to gererate WSDL file.
Try WSO2 WSF/PHP Library. It can generate WSDL right from your code.
If you're using Eclipse, you can take a look into the WSDL Editor.
You can also create a build script, that parses an existing WSDL (it's XML) and replace specific values (like the hostname) with another one to a target file.
Creating WSDL file from scratch can be very complicated and error prone. To ease this process, you can use an IDE to generate the WSDL file for your PHP functions and pass it as a parameter to your PHP SoapServer class. Check out this simple tutorial on How to generate wsdl for php native soap class
I'm using PHP xmlreader to validate and parse xml data. This xml is validated with some xsd schema from local file via XMLReader::setSchema function and remote xsd schema from http:// via xsd:import/include. Eveything work fine, but it fetch xsd schema from net and read from disk everytime when called.
So my questions is:
Is there a method for caching remote xsd schema in local RAM?
For local schema files, I think tmpfs in Linux will work fine, but is there another way to cache local xsd schema files ?
Solution
Thank VolkerK for pointing out the xmlcatalog system. It work fine with libxml/php xmlreader. In Linux, just edit file /etc/xml/catalog (It come from xml-common when you are in Fedora) add some entries like (for example):
<rewriteURI uriStartString="http://schemas.xmlsoap.org/soap/envelope/" rewritePrefix="/etc/xml/SOAP-Envolope.xsd"/>
<rewriteURI uriStartString="http://schemas.xmlsoap.org/soap/encoding/" rewritePrefix="/etc/xml/SOAP-Encoding.xsd"/>
and manual download schema (e.g http://schemas.xmlsoap.org/soap/encoding/ -> /etc/xml/SOAP-Encoding.xsd) then php xmlreader work like expected when parsing SOAP Messages.
php's xmlreader uses libxml and libxml supports xml catalouges:
What is a catalog? Basically it's a lookup mechanism [...]
It is basically used for 3 things:
[...]
providing a local cache mechanism allowing to load the entities associated to public identifiers or remote resources, this is a really important feature for any significant deployment of XML or SGML since it allows to avoid the aleas and delays associated to fetching remote resources.
Haven't tried it but I guess it's worth a test run.
How can I create a (empty) XML file trough a existing XSD schema?
Which PHP (5.3) functions are necessary?
I was also searching on how to "initialize" directly a DOM XML object that corresponds to an existing XSD in PHP. This allows for easily "feeding" this empty XML file with my own data.
Found only ONE method that does it, the SDO DAS XML extension of PHP
http://www.php.net/manual/en/sdo-das-xml.examples.php
see example #2. Unfortunately the extension is not by default in PHP 5.3, you have to add it through PECL, which does't work on my Windows PC, so I could not test it.
You would need to write a PHP parser that takes the XSD file and builds, tag by tag, an XML file.
Depending on the complexity of your XSD schema, this could either take a short/medium amount of time - or it could be entirely unfeasible, in terms of "you should probably just make an XML file by hand".