I have a .xsd schema that defines both simple and complex types - a sample is below. I need to be able to load this .xsd file, add more elements to it and return it as a string (which will eventually be sent via an api to a 3rd party service). The website is built on Drupal, so the code needs to be in PHP.
Below is a sample of the schema (.xsd)
Are there any tools or libraries that will make easier? I see lots of xml utilities in php like SimpleXML, but in the examples I looked at they already have the .xsd file and are parsing and creating objects and setting values in an xml document based on a given schema. I want to programatically change and update a schema .xsd file via php?Any tips? or libraries or appraoches would be greatly appreciated. I'm about to start wrtiing the code in a less than ideal way (but it will work), which just rebuilds the entire .xsd each time and has multiple loops using strings to add new elements, but that's not the best solution. I'm hoping there is a tool that may work something like this:
$newschemaObject = MakeDynmaicObject(oldschema.xsd);
$newschema->add(simple, text, "New Text Field", required);
$stringtosend = $newschema->buildXSD();
Sample of schema.xsd
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="DrupalEntityId" minOccurs="0" maxOccurs="1" type="textType">
<xsd:annotation>
<xsd:documentation/>
<xsd:appinfo>
<label>Drupal Entity ID</label>
<key>Drupal Entity ID</key>
<searchable>true</searchable>
<timeControl>false</timeControl>
<description/>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element id="md_631560E7-14AD-5327-732B-8268813A0553" name="SampleMultiValueTextField" minOccurs="0" maxOccurs="unbounded" type="textType">
<xsd:annotation>
<xsd:documentation/>
<xsd:appinfo>
<label>Sample Multi Value Text Field</label>
<key>Sample Multi Value Text Field</key>
<searchable>true</searchable>
<timeControl>false</timeControl>
<description>This is a sample multivalue text field</description>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
...
</xsd:schema>
The current version of my code uses a lot of strings like this:
$xsd .= '<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">';
$xsd .= ' <xsd:element name="metadata">';
to generate the above schema, but it's not flexible or very programmatic. any advice on being able to update the.xsd and set new elements in a object oriented way would be amazing!!!!