Whatever message this page gives is out now! Go check it out!
| Field | Description |
Errors | An array containing any validator error messages. These messages indicate that the document does not conform to the DTD or Schema (is not valid). |
FatalErrors | An array containing any validator fatal error messages. Fatal errors indicate that the document contains XML formatting errors (is not well-formed XML). |
Status | A Boolean value:
|
Warning | An array containing any validator warnings. A well-formed and valid document can produce warning messages. |
XmlValidate(xml, [validator])| Parameter | Description |
xml | Any of the following:
|
validator | Any of the following:
|
| allowExternalEntities | (True or False) To enable or disable external entities for the current invocation, specify a valid boolean value. If a valid boolean value is provided, external entities will be enabled or disabled accordingly. If no value is specified or if the value is invalid, the system property value (coldfusion.xml.allowExternalEntities) will be used. |
| parserOptions | A struct that controls XML parser behavior for the current invocation. Supported keys include:
|
XmlValidate() blocks XML input that contains a <!DOCTYPE ...> declaration unless you explicitly set parserOptions.ALLOWDOCTYPEDECLARATION = true.This is a breaking change for applications that validate XML documents that embed or depend on a DOCTYPE declaration. If your XML is trusted and intentionally uses a DOCTYPE, enable ALLOWDOCTYPEDECLARATION for that invocation only.If you omit the validator parameter, the XML document can still identify a DTD or schema in the document itself. However, if the XML contains a DOCTYPE declaration, it is rejected unless ALLOWDOCTYPEDECLARATION=true.Enable this option only for trusted XML. Do not enable it for XML received from untrusted users, browsers, or third-party systems that you do not control.<!--- Trusted XML that legitimately contains a DOCTYPE declaration --->
<cfset opts = {
ALLOWDOCTYPEDECLARATION = true,
ALLOWEXTERNALENTITIES = false,
ENTITYEXPANSIONLIMIT = 1000
}>
<cfset result = XmlValidate(myXmlString, "schema.xsd", opts)><?xml version="1.0" encoding="UTF-8"?>
<order xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://localhost:8500/something.xsd" id="4323251" >
<customer firstname="Philip" lastname="Cramer" accountNum="21"/>
<items>
<item id="43">
<name> Deluxe Carpenter's Hammer</name>
<quantity>1</quantity>
<unitprice>15.95</unitprice>
</item>
<item id="54">
<name> 36" Plastic Rake</name>
<quantity>2</quantity>
<unitprice>6.95</unitprice>
</item>
<item id="68">
<name> Standard paint thinner</name>
<quantity>3</quantity>
<unitprice>8.95</unitprice>
</item>
</items>
</order><?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="customer">
<xs:complexType>
<xs:attribute name="firstname" type="xs:string" use="required"/>
<xs:attribute name="lastname" type="xs:string" use="required"/>
<xs:attribute name="accountNum" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="name" type="xs:string"/>
<xs:element name="quantity" type="xs:string"/>
<xs:element name="unitprice" type="xs:string"/>
<xs:element name="item">
<xs:complexType>
<xs:sequence>
<xs:element ref="name"/>
<xs:element ref="quantity"/>
<xs:element ref="unitprice"/>
</xs:sequence>
<xs:attribute name="id" type="xs:integer" use="required">
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="items">
<xs:complexType>
<xs:sequence>
<xs:element ref="item" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="order">
<xs:complexType>
<xs:sequence>
<xs:element ref="customer"/>
<xs:element ref="items"/>
</xs:sequence>
<xs:attribute name="id" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema><cfset
myResults=XMLValidate("C:\CFusionMX7\wwwroot\examples\custorder.xml",
"http://localhost:8500/examples/custorder.xsd")>
<cfoutput>
Did custorder.xml validate against custorder.xsd? #myResults.status#<br><br>
</cfoutput>
Dump of myResults structure returned by XMLValidate<br>
<cfdump var="#myResults#">