This site has been taken over by the staff of www.ASPDeveloper.Net

Please report errors to suggest@aspdeveloper.net

BizTalk Utilities CV ,   Jobs ,   Code library  
 
Home Page
PHP XML
PHP DOMDocument Function saveXML
PHP DOMDocument Function saveHTMLFile
PHP DOMDocument Function saveHTML
PHP DOMDocument Function normalize
PHP DOMDocument Function loadXML
PHP DOMDocument Function loadHTMLFile
PHP DOMDocument Function loadHTML
PHP DOMDocument Function importNode
PHP DOMElement Function hasAttribute
PHP DOMDocument Function getElementsByTagName
PHP DOMDocument Function getAttributeNS
PHP DOMDocument Function getAttributeNodeNS
PHP DOMDocument Function getAttribute
PHP DOMDocument Function createTextNode
PHP DOMDocument Function createProcessingInstruction
PHP DOMDocument Function createEntityReference
PHP DOMDocument Function createElementNS
PHP DOMDocument Function createElement
PHP DOMDocument Function createDocumentFragment
PHP DOMDocument Function createComment
 
 

By :Mark Wilson
I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :03/24/2008
Times viewed :1869

 

DOMDocument Function schemaValidate

PHP Version: (No version information might be only in CVS. I have used this function in PHP5)

DOM: W3C DOM Level 1

Description

This function is used to validate a document based on a schema. In this example, I have loaded DOM Document from a valid XML file and validated it using against the schema using schemaValidate() function.

Usage:

boolDOMDocument->schemaValidate ( string filename)

Validates a document based on a schema defined by filename.

Content of XML file:

This is a valid xml against schema( Please see below the content of schema).

     <?xml version="1.0" encoding="UTF-8"?>

<employee>

     <employeename id="myId">test</employeename>

     <employeeaddress>test123</employeeaddress>

     <SSN>12343456</SSN>

     <company>XYZ Corporation</company>

</employee>

Content of Schema file:

    <?xml version="1.0" encoding="UTF-8"?>

<xs:schemaxmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

     <xs:element name="SSN" type="xs:int"/>

     <xs:element name="company" type="xs:string"/>

     <xs:element name="employee">

<xs:complexType>

               <xs:sequence>

                    <xs:element ref="employeename"/>

                    <xs:element ref="employeeaddress"/>

                    <xs:element ref="SSN"/>

                    <xs:element ref="company"/>

               </xs:sequence>

</xs:complexType>

     </xs:element>

     <xs:element name="employeeaddress" type="xs:string"/>

     <xs:element name="employeename">

<xs:complexType>

               <xs:simpleContent>

                    <xs:extension base="xs:string">

                         <xs:attribute name="id" type="xs:string" use="required"/>

                    </xs:extension>

               </xs:simpleContent>

</xs:complexType>

     </xs:element>

     </xs:schema>

PHP Code:

In this example, I have populated the DOM Document from a XML file.

<?php

$doc = new DomDocument;

//declare file variable

$file = 'C:/topxml_demo/php/xml_files/employee.xml';

//declare schema

$schema  = 'C:/topxml_demo/php/xml_files/employee.xsd';

// Load the xml file into DOMDocument

$doc->Load($file);

//validate the DOMDocument

if ($doc->schemaValidate($schema)) {

    print "$file is valid.\n";

 } else {

     print "$file is invalid.\n";

 }

?>

Output:


Rate this article on a scale of 1 to 10

Your vote :  


 

Recent Jobs

Software Specialist, Linux - Finlan
Linux Core Technical Project Manage
Graphics designer at Tanzania. Expe
Integration Specialist Needed - Wor
Virtualization Server Infrastructur

View all Jobs (Add yours)
View all CV (Add yours)






    Email TopXML  

Front Page Daily Stuff TopXML Forum XML blogs XML Newsgroups BizTalk Biztalk Utilities Biztalk Utilities Tutorial B2B SAP XML Microsoft .NET Dotnet System XML Soapformatter SQLXML XMLserializer XQuery PHP PHP SimpleXML PHP XML Dom PHP XML RPC PHP XSLT Java Java Java XML Xalan Microsoft ASP ASP Schemas XML SQL Server XML XMLDom XSL XSL Tutorial XSLT Stylesheets General Javascript CSS XHTML WAP