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".
Related
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
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 have a tmx file with multiple languages defined for each term, and I can't find any way to convert it into individual anything -- gettext, php arrays, anything. My translation service does not let me download it in other formats (other than one per line plaintext without any keys, but that's a whole other problem).
I've only seen a po2tmx utility, not the other way around. Zend Framework 2's Zend\I18n documentation says it supports Tmx and Xliff, but it seems to.. not. I have no idea why, but
Is there any way at all I can convert this into some kind of usable format or do I have to end up writing some kind of weird thing that uses SimpleXML?
This converter can import TMX files containing up to two languages, and has various download options including PHP and PO files.
The API will also convert a TMX file to PHP Zend format as follows (using command line cURL):
$ curl --data-binary #file.tmx 'http://localise.biz/api/convert/tmx/file.phps'
I'm currently developing a Web application with Zend Framework and PHP 5.3. I have a XML file that contain configs and mapping information (+- 1500 lines). On each request I perform an xpath query to get information from that XML file. The information that is found in the XML file is static and do not change after the deployment of the application.
It is a good practice to generated a php file that contain the XML information in a static arrays on the first request and then load that php file on every request to get the information instead of doing queries on the XML?
You can cache the parsed config file as source file with var_export.
Generating code to cache resources is implemented in several places in Zend Framework, for example autoloader, so I presume it is good practice.
There is also another way to cache it - with serialize (make sure to serialize an array, not for example a SimpleXML object) or Zend_Cache which does more or less the same but is more flexible as to how the result is stored.
Since the XML not changes after deploy, i think it would be the best to transform that XML in your local dev env, and not on the productive system when needed. Its not a good idea to generate source on the productive system that will be automatically included without any validation.
I'm not very familiar with XSLT, but it might be an option for you, according to the concrete structure of that XML.
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.