php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #75335 Missing code example in DOMDocument::schemaValidate
Submitted: 2017-10-08 00:34 UTC Modified: 2017-10-28 15:45 UTC
From: peterkokot at gmail dot com Assigned:
Status: Open Package: DOM XML related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: peterkokot at gmail dot com
New email:
PHP Version: OS:

 

 [2017-10-08 00:34 UTC] peterkokot at gmail dot com
Description:
------------
Documentation at http://php.net/manual/en/domdocument.schemavalidate.php is missing a code example. I would suggest to add an example from the php-src repository:

----------shipping.xml----------
<?xml version="1.0"?>
<shipOrder>
  <shipTo>
    <name>Tove Svendson</name>
    <street>Ragnhildvei 2</street>
    <address>4000 Stavanger</address>
    <country>Norway</country>
  </shipTo>
  <items>
    <item>
      <title>Empire Burlesque</title>
      <quantity>1</quantity>
      <price>10.90</price>
    </item>
    <item>
      <title>Hide your heart</title>
      <quantity>1</quantity>
      <price>9.90</price>
    </item>
  </items>
</shipOrder>
----------shipping.xml----------


----------shipping.xsd----------
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 

    <xsd:element       name="shipOrder" type="order"/> 
    
    <xsd:complexType   name="order">
        <xsd:all>
            <xsd:element   name="shipTo"    type="shipAddress"/>
            <xsd:element   name="items"     type="cdItems"/>
        </xsd:all>
    </xsd:complexType> 
    
    <xsd:complexType   name="shipAddress">
        <xsd:all>
            <xsd:element   name="name"      type="xsd:string"/>
            <xsd:element   name="street"    type="xsd:string"/>
            <xsd:element   name="address"   type="xsd:string"/>
            <xsd:element   name="country"   type="xsd:string"/>
        </xsd:all>
    </xsd:complexType> 
    
    <xsd:complexType   name="cdItems">
        <xsd:sequence>
            <xsd:element   name="item"      type="cdItem"  maxOccurs="unbounded" minOccurs="1"/>
        </xsd:sequence>
    </xsd:complexType> 
    
    <xsd:complexType   name="cdItem">
        <xsd:all>
            <xsd:element   name="title"     type="xsd:string"/>
            <xsd:element   name="quantity"  type="xsd:positiveInteger"/>
            <xsd:element   name="price"     type="xsd:decimal"/>
        </xsd:all>
    </xsd:complexType> 

</xsd:schema>
----------shipping.xsd----------


----------shipping.php----------
<?php

$dom = new domDocument;
$dom->load('shipping.xml');
if (!$dom->schemaValidate('shipping.xsd')) {
  print "Document is not valid";
} else {
  print "Document is valid";
}
----------shipping.php----------


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-10-28 15:45 UTC] cmb@php.net
-Package: Documentation problem +Package: DOM XML related
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 04:01:31 2024 UTC