1 Replies - 4051 Views - Last Post: 06 August 2012 - 06:28 AM Rate Topic: -----

#1 midasxl  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 188
  • Joined: 03-December 08

XMLValidate() throwing confusing error

Posted 25 July 2012 - 09:52 AM

Hello and thanks for your time.

I am messing around with Coldfusion 9, XMLValidate(), an XML document, and a handful of XML schemas as my test environment. These are all sample files I found in a tutorial. This is the error that I am getting:

[Error] :8:35: src-import.3.1: The namespace attribute, 'http://www.myTest.com/OrderTypes', of an <import> element information item must be identical to the targetNamespace attribute, 'http://www.myTest.com/Purchase', of the imported document.

The XML:
<?xml version="1.0" encoding="utf-8"?>
<p:Purchase xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
			xsi:schemaLocation="http://www.myTest.com/Purchase Main.xsd" 
			xmlns:p="http://www.myTest.com/Purchase"
			xmlns:o="http://www.myTest.com/OrderTypes"
			xmlns:c="http://www.myTest.com/CustomerTypes"
			xmlns:cmn="http://www.myTest.com/CommonTypes">
  <p:OrderDetail>
	<o:Item>
	  <o:ProductName>Widget</o:ProductName>
	  <o:Quantity>1</o:Quantity>
	  <o:UnitPrice>3.42</o:UnitPrice>
	</o:Item>
  </p:OrderDetail>
  <p:PaymentMethod>Visa</p:PaymentMethod>
  <p:CustomerDetails>
	<c:Name>James</c:Name>
	<c:DeliveryAddress>
	  <cmn:Line1>15 Some Road</cmn:Line1>
	  <cmn:Line2>SomeTown</cmn:Line2>
	</c:DeliveryAddress>
	<c:BillingAddress>
	  <cmn:Line1>15 Some Road</cmn:Line1>
	  <cmn:Line2>SomeTown</cmn:Line2>
	</c:BillingAddress>
  </p:CustomerDetails>
</p:Purchase>



The Main Schema:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://www.ncdoc.navy.mil/Purchase"
			xmlns:pur="http://www.myTest.com/Purchase"
			xmlns:ord="http://www.myTest.com/OrderTypes"
			xmlns:cmn="http://www.myTest.com/CommonTypes"
			xmlns:cust="http://www.myTest.com/CustomerTypes"
			xmlns:xs="http://www.w3.org/2001/XMLSchema"
			elementFormDefault="qualified">
			
<xs:import schemaLocation="OrderTypes.xsd" namespace="http://www.myTest.com/OrderTypes" />
<xs:import schemaLocation="CommonTypes.xsd" namespace="http://www.myTest.com/CommonTypes" />
<xs:import schemaLocation="CustomerTypes.xsd" namespace="http://www.myTest.com/CustomerTypes" />

<xs:element name="Purchase">
	<xs:complexType>
		<xs:sequence>
			<xs:element name="OrderDetail" type="ord:OrderType" />
			<xs:element name="PaymentMethod" type="cmn:PaymentMethodType" />
			<xs:element ref="pur:CustomerDetails" />
		</xs:sequence>
	</xs:complexType>
</xs:element>

<xs:element name="CustomerDetails" type="cust:CustomerType" />

</xs:schema>



The CFM Validation Page:
<cfset 
myResults=XMLValidate("test.xml", "Main.xsd")> 
<cfoutput> 
Did test.xml validate against Main.xsd? #myResults.status#<br><br> 
</cfoutput> 
Dump of myResults structure returned by XMLValidate<br> 
<cfdump var="#myResults#">



So, the error states that the namespace attribute value in the import tag must match the targetNamespace attribute value in the document being imported. So, in the first import tag of the Main.xsd file I have this:

<xs:import schemaLocation="OrderTypes.xsd" namespace="http://www.myTest.com/OrderTypes" />


In the OrderTypes.xsd, which is the document being imported, I have this:

<xs:schema xmlns:cmn="http://www.myTest.com/CommonTypes"
			targetNamespace="http://www.myTest.com/OrderTypes"
			xmlns:xs="http://www.w3.org/2001/XMLSchema"
			elementFormDefault="qualified">



From what I can see the namespace and the targetNamespace attribute values both match. I am not sure where it is getting the targetNamespace attribute value as stated in the error:

[Error] :8:35: src-import.3.1: The namespace attribute, 'http://www.myTest.com/OrderTypes', of an <import> element information item must be identical to the targetNamespace attribute, 'http://www.myTest.com/Purchase', of the imported document.

I get the same error for the other two import tags in the Main.xsd file. Thanks for any insight you may be able to provide.

Cheers!

Is This A Good Question/Topic? 0
  • +

Replies To: XMLValidate() throwing confusing error

#2 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 1866
  • View blog
  • Posts: 3,385
  • Joined: 13-January 08

Re: XMLValidate() throwing confusing error

Posted 06 August 2012 - 06:28 AM

Well, without loading up all your files and data and such and trying it myself, the first thing I'd do is to do an output dump of the namespace attribute and the targetNamespace attribute and see what you get for each. That sounds like kind of a "duh" thing to do but when I see what looks like an obvious error like that, I tend to go back and remove all the assumptions I've made and start from scratch.

The server believes those two values are different. Since that's so, have it tell you what they are on the line immediately before XMLValidate() fires and see what it's seeing. Once you have those values, you can do manual search for each value in all your code/data/pages and see where it's coming from.

Good luck!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1