Copy link to clipboard
Copied
This is something I have never tried before. We created an XML Schema to define XML documents we expect to receive from various entities. When we receive the document, we would like to validate it before processing it. I think ColdFusion is up to this from reading the documentation, but we have not got anything working yet.
When we try and xmlParse() our test XML file against the XML schema we get the following error. When we use a web based XML validation tool and feed it the same XML file and schema it validates just fine.
An error occured while parsing an XML document.
[Error] :2:6: cvc-elt.1: Cannot find the declaration of element 'pur'.
The error occurred in D:\playground\warren\ppur_file_import.cfm: line 57
55 :
56 :
57 : <cfset xmldoc = XmlParse(ExpandPath(filepath), true, ExpandPath(validator)) />
58 : <cfdump var="#xmldoc#">
59 : <cfabort>
Searching for the error has not provided me any useful hints. Can anybody here?
I was able to get the sample document to parse by adding namespaces to the sample file. I'm not an XML expert so I can't provide a clear explanation for this. I used Altova XML Spy to create an XML sample document based on your schema and it added the xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation sections to the XML file. Note that the value of noNamespaceSchemaLocation would normally be the path to the XSD file. I have left the value blank and the sampl
...Copy link to clipboard
Copied
Can you post the XML file and XML schema?
Copy link to clipboard
Copied
I can, but they are a bit large.
Copy link to clipboard
Copied
Can you post smaller files that reproduce the same error?
Copy link to clipboard
Copied
Probably not today. We developed the XML and XML Schema outside of this being a ColdFusion applicaiton. I'm not the developer, but looking at the files he created, I am not sure they are easily reducable.
Tomorrow, I could probably create a simple xml schema and just see what happens.
Copy link to clipboard
Copied
Smaller sample file, producing the same error.
XML Schema
<?xml version="1.0" encoding="iso-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="pur">
<xs:complexType>
<xs:sequence>
<xs:element name="File" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="Data" type="xs:string" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
XML Test FIle
<?xml version="1.0" encoding="iso-8859-1"?>
<pur>
<File>foo</File>
<Data>bar</Data>
</pur>
These files, and the large files I provided previously will validate correctly according to this tool.
Copy link to clipboard
Copied
I was able to get the sample document to parse by adding namespaces to the sample file. I'm not an XML expert so I can't provide a clear explanation for this. I used Altova XML Spy to create an XML sample document based on your schema and it added the xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation sections to the XML file. Note that the value of noNamespaceSchemaLocation would normally be the path to the XSD file. I have left the value blank and the sample still parses in ColdFusion 8.
I suspect the underlying issue is related to how CF's Java based XML parser expects namespaces to be handled in XML documents, but that is just a theory.
<cfsavecontent variable="sample"><?xml version="1.0" encoding="iso-8859-1"?><pur xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="">
<File>foo</File>
<Data>bar</Data>
</pur>
</cfsavecontent>
<cfsavecontent variable="theSchema"><?xml version="1.0" encoding="iso-8859-1"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="pur">
<xs:complexType>
<xs:sequence>
<xs:element name="File" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="Data" type="xs:string" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</cfsavecontent>
<cfset xmldoc1=XmlParse(sample, true, theSchema) />
<cfdump var="#xmldoc1#" />
Copy link to clipboard
Copied
JR "Bob" Dobbs wrote:
Note that the value of noNamespaceSchemaLocation would normally be the path to the XSD file.
Do you, or anybody, know right off the top of the head if that is an URL path or an File path?
TIA
Copy link to clipboard
Copied
Using Altova XML Spy the value was a path on my file system like "C:\dir\folder\item.xsd". I suspect that a valid URL would also work here as well.
Copy link to clipboard
Copied
Yup, I tested both and the both worked. I'm glad, because the URL path makes much more sense for us. The XML files are going to be generated by up to 52 different entities around the state on differet systems. They are not going to share the same file paths. But they can easily use the URL to the published schema on our server.
Thanks for all the help. I got it working just fine this morning.
Copy link to clipboard
Copied
XML SCHEMA
<?xml version="1.0" encoding="iso-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- Simple Types -->
<xs:simpleType name="RECORD_ID">
<xs:restriction base="xs:string">
<xs:pattern value="[AaBbCc]"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="REPORT_MONTH">
<xs:restriction base="xs:integer">
<xs:pattern value="(0[1-9]|1[0-2])"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="REPORT_YEAR">
<xs:restriction base="xs:integer">
<xs:pattern value="[0-9]{2}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="MFG_FIRMNO">
<xs:restriction base="xs:integer">
<xs:pattern value="[0-9]{7}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="LABEL_SEQ_NO">
<xs:restriction base="xs:integer">
<xs:pattern value="[0-9]{5}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="REVISION_NO">
<xs:restriction base="xs:string">
<xs:pattern value="[A-Za-z]{2}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="REG_FIRMNO">
<xs:restriction base="xs:integer">
<xs:pattern value="[0-9]{7}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="GROWER_ID">
<xs:restriction base="xs:integer">
<xs:pattern value="[0-9]{11}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="CEDTS_IND">
<xs:restriction base="xs:string">
<xs:pattern value="[Ee]|[ ]"/>
<!-- needs to match E or a blank. -->
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="APPLIC_DT">
<xs:restriction base="xs:integer">
<xs:pattern value="(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])([0-9]{2})"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="SITE_CODE">
<xs:restriction base="xs:integer">
<xs:pattern value="[0-9]{6}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="QUALIFY_CD">
<xs:restriction base="xs:integer">
<xs:pattern value="[0-9]{2}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="PLANTING_SEQ">
<xs:restriction base="xs:integer">
<xs:pattern value="[0-9]"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="ACRE_TREATED">
<xs:restriction base="xs:integer">
<xs:pattern value="[0-9]{8}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="UNIT_TREATED">
<xs:restriction base="xs:string">
<xs:pattern value="[ATSCKUPatsckup]"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="AMT_PRD_USED">
<xs:restriction base="xs:integer">
<xs:pattern value="[0-9]{10}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="UNIT_OF_MEAS">
<xs:restriction base="xs:string">
<xs:pattern value="LB|OZ|GA|QT|PT|KG|GR|LI|ML"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="DOCUMENT_NO">
<xs:restriction base="xs:integer">
<xs:pattern value="[0-9]{8}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="LINE_ITEM">
<xs:restriction base="xs:integer">
<xs:pattern value="[0-9]{4}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="PROCESS_DT">
<xs:restriction base="xs:integer">
<xs:pattern value="[0-9]{4}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="BATCH_NO">
<xs:restriction base="xs:integer">
<xs:pattern value="[0-5][0-9][0-9][0-9]"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="COUNTY_CD">
<xs:restriction base="xs:integer">
<xs:pattern value="[0-5][0-9]"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="SECTION">
<xs:restriction base="xs:integer">
<xs:pattern value="[0-9]{2}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="TOWNSHIP">
<xs:restriction base="xs:integer">
<xs:pattern value="[0-9]{2}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="TSHIP_DIR">
<xs:restriction base="xs:string">
<xs:pattern value="[NSns]"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="RANGE">
<xs:restriction base="xs:integer">
<xs:pattern value="[0-9]{2}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="RANGE_DIR">
<xs:restriction base="xs:string">
<xs:pattern value="[EWew]"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="BASE_LN_MER">
<xs:restriction base="xs:string">
<xs:pattern value="[HMShms]"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="AER_GND_IND">
<xs:restriction base="xs:string">
<xs:pattern value="[AFGOafgo]"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="SITE_LOC_ID">
<xs:restriction base="xs:string">
<xs:pattern value="[-0-9 ]+"/>
<!-- Examples in files I checked
only had numeric characters and
a dash. The county contract doesn't
specify numeric-only, so letters may
be acceptable. I find no evidence of
any letters being used. -->
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="ACRE_PLANTED">
<xs:restriction base="xs:integer">
<xs:pattern value="[0-9]{8}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="UNIT_PLANTED">
<xs:restriction base="xs:string">
<xs:pattern value="[ATSCKUPatsckup]"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="APPLIC_TM">
<xs:restriction base="xs:integer">
<xs:pattern value="[0-9]{4}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="APPLIC_CNT">
<xs:restriction base="xs:integer">
<xs:pattern value="[0-9]{6}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="FUME_CD">
<xs:restriction base="xs:integer">
<xs:pattern value="[0-9]{4}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="LICENSE_NO">
<xs:restriction base="xs:integer">
<xs:pattern value="[-0-9A-Za-z]{13}"/>
</xs:restriction>
</xs:simpleType>
<!-- end Simple Types -->
<!-- !!!!!!!!! Begin Abstract Types !!!!!!!!! -->
<xs:complexType name="application_data_abs" abstract="true">
<xs:sequence>
<xs:element name="GROWER_ID" type="GROWER_ID" />
<xs:element name="CEDTS_IND" type="CEDTS_IND" />
<xs:element name="APPLIC_DT" type="APPLIC_DT" />
<xs:element name="SITE_CODE" type="SITE_CODE" />
<xs:element name="QUALIFY_CD" type="QUALIFY_CD" />
<xs:element name="PLANTING_SEQ" type="PLANTING_SEQ" />
<xs:element name="ACRE_TREATED" type="ACRE_TREATED" />
<xs:element name="UNIT_TREATED" type="UNIT_TREATED" />
<xs:element name="AMT_PRD_USED" type="AMT_PRD_USED" />
<xs:element name="UNIT_OF_MEAS" type="UNIT_OF_MEAS" />
<xs:element name="DOCUMENT_NO" type="DOCUMENT_NO" />
<xs:element name="LINE_ITEM" type="LINE_ITEM" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="application_abs" abstract="true">
<xs:sequence>
<xs:element name="key_data" type="key_data" />
<xs:element name="product_data" type="product_data" />
</xs:sequence>
</xs:complexType>
<!-- !!!!!!!!! End Abstract Types !!!!!!!!! -->
<!-- !!!!!!!!! Start Complex Types !!!!!!!!! -->
<xs:complexType name="product_data">
<xs:sequence>
<xs:element name="MFG_FIRMNO" type="MFG_FIRMNO" />
<xs:element name="LABEL_SEQ_NO" type="LABEL_SEQ_NO"/>
<xs:element name="REVISION_NO" type="REVISION_NO" />
<xs:element name="REG_FIRMNO" type="REG_FIRMNO" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="key_data">
<xs:sequence>
<xs:element name="RECORD_ID" type="RECORD_ID" />
<xs:element name="COUNTY_KEY">
<!--
The optional COUNTY_ID field would be used by
the Counties to include their internal
record identifier. This would allow DPR
to reference a county's internal record ID
in the event of data inconsistencies.
-->
</xs:element>
<xs:element name="REPORT_MONTH" type="REPORT_MONTH" />
<xs:element name="REPORT_YEAR" type="REPORT_YEAR" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="fileInfo">
<xs:sequence>
<xs:element name="PROCESS_DT" type="PROCESS_DT" />
<xs:element name="BATCH_NO" type="BATCH_NO" />
<xs:element name="COUNTY_CD" type="COUNTY_CD" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="mtrs_data">
<xs:sequence>
<xs:element name="SECTION" type="SECTION" />
<xs:element name="TOWNSHIP" type="TOWNSHIP" />
<xs:element name="TSHIP_DIR" type="TSHIP_DIR" />
<xs:element name="RANGE" type="RANGE" />
<xs:element name="RANGE_DIR" type="RANGE_DIR" />
<xs:element name="BASE_LN_MER" type="BASE_LN_MER" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ag_application_data">
<xs:complexContent>
<xs:extension base="application_data_abs">
<xs:sequence>
<xs:element name="AER_GND_IND" type="AER_GND_IND" />
<xs:element name="SITE_LOC_ID" type="SITE_LOC_ID" />
<xs:element name="ACRE_PLANTED" type="ACRE_PLANTED" />
<xs:element name="UNIT_PLANTED" type="UNIT_PLANTED" />
<xs:element name="APPLIC_TM" type="APPLIC_TM" />
<xs:element name="FUME_CD" type="FUME_CD" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="nonag_application_data">
<xs:complexContent>
<xs:extension base="application_data_abs">
<xs:sequence>
<xs:element name="APPLIC_CNT" type="APPLIC_CNT" />
<xs:element name="LICENSE_NO" type="LICENSE_NO" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<!--- "Ag" -->
<!--
Type A:
Data that would appear on individual lines
in the old A type
(F file type, agricultural job report)
Type B:
Data that would appear on individual lines
in the old B type
(F file type, agricultural monthly production summary)
-->
<xs:complexType name="ag_application">
<xs:complexContent>
<xs:extension base="application_abs">
<xs:sequence>
<xs:element name="mtrs_data" type="mtrs_data" />
<xs:element name="application_data" type="ag_application_data" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<!--- "Non_Ag" -->
<!--
Data that would appear on individual lines
in the old C type
(C file type, non-agricultural monthly summary)
-->
<xs:complexType name="nonag_application">
<xs:complexContent>
<xs:extension base="application_abs">
<xs:sequence>
<xs:element name="application_data" type="nonag_application_data" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<!-- The individual lines of data that are transmitted. -->
<xs:complexType name="data_lines">
<xs:sequence>
<xs:element name="Non_Ag" type="nonag_application" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="Ag" type="ag_application" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<!-- !!!!!!!!! End Complex Types !!!!!!!!! -->
<xs:element name="pur">
<xs:complexType>
<xs:sequence>
<xs:element name="County" minOccurs="0" maxOccurs="1">
<!--
Tag for counties to put county-specific
data in (eg, their batch number, timestamp,
contact info, etc)
-->
</xs:element>
<!-- File: information specific to the file -->
<xs:element name="File" type="fileInfo" minOccurs="1" maxOccurs="1"/>
<!-- Data: lines of data transmitted -->
<xs:element name="Data" type="data_lines" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Copy link to clipboard
Copied
Test XML file to be validated
<?xml version="1.0" encoding="iso-8859-1"?>
<pur>
<County>
<!--
Tag for counties to put county-specific
data in (eg, their batch number, timestamp,
contact info, etc)
-->
</County>
<File>
<!--
Data that applies to the entire file
-->
<PROCESS_DT>1234</PROCESS_DT>
<BATCH_NO>1234</BATCH_NO>
<COUNTY_CD>12</COUNTY_CD>
</File>
<Data>
<Ag>
<!--
Type A:
Data that would appear on individual lines
in the old A type
(F file type, agricultural job report)
Type B:
Data that would appear on individual lines
in the old B type
(F file type, agricultural monthly production summary)
-->
<key_data>
<!--
Key Data Instructions
(report identification related)
-->
<!--- Either A or B, for data type -->
<RECORD_ID>A</RECORD_ID>
<COUNTY_KEY>
<!--
The optional COUNTY_ID field would be used by
the Counties to include their internal
record identifier. This would allow DPR
to reference a county's internal record ID
in the event of data inconsistencies.
-->
FOO TEST
</COUNTY_KEY>
<REPORT_MONTH>12</REPORT_MONTH>
<REPORT_YEAR>09</REPORT_YEAR>
</key_data>
<product_data>
<!--
Product Registration Data
(product identification related)
-->
<MFG_FIRMNO>1234567</MFG_FIRMNO>
<LABEL_SEQ_NO>12345</LABEL_SEQ_NO>
<REVISION_NO>AA</REVISION_NO>
<REG_FIRMNO>1234567</REG_FIRMNO>
</product_data>
<mtrs_data>
<!--
Township/Range/Section Data
(site identification related)
-->
<SECTION>12</SECTION>
<TOWNSHIP>12</TOWNSHIP>
<TSHIP_DIR>N</TSHIP_DIR>
<RANGE>12</RANGE>
<RANGE_DIR>E</RANGE_DIR>
<BASE_LN_MER>H</BASE_LN_MER>
</mtrs_data>
<application_data>
<!--
Application Data
(information about the individual application)
-->
<GROWER_ID>12345678901</GROWER_ID>
<CEDTS_IND>E</CEDTS_IND>
<APPLIC_DT>122410</APPLIC_DT>
<SITE_CODE>123456</SITE_CODE>
<QUALIFY_CD>12</QUALIFY_CD>
<PLANTING_SEQ>1</PLANTING_SEQ>
<ACRE_TREATED>12345678</ACRE_TREATED>
<UNIT_TREATED>A</UNIT_TREATED>
<AMT_PRD_USED>1234567890</AMT_PRD_USED>
<UNIT_OF_MEAS>OZ</UNIT_OF_MEAS>
<DOCUMENT_NO>12345678</DOCUMENT_NO>
<LINE_ITEM>1234</LINE_ITEM>
<AER_GND_IND>A</AER_GND_IND>
<SITE_LOC_ID>123- 1</SITE_LOC_ID>
<ACRE_PLANTED>12345678</ACRE_PLANTED>
<UNIT_PLANTED>A</UNIT_PLANTED>
<APPLIC_TM>1234</APPLIC_TM>
<FUME_CD>1234</FUME_CD>
</application_data>
</Ag>
<Ag>
<!--
Type A:
Data that would appear on individual lines
in the old A type
(F file type, agricultural job report)
Type B:
Data that would appear on individual lines
in the old B type
(F file type, agricultural monthly production summary)
-->
<key_data>
<!--
Key Data Instructions
(report identification related)
-->
<!--- Either A or B, for data type -->
<RECORD_ID>A</RECORD_ID>
<COUNTY_KEY>
<!--
The optional COUNTY_ID field would be used by
the Counties to include their internal
record identifier. This would allow DPR
to reference a county's internal record ID
in the event of data inconsistencies.
-->
FOO TEST
</COUNTY_KEY>
<REPORT_MONTH>12</REPORT_MONTH>
<REPORT_YEAR>09</REPORT_YEAR>
</key_data>
<product_data>
<!--
Product Registration Data
(product identification related)
-->
<MFG_FIRMNO>1234567</MFG_FIRMNO>
<LABEL_SEQ_NO>12345</LABEL_SEQ_NO>
<REVISION_NO>AA</REVISION_NO>
<REG_FIRMNO>1234567</REG_FIRMNO>
</product_data>
<mtrs_data>
<!--
Township/Range/Section Data
(site identification related)
-->
<SECTION>12</SECTION>
<TOWNSHIP>12</TOWNSHIP>
<TSHIP_DIR>N</TSHIP_DIR>
<RANGE>12</RANGE>
<RANGE_DIR>E</RANGE_DIR>
<BASE_LN_MER>H</BASE_LN_MER>
</mtrs_data>
<application_data>
<!--
Application Data
(information about the individual application)
-->
<GROWER_ID>01234567890</GROWER_ID>
<CEDTS_IND>E</CEDTS_IND>
<APPLIC_DT>070710</APPLIC_DT>
<SITE_CODE>123456</SITE_CODE>
<QUALIFY_CD>12</QUALIFY_CD>
<PLANTING_SEQ>1</PLANTING_SEQ>
<ACRE_TREATED>12345678</ACRE_TREATED>
<UNIT_TREATED>A</UNIT_TREATED>
<AMT_PRD_USED>1234567890</AMT_PRD_USED>
<UNIT_OF_MEAS>OZ</UNIT_OF_MEAS>
<DOCUMENT_NO>12345678</DOCUMENT_NO>
<LINE_ITEM>1234</LINE_ITEM>
<AER_GND_IND>A</AER_GND_IND>
<SITE_LOC_ID>123- 1</SITE_LOC_ID>
<ACRE_PLANTED>12345678</ACRE_PLANTED>
<UNIT_PLANTED>A</UNIT_PLANTED>
<APPLIC_TM>1234</APPLIC_TM>
<FUME_CD>1234</FUME_CD>
</application_data>
</Ag>
</Data>
</pur>