validating XML output using XML schema

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
dsguyok
Premium Member
Premium Member
Posts: 24
Joined: Thu Jan 21, 2010 10:22 pm

validating XML output using XML schema

Post by dsguyok »

I am having trouble telling Datastage 8 to validate XML produced by the "XML Output" stage.

I have an XML schema that I want to be referenced in the validation. Currently I set this up by putting the following code in the Namespace Declaration text box in the XML Output stage properties:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="file://D:/DS_test/ proto_schema.xsd"

By doing this, the above code appears in the XML code's root element: "event". The official documentation says to do this (ie use schemaLocation as a root element attribute)


I get this warning in the logs and the validation seems to fail:

XML_Output_30,0: Warning: testEventGen.XML_Output_30: XML output document parsing failed. File Path: "D:/DS_test/XML_OUT.xml" Reason: "Xalan fatal error (publicId: , systemId: D:/DS_test/proto_schema.xsd, line: 2, column: 1): Invalid document structure
Xalan error (publicId: , systemId: D:/DS_test/XML_OUT.xml, line: 6, column: 119): Unknown element 'event'
Xalan error (publicId: , systemId: D:/DS_test/XML_OUT.xml, line: 6, column: 119): Attribute '{http://www.w3.org/2000/xmlns/}xsi' is not declared for element 'event'
Xalan error (publicId: , systemId: D:/DS_test/XML_OUT.xml, line: 6, column: 119): Attribute '{http://www.w3.org/2001/XMLSchema-instan ... maLocation' is not declared for element 'event'
Xalan error (publicId: , systemId: D:/DS_test/XML_OUT.xml, line: 8, column: 15): Unknown element 'event_type'
Xalan error (publicId: , systemId: D:/DS_test/XML_OUT.xml, line: 11, column: 13): Unknown element 'event_dt'
Xalan error (publicId: , systemId: D:/DS_test/XML_OUT.xml, line: 14, column: 21): Unknown element 'perm_req_clnt_id'


Would appreciate any thoughts on what to change.
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

I haven't tried schema validation on xmlOutput in a long time, but in reviewing tests that I use very often for xmlInput, my schemaLocation attributes for Windows systems are always absolute file identifiers.....meaning noNameSpaceSchemaLocation="C:\myfile\xyz\mySchema.xsd" ...you might want to try that instead of the syntax you are using above.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
dsguyok
Premium Member
Premium Member
Posts: 24
Joined: Thu Jan 21, 2010 10:22 pm

Post by dsguyok »

Thanks. I tried using

noNameSpaceSchemaLocation="D:\DS_test\proto_schema.xsd"

instead but got a similar error:

XML_Output_30,0: Warning: testEventGen.XML_Output_30: XML output document parsing failed. File Path: "D:/DS_test/XML_OUT.xml" Reason: "Xalan error (publicId: , systemId: D:/DS_test/XML_OUT.xml, line: 6, column: 65): Unknown element 'event'
Xalan error (publicId: , systemId: D:/DS_test/XML_OUT.xml, line: 6, column: 65): Attribute 'noNameSpaceSchemaLocation' is not declared for element 'event'
Xalan error (publicId: , systemId: D:/DS_test/XML_OUT.xml, line: 8, column: 15): Unknown element 'event_type'
Xalan error (publicId: , systemId: D:/DS_test/XML_OUT.xml, line: 11, column: 13): Unknown element 'event_dt'
Xalan error (publicId: , systemId: D:/DS_test/XML_OUT.xml, line: 14, column: 21): Unknown element 'perm_req_clnt_id'


The error seems to be saying that noNameSpaceschemaLocation is undeclared for my root element "event". How would I fix that?
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

Hmm. Let's ask and try a few things.

a) what happens when you don't ask for validation (don't check the box)....do you get a document created?

b) if so....create it in DS and then find a validation tool on the web or in XMLSpy or other such product, and validate it.---- is it valid?

The error almost sounds like it is indeed doing validation correctly, and something is wrong with the document it is constructing, or wrong with your schema....

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
dsguyok
Premium Member
Premium Member
Posts: 24
Joined: Thu Jan 21, 2010 10:22 pm

Post by dsguyok »

eostic wrote:a) what happens when you don't ask for validation (don't check the box)....do you get a document created?
in this case, the XML files are created without issue.

I've validated the XML output and the schema itself using web tools. Here they are, respectively:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<event xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="D:\DS_test\ proto_schema.xsd">
  <event_type>1136</event_type>
  <event_dt>1960-01-01</event_dt>
  <perm_req_clnt_id>200</perm_req_clnt_id>
</event>

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" xml:lang="en">
  <xs:element name="event">
  	<xs:complexType>
	  	<xs:sequence>
  			<xs:element name="event_type" />
  			<xs:element name="event_dt" />
  			<xs:element name="perm_req_clnt_id" />
  		</xs:sequence>
  	</xs:complexType>
  </xs:element>
</xs:schema>
I get this error in Datastage with the validation switched back on:

XML_Output_30,0: Warning: testEventGen.XML_Output_30: XML output document parsing failed. File Path: "D:/DS_test/XML_OUT.xml" Reason: "Xalan fatal error (publicId: , systemId: D:/DS_test/proto_schema.xsd, line: 2, column: 1): Invalid document structure
Xalan error (publicId: , systemId: D:/DS_test/XML_OUT.xml, line: 2, column: 113): Unknown element 'event'
Xalan error (publicId: , systemId: D:/DS_test/XML_OUT.xml, line: 2, column: 113): Attribute '{http://www.w3.org/2000/xmlns/}xsi' is not declared for element 'event'
Xalan error (publicId: , systemId: D:/DS_test/XML_OUT.xml, line: 2, column: 113): Attribute '{http://www.w3.org/2001/XMLSchema-instan ... maLocation' is not declared for element 'event'
Xalan error (publicId: , systemId: D:/DS_test/XML_OUT.xml, line: 3, column: 15): Unknown element 'event_type'
Xalan error (publicId: , systemId: D:/DS_test/XML_OUT.xml, line: 6, column: 13): Unknown element 'event_dt'
Xalan error (publicId: , systemId: D:/DS_test/XML_OUT.xml, line: 9, column: 21): Unknown element 'perm_req_clnt_id'

Maybe it's having trouble reading the schema file ... "invalid document structure" ... ?

Using noNameSpaceSchemaLocation throws roughly the same error.
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

hmm. Not sure. Is that space in the xsd name just an issue here in the Forum? Assuming it is, I can't see anything obvious. Anyone else have an idea? I'll have to try it but probably won't have time until a day or so....

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
dsguyok
Premium Member
Premium Member
Posts: 24
Joined: Thu Jan 21, 2010 10:22 pm

Post by dsguyok »

eostic wrote:Is that space in the xsd name just an issue here in the Forum?
No, that's intended. If I take the space out, I get this error message:

XML_Output_30,0: Warning: testEventGen.XML_Output_30: XML output document parsing failed. File Path: "D:/DS_test/XML_OUT.xml" Reason: "Xalan fatal error (publicId: , systemId: D:/DS_test/XML_OUT.xml, line: 2, column: 112): The schemaLocation attribute does not contain pairs of values.

So that's why I have a "pair" value: schemaLocation="D:\DS_test\ proto_schema.xsd"

Your help is much appreciated - keep it coming :)
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

Ok. Something's up. I'm looking forward to trying it. Probably won't have a thought for you until the end of the w/e....let me know if you resolve it sooner.
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
dsguyok
Premium Member
Premium Member
Posts: 24
Joined: Thu Jan 21, 2010 10:22 pm

Post by dsguyok »

I've got it working on DS 7.5 running on UNIX.

The XML Output stage properties are the same as on DS 8 Windows (the installation with this issue).

So I guess it's a DS-8-Windows-specific problem.
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

Thanks. That's good news. At least we know that it is working as it "should" and that you did things correctly. Have you reported it for 8.x? I haven't been able to test as I've been "in between" systems while upgrading further to 8.1.2...., and there have been a lot of patches to various things that went into 8.1 and the FP1 to 8.1....

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
apierro1
Participant
Posts: 12
Joined: Thu Nov 13, 2008 8:50 am

Post by apierro1 »

dsguyok wrote:I've got it working on DS 7.5 running on UNIX.
How were you able to get this working on 7.5?
Thanks,

Anthony
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Anthony, have you been through the documentation on that option? Have an issue or specific question?
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply