Skip to content

Instantly share code, notes, and snippets.

@cmb69
Created September 10, 2016 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmb69/a98d1b784ff536393bd8e9cead5fd0e2 to your computer and use it in GitHub Desktop.
Save cmb69/a98d1b784ff536393bd8e9cead5fd0e2 to your computer and use it in GitHub Desktop.
<?xml version="1.0"?>
<x:books xmlns:x="urn:books">
<book id="1">
<author>Writer</author>
<title>The First Book</title>
<genre>Fiction</genre>
<price>44.95</price>
<pub_date>2000-10-01</pub_date>
<review>An amazing story of nothing.</review>
</book>
</x:books>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:books"
xmlns:bks="urn:books">
<xsd:element name="books" type="bks:BooksForm"/>
<xsd:complexType name="BooksForm">
<xsd:sequence>
<xsd:element name="book"
type="bks:BookForm"
minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="BookForm">
<xsd:sequence>
<xsd:element name="author" type="xsd:string"/>
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="genre" type="xsd:string"/>
<xsd:element name="price" type="xsd:float" />
<xsd:element name="pub_date" type="xsd:date" />
<xsd:element name="review" type="xsd:string"/>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:positiveInteger"/>
</xsd:complexType>
</xsd:schema>
<?php
$xmlfile = __DIR__ . DIRECTORY_SEPARATOR . 'books.xml';
$xsdfile = __DIR__ . DIRECTORY_SEPARATOR . 'books.xsd';
$xml = new XMLReader();
if(!$xml->open($xmlfile, null, LIBXML_PARSEHUGE)){
logging('Unable to Open XML file (Full Parse 1):' . $xmlfile);
return false;
}
$xml->setSchema($xsdfile);
while($xml->read()){
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment