PHP XML validation
What's the best way to validate an XML file (or part of it) against multiple XSD files?
For example, I have the following schema for a config loader:
<xsd:schema xmlns="http://www.kauriproject.org/schema/configuration"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.kauriproject.org/schema/configuration"
elementFormDefault="qualified">
<xsd:element name="configuration" type="configuration" />
<xsd:complexType name="configuration">
<xsd:choice maxOccurs="unbounded">
<xsd:element name="import" type="import" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="section" type="section" />
</xsd:choice>
</xsd:complexType>
<xsd:complexType name="section">
<xsd:sequence>
<xsd:any minOccurs="0" maxOccurs="unbounded" processContents="lax" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
<xsd:attribute name="type" type="xsd:string" use="required" />
</xsd:complexType>
<xsd:complexType name="import" mixed="true">
<xsd:attribute name="resource" type="xsd:string" />
</xsd:complexType>
</xsd:schema>
Since the configuration class now exists, it allows you to add a tag <section>
defining a specific parser class (much like custom configuration sections in ASP.NET). However, I'm not sure how to check the section being analyzed.
If it is possible to check only this section of code with an XSD file / line without writing it back to the file?
+2
a source to share
2 answers
I was solving the same problem and I just simply concatenated the files (this was possible in my case as it was very simple).
Reference: Is it possible to validate XML against multiple schemas in PHP?
0
a source to share