2010-04-14 62 views
2

針對多個XSD文件驗證XML文件(或其一部分)的最佳方式是什麼?PHP XML驗證

例如,我有一個配置加載下面的模式:

<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> 

由於配置類現在存在的,它讓一個加<section>標籤與定義具體的語法分析類(很像定製ASP.NET中的配置部分)。但是,我不確定如何驗證正在分析的部分。

如果可以使用XSD文件/字符串驗證這段代碼而不寫回文件?

+0

你解決這個問題? – 2010-05-07 07:41:53

回答

0

不要將它看作一個大的XML文件,而應該將它看作塊。自定義XML部分不是您的主文件架構的一部分,它只是其數據。嘗試使用此XSD文件進行驗證,然後在加載自定義節時使用另一個XSD文件驗證XML。