<html>
<head>
<link href="mmres://user_interface_reference.css" rel="stylesheet" type="text/css">
<title>XMLVALIDATE</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
   <div id="Description">
   <table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
      <tr> 
         <td valign="top" class="name">XMLVALIDATE</td>
         <td valign="top" nowrap class="compatibility">&nbsp;</td>
      </tr>
      <tr>
         <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
      </tr>


    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Description</span>
<p>
Uses a Document Type Definition (DTD) or XML Schema to validate an XML text document or an XML document object. 
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Returns</span>
<p>
The following validation structure:
</p>

<p>

</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Category</span>
<p>
XML functions
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Function syntax</span><pre>XmlValidate(xmlDoc[, validator])
</pre>    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">See also</span>
<p>
cfxml, IsXmlDoc, IsXML, XmlFormat, XmlNew, XmlParse, XmlSearch, XmlTransform; Chapter&#160;35, "Using XML and WDDX" in ColdFusion MX Developer's Guide
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">History</span>
<p>
ColdFusion&#160;MX&#160;7: Added this function.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Parameters</span>
<p>

</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Usage</span>
<p>
If you specify a relative URL or filename in a parameter, ColdFusion uses the directory (or, for URLs, the virtual directory) that contains the current ColdFusion page as the path root. 
</p>

<p>
The validator parameter specifies a DTD or Schema to use to validate the document. If you omit the parameter, the XML document must contain one of the following:
</p>
<ul>

<li>A !DOCTYPE tag to specify the DTD or its location</li>

<li>An xsi:schemaLocation or xsi:noNamespaceSchemaLocation tag to specify the Schema location </li>
</ul>

<p>
If you use a validator parameter and the XML document specifies a DTD or Schema, the XmlValidate function uses the validator parameter, and ignores the specification in the XML document.
</p>

<p>
If you do not use a validator parameter, and the XML document does not specify a DTD or Schema, the function returns a structure with an error message in the Errors field.
</p>

<p>
This function attempts to process the complete XML document, and reports all errors found during the processing. As a result, the returned structure can have a combination of Warning, Error, and FatalError fields, and each field can contain multiple error messages.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Example</span>
<p>
The following example has three parts: an XML file, an XSD Schema file, and a CFML page that parses the XML file and uses the Schema for validation. The CFML file displays the value of the returned structure's Status field and displays the returned structure. To show the results of invalid XML, modify the custorder.xml file.
</p>
<table>
  <tr valign="top">
    <td width="30"><strong>Note: </strong></td>
    <td>The Schema used in the following example represents the same XML structure as the DTD used in the XmlParse example.</td>
  </tr>
</table>
<p>
The custorder.xml file is as follows: 
</p>
<pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;order xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; 
xsi:noNamespaceSchemaLocation=&quot;http://localhost:8500/something.xsd&quot; 
id=&quot;4323251&quot; &gt;
   &lt;customer firstname=&quot;Philip&quot; lastname=&quot;Cramer&quot; accountNum=&quot;21&quot;/&gt;
   &lt;items&gt;
      &lt;item id=&quot;43&quot;&gt;
         &lt;name&gt;   Deluxe Carpenter&amp;apos;s Hammer&lt;/name&gt;
         &lt;quantity&gt;1&lt;/quantity&gt;
         &lt;unitprice&gt;15.95&lt;/unitprice&gt;
      &lt;/item&gt;
      &lt;item id=&quot;54&quot;&gt;
         &lt;name&gt;   36&amp;quot; Plastic Rake&lt;/name&gt;
         &lt;quantity&gt;2&lt;/quantity&gt;
         &lt;unitprice&gt;6.95&lt;/unitprice&gt;
      &lt;/item&gt;
      &lt;item id=&quot;68&quot;&gt;
         &lt;name&gt;   Standard paint thinner&lt;/name&gt;
         &lt;quantity&gt;3&lt;/quantity&gt;
         &lt;unitprice&gt;8.95&lt;/unitprice&gt;
      &lt;/item&gt;
   &lt;/items&gt;
&lt;/order&gt;
</pre>
<p>
The custorder.xsd file is as follows:
</p>
<pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;xs:schema xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;
elementFormDefault=&quot;qualified&quot;&gt;
   &lt;xs:element name=&quot;customer&quot;&gt;
      &lt;xs:complexType&gt;
         &lt;xs:attribute name=&quot;firstname&quot; type=&quot;xs:string&quot; use=&quot;required&quot;/&gt;
         &lt;xs:attribute name=&quot;lastname&quot; type=&quot;xs:string&quot; use=&quot;required&quot;/&gt;
         &lt;xs:attribute name=&quot;accountNum&quot; type=&quot;xs:string&quot; use=&quot;required&quot;/&gt;
      &lt;/xs:complexType&gt;
   &lt;/xs:element&gt;
   &lt;xs:element name=&quot;name&quot; type=&quot;xs:string&quot;/&gt;
   &lt;xs:element name=&quot;quantity&quot; type=&quot;xs:string&quot;/&gt;
   &lt;xs:element name=&quot;unitprice&quot; type=&quot;xs:string&quot;/&gt;
   &lt;xs:element name=&quot;item&quot;&gt;
      &lt;xs:complexType&gt;
         &lt;xs:sequence&gt;
            &lt;xs:element ref=&quot;name&quot;/&gt;
            &lt;xs:element ref=&quot;quantity&quot;/&gt;
            &lt;xs:element ref=&quot;unitprice&quot;/&gt;
         &lt;/xs:sequence&gt;
         &lt;xs:attribute name=&quot;id&quot; type=&quot;xs:integer&quot; use=&quot;required&quot;&gt;
         &lt;/xs:attribute&gt;
      &lt;/xs:complexType&gt;
   &lt;/xs:element&gt;
   &lt;xs:element name=&quot;items&quot;&gt;
      &lt;xs:complexType&gt;
         &lt;xs:sequence&gt;
            &lt;xs:element ref=&quot;item&quot; maxOccurs=&quot;unbounded&quot;/&gt;
         &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
   &lt;/xs:element&gt;
   &lt;xs:element name=&quot;order&quot;&gt;
      &lt;xs:complexType&gt;
         &lt;xs:sequence&gt;
            &lt;xs:element ref=&quot;customer&quot;/&gt;
            &lt;xs:element ref=&quot;items&quot;/&gt;
         &lt;/xs:sequence&gt;
         &lt;xs:attribute name=&quot;id&quot; type=&quot;xs:string&quot; use=&quot;required&quot;/&gt;
      &lt;/xs:complexType&gt;
   &lt;/xs:element&gt;
&lt;/xs:schema&gt;
</pre>
<p>
The CFML file is as follows. It uses a filename for the XML file and a URL for the Schema.  The XML and URL paths must be absolute.
</p>
<pre>&lt;cfset
myResults=XMLValidate(&quot;C:\CFusionMX7\wwwroot\examples\custorder.xml&quot;, 
&quot;http://localhost:8500/examples/custorder.xsd&quot;)&gt;
&lt;cfoutput&gt;
Did custorder.xml validate against custorder.xsd? #results.status#&lt;br&gt;&lt;br&gt;
&lt;/cfoutput&gt;
Dump of myResults structure returned by XMLValidate&lt;br&gt;
&lt;cfdump var=&quot;#myResults#&quot;&gt;
</pre>
         </td>
      </tr>
   </table>
   </div>
<div id="ERRORS">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">ERRORS</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>


<p>An array containing any validator error messages. These messages indicate that the document does not conform to the DTD or Schema (is not valid).</p>

  </td>
  </tr>
  </table>
</div>
<div id="FATALERRORS">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">FATALERRORS</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>


<p>An array containing any validator fatal error messages. Fatal errors indicate that the document contains XML formatting errors (is not well-formed XML).</p>

  </td>
  </tr>
  </table>
</div>
<div id="STATUS">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">STATUS</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>


<p>A Boolean value:</p><ul>

<li>True if the document is valid.</li>

<li>False if the validation check failed.</li>
</ul>


  </td>
  </tr>
  </table>
</div>
<div id="WARNING">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">WARNING</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>


<p>An array containing any validator warnings. A well-formed and valid document can produce warning messages.</p>

  </td>
  </tr>
  </table>
</div>
<div id="XMLDOC">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">XMLDOC</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>


<p>Any of the following:</p><ul>

<li>A string containing an XML document.</li>

<li>The name of an XML file.</li>

<li>The URL of an XML file; valid protocol identifiers include http, https, ftp, and file.</li>

<li>An XML document object, such as one generated by the XmlParse function.</li>
</ul>


  </td>
  </tr>
  </table>
</div>
<div id="VALIDATOR">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">VALIDATOR</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>


<p>Any of the following:</p><ul>

<li>A string containing a DTD or Schema.</li>

<li>The name of a DTD or Schema file.</li>

<li>The URL of a DTD or Schema file; valid protocol identifiers include http, https, ftp, and file.</li>
</ul>


  </td>
  </tr>
  </table>
</div>

  </body>
</html>
