PHP XML Validation
Posted
by efritz
on Stack Overflow
See other posts from Stack Overflow
or by efritz
Published on 2010-04-14T03:16:56Z
Indexed on
2010/04/14
3:23 UTC
Read the original article
Hit count: 543
What's the best way to validate an XML file (or a portion of it) against multiple XSD files?
For example, I have the following schema for a configuration 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>
As the Configuration class exists now, it lets one add a <section>
tag with a define concrete parser class (much like custom configuration sections in ASP.NET). However, I'm unsure of how to validate the section being parsed.
If it possible to validate just this section of code with an XSD file/string without writing it back to a file?
© Stack Overflow or respective owner